[offers][feat] add admin table in db

pull/553/head
Stuart Long Chay Boon 2 years ago
parent ada6a68420
commit 55beb386e8

@ -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;

@ -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())

@ -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
}
});

Loading…
Cancel
Save