Skip to content

Commit

Permalink
refactor resume books
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou committed Jul 19, 2024
1 parent 4b27f72 commit 3c64ebf
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Form as RemixForm, useActionData, useFetcher } from '@remix-run/react';
import { useEffect } from 'react';

import { createResumeBook } from '@oyster/core/resume-books';
import {
Button,
ComboboxPopover,
Expand All @@ -24,7 +25,6 @@ import {
validateForm,
} from '@oyster/ui';

import { createResumeBook } from '@/member-profile.server';
import { CreateResumeBookInput } from '@/member-profile.ui';
import { type SearchCompaniesResult } from '@/routes/api.companies.search';
import { Route } from '@/shared/constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dayjs from 'dayjs';
import { useState } from 'react';
import { Clipboard, ExternalLink, Menu, Plus } from 'react-feather';

import { listResumeBooks } from '@oyster/core/resume-books.server';
import { listResumeBooks } from '@oyster/core/resume-books';
import {
Dashboard,
Dropdown,
Expand Down
4 changes: 2 additions & 2 deletions apps/member-profile/app/routes/_profile.resume-books.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {
import dayjs from 'dayjs';
import { match } from 'ts-pattern';

import { SubmitResumeInput } from '@oyster/core/resume-books';
import {
getResumeBook,
getResumeBookSubmission,
listResumeBookSponsors,
submitResume,
} from '@oyster/core/resume-books.server';
} from '@oyster/core/resume-books';
import { SubmitResumeInput } from '@oyster/core/resume-books.types';
import { db } from '@oyster/db';
import { FORMATTED_RACE, Race, WorkAuthorizationStatus } from '@oyster/types';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"./object-storage": "./src/modules/object-storage/index.ts",
"./resources": "./src/modules/resource/index.ts",
"./resources.server": "./src/modules/resource/index.server.ts",
"./resume-books": "./src/modules/resume-book/index.ts",
"./resume-books.server": "./src/modules/resume-book/index.server.ts",
"./resume-books": "./src/modules/resume-book/resume-book.core.ts",
"./resume-books.types": "./src/modules/resume-book/resume-book.types.ts",
"./slack.server": "./src/modules/slack/index.server.ts"
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/member-profile.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export { changePrimaryEmail } from './modules/member/use-cases/change-primary-em
export { joinMemberDirectory } from './modules/member/use-cases/join-member-directory';
export { updateAllowEmailShare } from './modules/member/use-cases/update-allow-email-share';
export { updateMember } from './modules/member/use-cases/update-member';
export { createResumeBook } from './modules/resume-book/use-cases/create-resume-book';
export { reportException } from './modules/sentry/use-cases/report-exception';
export { countMessagesSent } from './modules/slack/queries/count-messages-sent';
export { getSwagPackInventory } from './modules/swag-pack/swag-pack.service';
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/modules/resume-book/index.server.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/modules/resume-book/index.ts

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions packages/core/src/modules/resume-book/queries/get-resume-book.ts

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions packages/core/src/modules/resume-book/queries/list-resume-books.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,135 @@
import dayjs from 'dayjs';
import { type SelectExpression } from 'kysely';
import { match } from 'ts-pattern';

import { db, point } from '@oyster/db';
import { type DB, db, point } from '@oyster/db';
import { FORMATTED_RACE } from '@oyster/types';
import { iife } from '@oyster/utils';
import { id, iife } from '@oyster/utils';

import { job } from '@/infrastructure/bull/use-cases/job';
import { createAirtableRecord } from '@/modules/airtable/use-cases/create-airtable-record';
import { updateAirtableRecord } from '@/modules/airtable/use-cases/update-airtable-record';
import { type DegreeType } from '@/modules/education/education.types';
import { getPresignedURL, putObject } from '@/modules/object-storage';
import { getResumeBookSubmission } from '@/modules/resume-book/queries/get-resume-book-submission';
import { type SubmitResumeInput } from '@/modules/resume-book/resume-book.types';
import {
type CreateResumeBookInput,
type SubmitResumeInput,
} from '@/modules/resume-book/resume-book.types';

// Queries

type GetResumeBookOptions<Selection> = {
select: Selection[];
where: { id: string };
};

export async function getResumeBook<
Selection extends SelectExpression<DB, 'resumeBooks'>,
>({ select, where }: GetResumeBookOptions<Selection>) {
const resumeBook = await db
.selectFrom('resumeBooks')
.select(select)
.where('id', '=', where.id)
.executeTakeFirst();

return resumeBook;
}

type GetResumeBookSubmissionOptions<Selection> = {
select: Selection[];
where: {
memberId: string;
resumeBookId: string;
};
};

export async function getResumeBookSubmission<
Selection extends SelectExpression<DB, 'resumeBookSubmissions'>,
>({ select, where }: GetResumeBookSubmissionOptions<Selection>) {
const submission = await db
.selectFrom('resumeBookSubmissions')
.select(select)
.where('memberId', '=', where.memberId)
.where('resumeBookId', '=', where.resumeBookId)
.executeTakeFirst();

return submission;
}

export async function listResumeBooks() {
const resumeBooks = await db
.selectFrom('resumeBooks')
.select([
'airtableBaseId',
'airtableTableId',
'endDate',
'id',
'name',
'startDate',

(eb) => {
return eb
.selectFrom('resumeBookSubmissions')
.select((eb) => eb.fn.countAll().as('submissions'))
.whereRef('resumeBooks.id', '=', 'resumeBookSubmissions.resumeBookId')
.as('submissions');
},
])
.orderBy('startDate', 'desc')
.orderBy('endDate', 'desc')
.execute();

return resumeBooks;
}

type ListResumeBookSponsorsOptions = {
where: { resumeBookId: string };
};

export async function listResumeBookSponsors({
where,
}: ListResumeBookSponsorsOptions) {
const sponsors = await db
.selectFrom('resumeBookSponsors')
.leftJoin('companies', 'companies.id', 'resumeBookSponsors.companyId')
.select(['companies.id', 'companies.name'])
.where('resumeBookId', '=', where.resumeBookId)
.execute();

return sponsors;
}

// Mutations

export async function createResumeBook(input: CreateResumeBookInput) {
await db.transaction().execute(async (trx) => {
const resumeBookId = id();

await trx
.insertInto('resumeBooks')
.values({
airtableBaseId: input.airtableBaseId,
airtableTableId: input.airtableTableId,
endDate: input.endDate,
id: resumeBookId,
name: input.name,
startDate: input.startDate,
})
.execute();

await trx
.insertInto('resumeBookSponsors')
.values(
input.sponsors.map((sponsor) => {
return {
companyId: sponsor,
resumeBookId,
};
})
)
.execute();
});
}

export async function submitResume({
codingLanguages,
Expand Down

This file was deleted.

0 comments on commit 3c64ebf

Please sign in to comment.