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.
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { TodoItems } from '../../../src/db/entities/TodoItems.entity';
|
|
import { inContext, type FactoryOrm } from './context';
|
|
import { createRow } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type TodoItemRow = EntityDTO<TodoItems>;
|
|
|
|
/** An open to-do on the trip, appended after the trip's last one. */
|
|
export async function makeTodoItem(
|
|
orm: FactoryOrm,
|
|
tripId: number,
|
|
overrides: EntityData<TodoItems> = {},
|
|
): Promise<TodoItemRow> {
|
|
const sortOrder =
|
|
overrides.sort_order ??
|
|
(await inContext(orm, async (em) => {
|
|
const last = await em.findOne(
|
|
TodoItems,
|
|
{ trip: tripId },
|
|
{ orderBy: { sort_order: 'desc' }, disableIdentityMap: true },
|
|
);
|
|
return last?.sort_order == null ? 0 : last.sort_order + 1;
|
|
}));
|
|
return createRow(
|
|
orm,
|
|
TodoItems,
|
|
{
|
|
trip: tripId,
|
|
name: 'Test Todo',
|
|
checked: 0,
|
|
category: null,
|
|
sort_order: sortOrder,
|
|
},
|
|
{ ...overrides, sort_order: sortOrder },
|
|
);
|
|
}
|