diff --git a/packages/core/src/modules/employment/employment.types.ts b/packages/core/src/modules/employment/employment.types.ts index 2151028d5..aeb9323e0 100644 --- a/packages/core/src/modules/employment/employment.types.ts +++ b/packages/core/src/modules/employment/employment.types.ts @@ -28,6 +28,12 @@ export const FORMATTED_EMPLOYMENT_TYPE: Record = { part_time: 'Part-Time', }; +export const JobOfferStatus = { + ACCEPTED: 'accepted', + RECEIVED: 'received', + REJECTED: 'rejected', +} as const; + export const LocationType = { HYBRID: 'hybrid', IN_PERSON: 'in_person', @@ -53,6 +59,24 @@ export const BaseCompany = z.object({ export const Company = Entity.merge(BaseCompany); +export const JobOffer = Entity.omit({ deletedAt: true }).extend({ + baseSalary: z.number().optional(), + bonus: z.number().optional(), + companyId: Company.shape.id.nullish(), + compensationType: z.string(), + employmentType: z.nativeEnum(EmploymentType), + hourlyPay: z.number().optional(), + location: z.string().optional(), + locationLatitude: z.number().optional(), + locationLongitude: z.number().optional(), + locationType: z.nativeEnum(LocationType), + otherCompany: NullishString.optional(), + startDate: ISO8601Date, + status: z.string(), + stockPerYear: z.number().optional(), + studentId: Student.shape.id, +}); + export const WorkExperience = Entity.extend({ companyId: Company.shape.id.nullish(), companyName: z.string().trim().min(1).nullish(), @@ -91,6 +115,12 @@ export const EditWorkExperienceInput = AddWorkExperienceInput.extend({ id: WorkExperience.shape.id, }); +export const UploadJobOfferInput = JobOffer.omit({ + createdAt: true, + id: true, + updatedAt: true, +}); + // Types export type AddWorkExperienceInput = z.infer; @@ -102,4 +132,5 @@ export type DeleteWorkExperienceInput = z.infer< export type EditWorkExperienceInput = z.infer; export type EmploymentType = ExtractValue; export type LocationType = ExtractValue; +export type UploadJobOfferInput = z.infer; export type WorkExperience = z.infer; diff --git a/packages/core/src/modules/employment/use-cases/upload-job-offer.ts b/packages/core/src/modules/employment/use-cases/upload-job-offer.ts new file mode 100644 index 000000000..d0baa1e5a --- /dev/null +++ b/packages/core/src/modules/employment/use-cases/upload-job-offer.ts @@ -0,0 +1,47 @@ +import { sql } from 'kysely'; + +import { id } from '@oyster/utils'; + +import { db } from '@/infrastructure/database'; +import { UploadJobOfferInput } from '../employment.types'; + +export async function uploadJobOffer({ + baseSalary, + bonus, + companyId, + compensationType, + employmentType, + hourlyPay, + location, + locationLatitude, + locationLongitude, + locationType, + otherCompany, + startDate, + status, + stockPerYear, + studentId, +}: UploadJobOfferInput) { + await db.transaction().execute(async (trx) => { + await trx + .insertInto('jobOffers') + .values({ + baseSalary, + bonus, + companyId, + compensationType, + employmentType, + hourlyPay, + id: id(), + location, + locationCoordinates: sql`point(${locationLongitude}, ${locationLatitude})`, + locationType, + otherCompany, + startDate, + status, + stockPerYear, + studentId, + }) + .execute(); + }); +}