mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +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.
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { CollectionMembers } from '../../../src/db/entities/CollectionMembers.entity';
|
|
import { CollectionPlaces } from '../../../src/db/entities/CollectionPlaces.entity';
|
|
import { Collections } from '../../../src/db/entities/Collections.entity';
|
|
import { inContext, nextSeq, type FactoryOrm } from './context';
|
|
import { createRow } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type CollectionRow = EntityDTO<Collections>;
|
|
export type CollectionPlaceRow = EntityDTO<CollectionPlaces>;
|
|
|
|
/** A collection owned by `ownerId`. */
|
|
export function makeCollection(
|
|
orm: FactoryOrm,
|
|
ownerId: number,
|
|
overrides: EntityData<Collections> = {},
|
|
): Promise<CollectionRow> {
|
|
return createRow(
|
|
orm,
|
|
Collections,
|
|
{
|
|
owner: ownerId,
|
|
name: `Test Collection ${nextSeq('collection')}`,
|
|
},
|
|
overrides,
|
|
);
|
|
}
|
|
|
|
/** Invites the user into the collection; `status: 'accepted'` makes them a member right away. */
|
|
export function addCollectionMember(
|
|
orm: FactoryOrm,
|
|
collectionId: number,
|
|
userId: number,
|
|
overrides: EntityData<CollectionMembers> = {},
|
|
): Promise<EntityDTO<CollectionMembers>> {
|
|
return createRow(
|
|
orm,
|
|
CollectionMembers,
|
|
{
|
|
collection: collectionId,
|
|
user: userId,
|
|
status: 'accepted',
|
|
role: 'editor',
|
|
},
|
|
overrides,
|
|
);
|
|
}
|
|
|
|
/** A place saved into the collection by `ownerId`. */
|
|
export function makeCollectionPlace(
|
|
orm: FactoryOrm,
|
|
collectionId: number,
|
|
ownerId: number,
|
|
overrides: EntityData<CollectionPlaces> = {},
|
|
): Promise<CollectionPlaceRow> {
|
|
return createRow(
|
|
orm,
|
|
CollectionPlaces,
|
|
{
|
|
collection: collectionId,
|
|
owner: ownerId,
|
|
name: `Saved Place ${nextSeq('collection-place')}`,
|
|
lat: 48.8566,
|
|
lng: 2.3522,
|
|
},
|
|
overrides,
|
|
);
|
|
}
|
|
|
|
/** Puts the tags on the saved place. */
|
|
export async function tagCollectionPlace(orm: FactoryOrm, collectionPlaceId: number, tagIds: number[]): Promise<void> {
|
|
await inContext(orm, (em) => em.getRepository(CollectionPlaces).attachTags(collectionPlaceId, tagIds));
|
|
}
|
|
|
|
/** Files the saved place under the collection label. */
|
|
export async function labelCollectionPlace(orm: FactoryOrm, collectionPlaceId: number, labelId: number): Promise<void> {
|
|
await inContext(orm, (em) => em.getRepository(CollectionPlaces).assignLabel(collectionPlaceId, labelId));
|
|
}
|