mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +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.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { BucketList } from '../../../src/db/entities/BucketList.entity';
|
|
import { VisitedCountries } from '../../../src/db/entities/VisitedCountries.entity';
|
|
import { VisitedRegions } from '../../../src/db/entities/VisitedRegions.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { createRow, insertRowIgnoringConflict } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type BucketListRow = EntityDTO<BucketList>;
|
|
|
|
/** A destination on the user's bucket list. */
|
|
export function makeBucketListItem(
|
|
orm: FactoryOrm,
|
|
userId: number,
|
|
overrides: EntityData<BucketList> = {},
|
|
): Promise<BucketListRow> {
|
|
return createRow(orm, BucketList, {
|
|
user: userId,
|
|
name: 'Test Destination',
|
|
lat: null,
|
|
lng: null,
|
|
country_code: null,
|
|
notes: null,
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
/** Marks the country visited by hand; marking it twice is a no-op. The code is upper-cased as the atlas stores it. */
|
|
export async function markCountryVisited(orm: FactoryOrm, userId: number, countryCode: string): Promise<void> {
|
|
await insertRowIgnoringConflict(orm, VisitedCountries, { user: userId, country_code: countryCode.toUpperCase() });
|
|
}
|
|
|
|
/** Marks the region visited; marking it twice is a no-op. */
|
|
export async function markRegionVisited(
|
|
orm: FactoryOrm,
|
|
userId: number,
|
|
region: { region_code: string; region_name: string; country_code: string },
|
|
): Promise<void> {
|
|
await insertRowIgnoringConflict(orm, VisitedRegions, { user: userId, ...region });
|
|
}
|