Skip to content

Commit

Permalink
Add announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermenezes committed Apr 18, 2024
1 parent 3f2cc61 commit 21670c0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions prisma/migrations/20240418080551_add_announcements/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ model Event {
promoCodes PromoCode[]
interestedEmails MailingListMember[]
webhooks Webhook[]
announcements Announcement[]
}

enum WebhookService {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/customModelsEnhanceMap/Announcement.ts
Original file line number Diff line number Diff line change
@@ -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: [],
}
}
13 changes: 13 additions & 0 deletions src/customResolversEnhanceMap/Announcement.ts
Original file line number Diff line number Diff line change
@@ -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)],
}

0 comments on commit 21670c0

Please sign in to comment.