mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 07:53:09 +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.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { BudgetItemMembers } from '../../../src/db/entities/BudgetItemMembers.entity';
|
|
import { BudgetItemPayers } from '../../../src/db/entities/BudgetItemPayers.entity';
|
|
import { BudgetItems } from '../../../src/db/entities/BudgetItems.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { createRow } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type BudgetItemRow = EntityDTO<BudgetItems>;
|
|
|
|
/** An expense on the trip: "Test Budget Item", Transport, 100 in the trip currency. */
|
|
export function makeBudgetItem(
|
|
orm: FactoryOrm,
|
|
tripId: number,
|
|
overrides: EntityData<BudgetItems> = {},
|
|
): Promise<BudgetItemRow> {
|
|
return createRow(orm, BudgetItems, {
|
|
trip: tripId,
|
|
name: 'Test Budget Item',
|
|
category: 'Transport',
|
|
total_price: 100,
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
/** Adds the user to the expense's split, with an explicit share when `amount` is given. */
|
|
export function addBudgetItemMember(
|
|
orm: FactoryOrm,
|
|
budgetItemId: number,
|
|
userId: number,
|
|
overrides: EntityData<BudgetItemMembers> = {},
|
|
): Promise<EntityDTO<BudgetItemMembers>> {
|
|
return createRow(orm, BudgetItemMembers, { budgetItem: budgetItemId, user: userId, ...overrides });
|
|
}
|
|
|
|
/** Records that the user paid `amount` of the expense. */
|
|
export function addBudgetItemPayer(
|
|
orm: FactoryOrm,
|
|
budgetItemId: number,
|
|
userId: number,
|
|
amount: number,
|
|
): Promise<EntityDTO<BudgetItemPayers>> {
|
|
return createRow(orm, BudgetItemPayers, { budgetItem: budgetItemId, user: userId, amount });
|
|
}
|