Skip to content

Commit

Permalink
refactor: use @oyster/db directly in core 🍎 (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou authored Jul 31, 2024
1 parent 30fcde4 commit 8b3e3a1
Show file tree
Hide file tree
Showing 75 changed files with 115 additions and 91 deletions.
1 change: 0 additions & 1 deletion packages/core/src/infrastructure/database/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sql } from 'kysely';

import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { cache } from '@/infrastructure/redis';
import { LeaderboardPosition } from '../shared/active-status.shared';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sql } from 'kysely';

import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

const streakGroup = sql<number>`
row_number() over (partition by student_id order by date desc) -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dayjs from 'dayjs';

import { db } from '@oyster/db';
import { type StudentActiveStatus } from '@oyster/types';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { db } from '@/infrastructure/database';

export async function backfillActiveStatuses({
studentId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dayjs from 'dayjs';

import { db } from '@oyster/db';
import { type StudentActiveStatus } from '@oyster/types';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { db } from '@/infrastructure/database';

type CreateNewActiveStatusesInput = GetBullJobData<'student.statuses.new'>;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/admin/use-cases/add-admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { db } from '@/infrastructure/database';
import { type AddAdminInput } from '../admin.types';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/airtable/airtable.core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { match } from 'ts-pattern';
import { z } from 'zod';

import { db } from '@oyster/db';
import {
FORMATTED_DEMOGRAPHICS,
FORMATTED_GENDER,
Expand All @@ -13,7 +14,6 @@ import {
type GetBullJobData,
} from '@/infrastructure/bull/bull.types';
import { registerWorker } from '@/infrastructure/bull/use-cases/register-worker';
import { db } from '@/infrastructure/database';
import { IS_PRODUCTION } from '@/shared/env';
import { ColorStackError, ErrorWithContext } from '@/shared/errors';
import { RateLimiter } from '@/shared/utils/rate-limiter';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '@oyster/db';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { db } from '@/infrastructure/database';

export async function expireOneTimeCode({
oneTimeCodeId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { match } from 'ts-pattern';

import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { getMemberByEmail } from '@/modules/member/queries/get-member-by-email';
import { signToken } from '@/shared/utils/auth.utils';
import { type OAuthCodeState } from '../authentication.types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { match } from 'ts-pattern';

import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { sendEmail } from '@/modules/notification/use-cases/send-email';
import { IS_DEVELOPMENT } from '@/shared/env';
import type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { match } from 'ts-pattern';

import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { IS_DEVELOPMENT } from '@/shared/env';
import {
type OneTimeCodePurpose,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { checkMostRecentEducation } from './check-most-recent-education';
import { type AddEducationInput } from '../education.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import {
AIRTABLE_FAMILY_BASE_ID,
AIRTABLE_MEMBERS_TABLE_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { checkMostRecentEducation } from './check-most-recent-education';
import { type Education } from '../education.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { checkMostRecentEducation } from './check-most-recent-education';
import { type Education } from '../education.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { type SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';
import { type DB, db } from '@oyster/db';

import { db } from '@/infrastructure/database';
import { type WorkExperience } from '../employment.types';

type GetWorkExperienceQuery = Pick<WorkExperience, 'id' | 'studentId'>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sql } from 'kysely';

import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { type ListJobOffersWhere } from '../employment.types';

type ListJobOffersOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dayjs from 'dayjs';

import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

type ListWorkExperiencesOptions = {
include?: 'hasReviewed'[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { saveCompanyIfNecessary } from './save-company-if-necessary';
import { type AddWorkExperienceInput } from '../employment.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { type DeleteWorkExperienceInput } from '../employment.types';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { saveCompanyIfNecessary } from './save-company-if-necessary';
import { type EditWorkExperienceInput } from '../employment.types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from '@oyster/db';
import { company1, company4 } from '@oyster/db/test/constants';

import { db } from '@/infrastructure/database';
import { saveCompanyIfNecessary } from './save-company-if-necessary';
import * as module from '../queries/get-crunchbase-organization';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type Transaction } from 'kysely';

import { type DB } from '@oyster/db';
import { type DB, db } from '@oyster/db';
import { id } from '@oyster/utils';

import { db } from '@/infrastructure/database';
import { getCrunchbaseOrganization } from '../queries/get-crunchbase-organization';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sql } from 'kysely';

import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { db } from '@/infrastructure/database';
import { type UploadJobOfferInput } from '../employment.types';

export async function uploadJobOffer({
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/modules/event/event.core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '@oyster/db';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { ActivityType } from '@/modules/gamification/gamification.types';

type CheckIntoEventInput = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/event/events/event-registered.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { db } from '@oyster/db';
import type { Gender } from '@oyster/types';
import { FORMATTED_GENDER } from '@oyster/types';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';

export async function onRegisteredForEvent({
eventId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { db } from '@oyster/db';
import { type EventAttendee } from '@oyster/types';

import { db } from '@/infrastructure/database';

type CountEventAttendeesOptions = {
where: Partial<Pick<EventAttendee, 'eventId' | 'studentId'>>;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

export async function countPastEvents() {
const result = await db
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

export async function countUpcomingEvents() {
const result = await db
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/modules/event/queries/get-event.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';
import { type DB, db } from '@oyster/db';
import { type EventType } from '@oyster/types';

import { db } from '@/infrastructure/database';

type GetEventOptions = {
include?: 'isCheckedIn'[];
memberId?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { type SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';
import { type DB, db } from '@oyster/db';
import { type EventAttendee } from '@oyster/types';

import { db } from '@/infrastructure/database';

type ListEventAttendeesOptions<Selection> = {
select: Selection[];
where: Pick<EventAttendee, 'eventId'>;
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/modules/event/queries/list-events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { type SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';

import { db } from '@/infrastructure/database';
import { type DB, db } from '@oyster/db';

type ListEventsQuery = Partial<{
limit: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { db } from '@/infrastructure/database';
import { db } from '@oyster/db';

import { type AddEventRecordingLinkInput } from '@/modules/event/event.types';

export async function addEventRecordingLink(
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/modules/event/use-cases/create-event.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import dayjs from 'dayjs';

import { db } from '@oyster/db';
import { type Event } from '@oyster/types';
import { id } from '@oyster/utils';

import { db } from '@/infrastructure/database';

type CreateEventInput = Pick<Event, 'description' | 'name' | 'type'> & {
endTime: string;
startTime: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { db } from '@oyster/db';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { registerForAirmeetEvent } from '../airmeet-event.service';

export async function registerForEvent({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { db } from '@oyster/db';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { getMemberByEmail } from '@/modules/member/queries/get-member-by-email';
import { NotFoundError } from '@/shared/errors';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';

import { db } from '@/infrastructure/database';
import { type DB, db } from '@oyster/db';

export async function getIcebreakerPrompts<
Selection extends SelectExpression<DB, 'icebreakerPrompts'>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { SelectExpression } from 'kysely';

import { type DB } from '@oyster/db';

import { db } from '@/infrastructure/database';
import { type DB, db } from '@oyster/db';

export async function getIcebreakerResponses<
Selection extends SelectExpression<DB, 'icebreakerResponses'>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from '@oyster/db';
import { id } from '@oyster/utils';

import { db } from '@/infrastructure/database';
import { type AddIcebreakerPromptInput } from '../icebreaker.types';

export async function addIcebreakerPrompt(input: AddIcebreakerPromptInput) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mailchimp, { type Mailchimp } from '@mailchimp/mailchimp_marketing';

import { db } from '@oyster/db';
import {
type EmailCampaign,
type EmailCampaignClick,
Expand All @@ -10,7 +11,6 @@ import { id } from '@oyster/utils';

import { type GetBullJobData } from '@/infrastructure/bull/bull.types';
import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { getMemberByEmail } from '@/modules/member/queries/get-member-by-email';
import { NotFoundError } from '@/shared/errors';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mailchimp, { type Mailchimp } from '@mailchimp/mailchimp_marketing';

import { db } from '@oyster/db';
import { type EmailCampaign, type EmailList } from '@oyster/types';

import { job } from '@/infrastructure/bull/use-cases/job';
import { db } from '@/infrastructure/database';
import { ENV } from '@/shared/env';
import { NotFoundError } from '@/shared/errors';

Expand Down
Loading

0 comments on commit 8b3e3a1

Please sign in to comment.