diff --git a/prisma/migrations/20240418080551_add_announcements/migration.sql b/prisma/migrations/20240418080551_add_announcements/migration.sql new file mode 100644 index 0000000..0204466 --- /dev/null +++ b/prisma/migrations/20240418080551_add_announcements/migration.sql @@ -0,0 +1,15 @@ +-- CreateTable +CREATE TABLE "Announcement" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "content" TEXT NOT NULL, + "isSent" BOOLEAN NOT NULL DEFAULT false, + "eventId" TEXT, + "eventGroupId" TEXT, + + CONSTRAINT "Announcement_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Announcement" ADD CONSTRAINT "Announcement_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 897b839..de621f4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -90,6 +90,7 @@ model Event { promoCodes PromoCode[] interestedEmails MailingListMember[] webhooks Webhook[] + announcements Announcement[] } enum WebhookService { @@ -300,6 +301,20 @@ model ScheduleItem { eventGroupId String? } +model Announcement { + // Metadata + id String @id @default(cuid()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + content String + isSent Boolean @default(false) + + // Relations + event Event? @relation(fields: [eventId], references: [id]) + eventId String? +} + enum DiscountType { SUBTRACT PERCENT diff --git a/src/customModelsEnhanceMap/Announcement.ts b/src/customModelsEnhanceMap/Announcement.ts new file mode 100644 index 0000000..05c05fb --- /dev/null +++ b/src/customModelsEnhanceMap/Announcement.ts @@ -0,0 +1,16 @@ +import {AnnouncementScalarFieldEnum, ModelConfig} from "../generated/typegraphql-prisma"; +import {Authorized} from "type-graphql"; +import {AuthRole} from "../context"; + +let defaultPerms: {[key: string]: MethodDecorator[]} = {}; +Object.keys(AnnouncementScalarFieldEnum).forEach((value: string) => defaultPerms[value] = [Authorized(AuthRole.ADMIN, AuthRole.MANAGER)]) + +export const announcementEnhanceConfig: ModelConfig<"Announcement"> = { + fields: { + ...defaultPerms, + id: [], + createdAt: [], + updatedAt: [], + content: [], + } +} diff --git a/src/customResolversEnhanceMap/Announcement.ts b/src/customResolversEnhanceMap/Announcement.ts new file mode 100644 index 0000000..252d169 --- /dev/null +++ b/src/customResolversEnhanceMap/Announcement.ts @@ -0,0 +1,13 @@ +import {ResolverActionsConfig, AnnouncementCrudResolver} from "../generated/typegraphql-prisma"; +import {Authorized} from "type-graphql"; +import {AuthRole} from "../context"; + +let defaultPerms: {[key: string]: MethodDecorator[]} = {}; +Object.getOwnPropertyNames(AnnouncementCrudResolver.prototype).forEach((value: string) => defaultPerms[value] = [Authorized(AuthRole.ADMIN)]) + +export const announcementEnhanceConfig: ResolverActionsConfig<"Announcement"> = { + ...defaultPerms, + createAnnouncement: [Authorized(AuthRole.ADMIN, AuthRole.MANAGER)], + updateAnnouncement: [Authorized(AuthRole.ADMIN)], + deleteAnnouncement: [Authorized(AuthRole.ADMIN)], +}