diff --git a/apps/portal/prisma/migrations/20221117094655_add_offersadmin_table/migration.sql b/apps/portal/prisma/migrations/20221117094655_add_offersadmin_table/migration.sql new file mode 100644 index 00000000..3d3bd7bd --- /dev/null +++ b/apps/portal/prisma/migrations/20221117094655_add_offersadmin_table/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE "OffersAdmin" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + + CONSTRAINT "OffersAdmin_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "OffersAdmin_userId_key" ON "OffersAdmin"("userId"); + +-- AddForeignKey +ALTER TABLE "OffersAdmin" ADD CONSTRAINT "OffersAdmin_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index 31f846d9..c73aab8a 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -62,6 +62,7 @@ model User { OffersProfile OffersProfile[] offersDiscussion OffersReply[] questionsLists QuestionsList[] + OffersAdmin OffersAdmin? } enum Vote { @@ -241,6 +242,12 @@ model OffersProfile { analysis OffersAnalysis? } +model OffersAdmin { + id String @id @default(cuid()) + userId String @unique + user User @relation(fields: [userId], references: [id], onDelete: Cascade) +} + model OffersBackground { id String @id @default(cuid()) diff --git a/apps/portal/src/server/router/offers/offers-admin-router.ts b/apps/portal/src/server/router/offers/offers-admin-router.ts index 4403b959..cd923d07 100644 --- a/apps/portal/src/server/router/offers/offers-admin-router.ts +++ b/apps/portal/src/server/router/offers/offers-admin-router.ts @@ -10,7 +10,7 @@ import { Currency } from '~/utils/offers/currency/CurrencyEnum'; import { convertWithDate } from '~/utils/offers/currency/currencyExchange'; import { createValidationRegex } from '~/utils/offers/zodRegex'; -import { createRouter } from '../context'; +import { createProtectedRouter } from '../context'; const getOrder = (prefix: string) => { return prefix === '+' ? 'asc' : 'desc'; @@ -43,7 +43,7 @@ const getYoeRange = (yoeCategory: number | null | undefined) => { : null; // Internship }; -export const offerAdminRouter = createRouter().query('list', { +export const offerAdminRouter = createProtectedRouter().query('list', { input: z.object({ companyId: z.string().nullish(), countryId: z.string().nullish(), @@ -463,4 +463,15 @@ export const offerAdminRouter = createRouter().query('list', { !yoeRange ? JobType.INTERN : JobType.FULLTIME, ); }, +}).query('isAdmin', { + async resolve({ ctx }) { + const userId = ctx.session.user.id; + const result = await ctx.prisma.offersAdmin.findFirst({ + where: { + userId + } + }) + + return result ? true : false + } });