mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { VacayEntries } from '../../../src/db/entities/VacayEntries.entity';
|
|
import { VacayPlanMembers } from '../../../src/db/entities/VacayPlanMembers.entity';
|
|
import { VacayPlans } from '../../../src/db/entities/VacayPlans.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { createRow } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type VacayPlanRow = EntityDTO<VacayPlans>;
|
|
|
|
/** A vacation plan owned by `ownerId`, with the plan defaults the migration sets. */
|
|
export function makeVacayPlan(
|
|
orm: FactoryOrm,
|
|
ownerId: number,
|
|
overrides: EntityData<VacayPlans> = {},
|
|
): Promise<VacayPlanRow> {
|
|
return createRow(orm, VacayPlans, { owner: ownerId, ...overrides });
|
|
}
|
|
|
|
/** Invites the user into the plan; `status: 'accepted'` (the default here) makes them a member. */
|
|
export function addVacayPlanMember(
|
|
orm: FactoryOrm,
|
|
planId: number,
|
|
userId: number,
|
|
status: 'pending' | 'accepted' = 'accepted',
|
|
): Promise<EntityDTO<VacayPlanMembers>> {
|
|
return createRow(orm, VacayPlanMembers, { plan: planId, user: userId, status });
|
|
}
|
|
|
|
/** A full vacation day for the user in the plan. */
|
|
export function makeVacayEntry(
|
|
orm: FactoryOrm,
|
|
planId: number,
|
|
userId: number,
|
|
date: string,
|
|
overrides: EntityData<VacayEntries> = {},
|
|
): Promise<EntityDTO<VacayEntries>> {
|
|
return createRow(orm, VacayEntries, { plan: planId, user: userId, date, ...overrides });
|
|
}
|