Skip to content

Commit

Permalink
refactor: Update nullable property for endAnnouncementAt column in St…
Browse files Browse the repository at this point in the history
…atusPageAnnouncement model
  • Loading branch information
simlarsen committed Sep 6, 2024
1 parent 0f58e16 commit 24bd374
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Common/Models/DatabaseModels/StatusPageAnnouncement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default class StatusPageAnnouncement extends BaseModel {
@TableColumn({
title: "End At",
type: TableColumnType.Date,
required: true,
required: false,
description: "When should this announcement hidden?",
})
@ColumnAccessControl({
Expand All @@ -284,7 +284,7 @@ export default class StatusPageAnnouncement extends BaseModel {
],
})
@Column({
nullable: false,
nullable: true,
type: ColumnType.Date,
})
public endAnnouncementAt?: Date = undefined;
Expand Down
2 changes: 1 addition & 1 deletion Common/Server/API/StatusPageAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export default class StatusPageAPI extends BaseAPI<
query: {
statusPages: objectId as any,
showAnnouncementAt: QueryHelper.lessThan(today),
endAnnouncementAt: QueryHelper.greaterThan(today),
endAnnouncementAt: QueryHelper.greaterThanOrNull(today),
projectId: statusPage.projectId!,
},
select: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1725618842598 implements MigrationInterface {
public name = "MigrationName1725618842598";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "StatusPageAnnouncement" ALTER COLUMN "endAnnouncementAt" DROP NOT NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "StatusPageAnnouncement" ALTER COLUMN "endAnnouncementAt" SET NOT NULL`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { MigrationName1725360199561 } from "./1725360199561-MigrationName";
import { MigrationName1725379949648 } from "./1725379949648-MigrationName";
import { MigrationName1725551629492 } from "./1725551629492-MigrationName";
import { MigrationName1725556630384 } from "./1725556630384-MigrationName";
import { MigrationName1725618842598 } from "./1725618842598-MigrationName";

export default [
InitialMigration,
Expand Down Expand Up @@ -104,4 +105,5 @@ export default [
MigrationName1725379949648,
MigrationName1725551629492,
MigrationName1725556630384,
MigrationName1725618842598,
];
6 changes: 6 additions & 0 deletions Common/Tests/Server/Services/BillingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,17 @@ describe("BillingService", () => {
downloadableLink: "",
status: "paid",
subscriptionId: invoice.subscription,
invoiceNumber: invoice.number,
invoiceDate: new Date(invoice.created * 1000),
};
}),
);

expect(mockStripe.invoices.list).toHaveBeenCalledWith({
customer: customerId,
limit: 100,
});

});

it("should return an empty array if no invoices are found for the customer", async () => {
Expand Down Expand Up @@ -1428,6 +1432,8 @@ describe("BillingService", () => {
status: mockPaidInvoice.status,
downloadableLink: "",
subscriptionId: mockPaidInvoice.subscription,
invoiceNumber: mockPaidInvoice.number,
invoiceDate: new Date(mockPaidInvoice.created * 1000),
});
expect(mockStripe.invoices.pay).toHaveBeenCalledWith(
mockPaidInvoice.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const getStripeInvoice: GetStripeInvoiceFunction = (): Stripe.Invoice => {
currency: "usd",
customer: Faker.generateRandomObjectID().toString(),
subscription: Faker.generateRandomObjectID().toString(),
created: new Date().getTime() / 1000,
number: Faker.generateRandomString(),
status: "paid",
};
};
Expand Down
3 changes: 2 additions & 1 deletion Dashboard/src/Pages/StatusPages/View/Announcements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
stepId: "more",
title: "End Showing Announcement At",
fieldType: FormFieldSchemaType.DateTime,
required: true,
required: false,
placeholder: "Pick Date and Time",
},
{
Expand Down Expand Up @@ -171,6 +171,7 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
},
title: "End Announcement At",
type: FieldType.DateTime,
noValueMessage: "-",
},
{
field: {
Expand Down
19 changes: 13 additions & 6 deletions StatusPage/src/Pages/Announcement/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,24 @@ const Overview: FunctionComponent<PageComponentProps> = (

const activeAnnouncement: Array<StatusPageAnnouncement> =
announcements.filter((announcement: StatusPageAnnouncement) => {
return OneUptimeDate.isBefore(
OneUptimeDate.getCurrentDate(),
announcement.endAnnouncementAt!,
return (
!announcement.endAnnouncementAt ||
(announcement.endAnnouncementAt &&
OneUptimeDate.isBefore(
OneUptimeDate.getCurrentDate(),
announcement.endAnnouncementAt!,
))
);
});

const pastAnnouncement: Array<StatusPageAnnouncement> =
announcements.filter((announcement: StatusPageAnnouncement) => {
return OneUptimeDate.isAfter(
OneUptimeDate.getCurrentDate(),
announcement.endAnnouncementAt!,
return (
announcement.endAnnouncementAt &&
OneUptimeDate.isAfter(
OneUptimeDate.getCurrentDate(),
announcement.endAnnouncementAt!,
)
);
});

Expand Down

0 comments on commit 24bd374

Please sign in to comment.