Skip to content

Commit

Permalink
feat: upload job offer 💰 (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
hebronmekuria authored Apr 3, 2024
1 parent 666c464 commit c09c1d9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/core/src/modules/employment/employment.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const FORMATTED_EMPLOYMENT_TYPE: Record<EmploymentType, string> = {
part_time: 'Part-Time',
};

export const JobOfferStatus = {
ACCEPTED: 'accepted',
RECEIVED: 'received',
REJECTED: 'rejected',
} as const;

export const LocationType = {
HYBRID: 'hybrid',
IN_PERSON: 'in_person',
Expand All @@ -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(),
Expand Down Expand Up @@ -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<typeof AddWorkExperienceInput>;
Expand All @@ -102,4 +132,5 @@ export type DeleteWorkExperienceInput = z.infer<
export type EditWorkExperienceInput = z.infer<typeof EditWorkExperienceInput>;
export type EmploymentType = ExtractValue<typeof EmploymentType>;
export type LocationType = ExtractValue<typeof LocationType>;
export type UploadJobOfferInput = z.infer<typeof UploadJobOfferInput>;
export type WorkExperience = z.infer<typeof WorkExperience>;
47 changes: 47 additions & 0 deletions packages/core/src/modules/employment/use-cases/upload-job-offer.ts
Original file line number Diff line number Diff line change
@@ -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();
});
}

0 comments on commit c09c1d9

Please sign in to comment.