Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload job offer 💰 #77

Merged
merged 17 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
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();
});
}