From 75b352b7213d23ba5fd1b1e65ea74f7150a8fbf9 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 8 Jul 2023 19:48:20 +0000 Subject: [PATCH] Add showPopup, isGoodNews & Update API --- .../1688845537045-announcement-popup.js | 21 +++++++++++++++++++ .../src/models/entities/announcement.ts | 10 +++++++++ .../endpoints/admin/announcements/create.ts | 14 +++++++++++++ .../api/endpoints/admin/announcements/list.ts | 12 +++++++++++ .../endpoints/admin/announcements/update.ts | 4 ++++ .../src/server/api/endpoints/announcements.ts | 10 +++++++++ 6 files changed, 71 insertions(+) create mode 100644 packages/backend/migration/1688845537045-announcement-popup.js diff --git a/packages/backend/migration/1688845537045-announcement-popup.js b/packages/backend/migration/1688845537045-announcement-popup.js new file mode 100644 index 000000000..196590d3e --- /dev/null +++ b/packages/backend/migration/1688845537045-announcement-popup.js @@ -0,0 +1,21 @@ +export class AnnouncementPopup1688845537045 { + name = "AnnouncementPopup1688845537045"; + + async up(queryRunner) { + await queryRunner.query( + `ALTER TABLE "announcement" ADD "showPopup" boolean NOT NULL DEFAULT false`, + ); + await queryRunner.query( + `ALTER TABLE "announcement" ADD "isGoodNews" boolean NOT NULL DEFAULT false`, + ); + } + + async down(queryRunner) { + await queryRunner.query( + `ALTER TABLE "announcement" DROP COLUMN "isGoodNews"`, + ); + await queryRunner.query( + `ALTER TABLE "announcement" DROP COLUMN "showPopup"`, + ); + } +} diff --git a/packages/backend/src/models/entities/announcement.ts b/packages/backend/src/models/entities/announcement.ts index 1939604b9..7872c0fe1 100644 --- a/packages/backend/src/models/entities/announcement.ts +++ b/packages/backend/src/models/entities/announcement.ts @@ -36,6 +36,16 @@ export class Announcement { }) public imageUrl: string | null; + @Column("boolean", { + default: false, + }) + public showPopup: boolean; + + @Column("boolean", { + default: false, + }) + public isGoodNews: boolean; + constructor(data: Partial) { if (data == null) return; diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts index a532b6677..754cc6c89 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts @@ -47,6 +47,16 @@ export const meta = { optional: false, nullable: true, }, + showPopup: { + type: "boolean", + optional: true, + nullable: false, + }, + isGoodNews: { + type: "boolean", + optional: true, + nullable: false, + }, }, }, } as const; @@ -57,6 +67,8 @@ export const paramDef = { title: { type: "string", minLength: 1 }, text: { type: "string", minLength: 1 }, imageUrl: { type: "string", nullable: true, minLength: 1 }, + showPopup: { type: "boolean" }, + isGoodNews: { type: "boolean" }, }, required: ["title", "text", "imageUrl"], } as const; @@ -69,6 +81,8 @@ export default define(meta, paramDef, async (ps) => { title: ps.title, text: ps.text, imageUrl: ps.imageUrl, + showPopup: ps.showPopup ?? false, + isGoodNews: ps.isGoodNews ?? false, }).then((x) => Announcements.findOneByOrFail(x.identifiers[0])); return Object.assign({}, announcement, { diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/list.ts b/packages/backend/src/server/api/endpoints/admin/announcements/list.ts index fc5b02070..e96517c68 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/list.ts @@ -57,6 +57,16 @@ export const meta = { optional: false, nullable: false, }, + showPopup: { + type: "boolean", + optional: true, + nullable: false, + }, + isGoodNews: { + type: "boolean", + optional: true, + nullable: false, + }, }, }, }, @@ -100,5 +110,7 @@ export default define(meta, paramDef, async (ps) => { text: announcement.text, imageUrl: announcement.imageUrl, reads: reads.get(announcement)!, + showPopup: announcement.showPopup, + isGoodNews: announcement.isGoodNews, })); }); diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/update.ts b/packages/backend/src/server/api/endpoints/admin/announcements/update.ts index 35e64f281..616b94d69 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/update.ts @@ -24,6 +24,8 @@ export const paramDef = { title: { type: "string", minLength: 1 }, text: { type: "string", minLength: 1 }, imageUrl: { type: "string", nullable: true, minLength: 1 }, + showPopup: { type: "boolean" }, + isGoodNews: { type: "boolean" }, }, required: ["id", "title", "text", "imageUrl"], } as const; @@ -38,5 +40,7 @@ export default define(meta, paramDef, async (ps, me) => { title: ps.title, text: ps.text, imageUrl: ps.imageUrl, + showPopup: ps.showPopup ?? false, + isGoodNews: ps.isGoodNews ?? false, }); }); diff --git a/packages/backend/src/server/api/endpoints/announcements.ts b/packages/backend/src/server/api/endpoints/announcements.ts index 00634cc42..1bab61ba2 100644 --- a/packages/backend/src/server/api/endpoints/announcements.ts +++ b/packages/backend/src/server/api/endpoints/announcements.ts @@ -56,6 +56,16 @@ export const meta = { optional: true, nullable: false, }, + showPopup: { + type: "boolean", + optional: false, + nullable: false, + }, + isGoodNews: { + type: "boolean", + optional: false, + nullable: false, + }, }, }, },