diff --git a/apps/portal/prisma/seed.ts b/apps/portal/prisma/seed.ts index c31d6705..0e736d19 100644 --- a/apps/portal/prisma/seed.ts +++ b/apps/portal/prisma/seed.ts @@ -35,34 +35,6 @@ const COMPANIES = [ }, ]; -const OFFER_PROFILES = [ - { - id: 'cl91v97ex000109mt7fka5rto', - profileName: 'battery-horse-stable-cow', - editToken: 'cl91ulmhg000009l86o45aspt', - }, - { - id: 'cl91v9iw2000209mtautgdnxq', - profileName: 'house-zebra-fast-giraffe', - editToken: 'cl91umigc000109l80f1tcqe8', - }, - { - id: 'cl91v9m3y000309mt1ctw55wi', - profileName: 'keyboard-mouse-lazy-cat', - editToken: 'cl91ummoa000209l87q2b8hl7', - }, - { - id: 'cl91v9p09000409mt5rvoasf1', - profileName: 'router-hen-bright-pig', - editToken: 'cl91umqa3000309l87jyefe9k', - }, - { - id: 'cl91v9uda000509mt5i5fez3v', - profileName: 'screen-ant-dirty-bird', - editToken: 'cl91umuj9000409l87ez85vmg', - }, -]; - async function main() { console.log('Seeding started...'); await Promise.all([ @@ -73,13 +45,6 @@ async function main() { create: company, }); }), - OFFER_PROFILES.map(async (offerProfile) => { - await prisma.offersProfile.upsert({ - where: { profileName: offerProfile.profileName }, - update: offerProfile, - create: offerProfile, - }); - }), ]); console.log('Seeding completed.'); } diff --git a/apps/portal/src/pages/offers/test/createProfile.tsx b/apps/portal/src/pages/offers/test/createProfile.tsx index 93ff8b7e..128960ff 100644 --- a/apps/portal/src/pages/offers/test/createProfile.tsx +++ b/apps/portal/src/pages/offers/test/createProfile.tsx @@ -77,7 +77,7 @@ function Test() { message: 'wassup bro', profileId: 'cl9efyn9p004ww3u42mjgl1vn', replyingToId: 'cl9el4xj10001w3w21o3p2iny', - userId: 'cl9ehvpng0000w3ec2mpx0bdd' + userId: 'cl9ehvpng0000w3ec2mpx0bdd', }); }; @@ -218,7 +218,6 @@ function Test() { }, ); - // Console.log(replies.data?.data) const deleteMutation = trpc.useMutation(['offers.profile.delete']); const handleDelete = (id: string) => { diff --git a/apps/portal/src/pages/offers/test/listOffers.tsx b/apps/portal/src/pages/offers/test/listOffers.tsx index db295d0d..143d1826 100644 --- a/apps/portal/src/pages/offers/test/listOffers.tsx +++ b/apps/portal/src/pages/offers/test/listOffers.tsx @@ -9,8 +9,8 @@ function Test() { limit: 100, location: 'Singapore, Singapore', offset: 0, - sortBy: '-totalYoe', - yoeCategory: 2, + sortBy: '+totalCompensation', + yoeCategory: 1, }, ]); diff --git a/apps/portal/src/server/router/offers/offers.ts b/apps/portal/src/server/router/offers/offers.ts index d75ed270..953e133a 100644 --- a/apps/portal/src/server/router/offers/offers.ts +++ b/apps/portal/src/server/router/offers/offers.ts @@ -43,7 +43,7 @@ export const offersRouter = createRouter().query('list', { limit: z.number().positive(), location: z.string(), offset: z.number().nonnegative(), - salaryMax: z.number().nullish(), + salaryMax: z.number().nonnegative().nullish(), salaryMin: z.number().nonnegative().nullish(), sortBy: z.string().regex(createSortByValidationRegex()).nullish(), title: z.string().nullish(), @@ -154,38 +154,47 @@ export const offersRouter = createRouter().query('list', { data = data.filter((offer) => { let validRecord = true; - if (input.companyId) { + if (input.companyId && input.companyId.length !== 0) { validRecord = validRecord && offer.company.id === input.companyId; } - if (input.title) { + if (input.title && input.title.length !== 0) { validRecord = validRecord && (offer.offersFullTime?.title === input.title || offer.offersIntern?.title === input.title); } - if (input.dateStart && input.dateEnd) { + if ( + input.dateStart && + input.dateEnd && + input.dateStart.getTime() <= input.dateEnd.getTime() + ) { validRecord = validRecord && offer.monthYearReceived.getTime() >= input.dateStart.getTime() && offer.monthYearReceived.getTime() <= input.dateEnd.getTime(); } - if (input.salaryMin && input.salaryMax) { + if (input.salaryMin != null || input.salaryMax != null) { const salary = offer.offersFullTime?.totalCompensation.value ? offer.offersFullTime?.totalCompensation.value : offer.offersIntern?.monthlySalary.value; - if (!salary) { + if (salary == null) { throw new TRPCError({ code: 'NOT_FOUND', message: 'Total Compensation or Salary not found', }); } - validRecord = - validRecord && salary >= input.salaryMin && salary <= input.salaryMax; + if (input.salaryMin != null) { + validRecord = validRecord && salary >= input.salaryMin; + } + + if (input.salaryMax != null) { + validRecord = validRecord && salary <= input.salaryMax; + } } return validRecord; @@ -221,7 +230,7 @@ export const offersRouter = createRouter().query('list', { ? offer2.offersFullTime?.totalCompensation.value : offer2.offersIntern?.monthlySalary.value; - if (!salary1 || !salary2) { + if (salary1 == null || salary2 == null) { throw new TRPCError({ code: 'NOT_FOUND', message: 'Total Compensation or Salary not found', @@ -235,7 +244,7 @@ export const offersRouter = createRouter().query('list', { const yoe1 = offer1.profile.background?.totalYoe; const yoe2 = offer2.profile.background?.totalYoe; - if (!yoe1 || !yoe2) { + if (yoe1 == null || yoe2 == null) { throw new TRPCError({ code: 'NOT_FOUND', message: 'Total years of experience not found', @@ -267,7 +276,7 @@ export const offersRouter = createRouter().query('list', { ? offer2.offersFullTime?.totalCompensation.value : offer2.offersIntern?.monthlySalary.value; - if (!salary1 || !salary2) { + if (salary1 == null || salary2 == null) { throw new TRPCError({ code: 'NOT_FOUND', message: 'Total Compensation or Salary not found', @@ -281,7 +290,7 @@ export const offersRouter = createRouter().query('list', { const yoe1 = offer1.profile.background?.totalYoe; const yoe2 = offer2.profile.background?.totalYoe; - if (!yoe1 || !yoe2) { + if (yoe1 == null || yoe2 == null) { throw new TRPCError({ code: 'NOT_FOUND', message: 'Total years of experience not found',