mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
188c6153d5
The assistant tables gave Users three more relations, and a spread of overrides checked against RequiredEntityData now ran tsc past its instantiation depth (TS2589). Every factory passes its overrides as createRow's own argument, the way rows.ts documents it.
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);
|
|
}
|