mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
f69a4c1a24
- A user can group the uses of one place (trip places and saved places) into a place identity of their own (user_places, user_place_links). It is personal: it groups their "All places" and is never written into a shared trip or list row. An identity without a use they can still reach is not shown, and one left without links is pruned on their next write and nightly. - Possible duplicates are suggested server side (same provider id, or the same name at the same spot), each pair with what differs and whether the user may merge it. A merge joins two identities in one transaction and can be undone; a dismissed pair does not come back. No trip or list row is deleted or changed. - A trip can link lists (trip_collection_links, needs place_edit and access to the list). A member sees a linked list only with their own access to it; the map layer lists its places and whether each is already in the trip. tripCollections:changed tells the members to read their view again. - REST, MCP tools and client data layer for all of it; migrations on both engines, additive only. - CI: the stage 1 to 2 places-library helper types, and the await-in-loop and non-null counts it had raised.
83 lines
3.2 KiB
TypeScript
83 lines
3.2 KiB
TypeScript
import { ADDON_IDS } from '../../addons';
|
|
import type { User } from '../../types';
|
|
import { AddonGuard } from '../addons/addon.guard';
|
|
import { RequireAddon } from '../addons/require-addon.decorator';
|
|
import { CurrentUser } from '../auth-core/current-user.decorator';
|
|
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
|
import { ResponseContract } from '../common/response-contract';
|
|
import { rowId } from '../common/row-id.pipe';
|
|
import { PlaceDuplicatesService } from './place-duplicates.service';
|
|
import { PlaceIdentitiesService } from './place-identities.service';
|
|
import {
|
|
PlacesLibraryDuplicatesQueryDto,
|
|
PlacesLibraryLinkDto,
|
|
PlacesLibraryMergeDto,
|
|
PlacesLibraryPairDto,
|
|
PlacesLibraryUnlinkDto,
|
|
} from './places-library.dto';
|
|
import { Body, Controller, Get, HttpCode, Param, Post, Query, UseGuards } from '@nestjs/common';
|
|
import {
|
|
placesLibraryDuplicatesResponseSchema,
|
|
placesLibraryEntryResponseSchema,
|
|
placesLibraryMergeResponseSchema,
|
|
successResponseSchema,
|
|
} from '@trek/shared';
|
|
|
|
/**
|
|
* D5/PLC-13 under /api/addons/collections/library: the user's own places in
|
|
* "All places". Assigning uses to one, taking one out, the duplicate
|
|
* suggestions, merging two entries and undoing it. Everything here is the
|
|
* user's own and changes no trip place and no saved place, so nothing is
|
|
* broadcast. Behind the Collections addon like the rest of the library.
|
|
*/
|
|
@Controller('api/addons/collections/library')
|
|
@UseGuards(AddonGuard, JwtAuthGuard)
|
|
@RequireAddon(ADDON_IDS.COLLECTIONS, 'Collections')
|
|
export class PlaceIdentitiesController {
|
|
constructor(
|
|
private readonly identities: PlaceIdentitiesService,
|
|
private readonly duplicates: PlaceDuplicatesService,
|
|
) {}
|
|
|
|
@Post('places/link')
|
|
@HttpCode(200)
|
|
@ResponseContract(placesLibraryEntryResponseSchema)
|
|
async link(@CurrentUser() user: User, @Body() body: PlacesLibraryLinkDto) {
|
|
return this.identities.link({ id: user.id, role: user.role }, body);
|
|
}
|
|
|
|
@Post('places/unlink')
|
|
@HttpCode(200)
|
|
@ResponseContract(placesLibraryEntryResponseSchema)
|
|
async unlink(@CurrentUser() user: User, @Body() body: PlacesLibraryUnlinkDto) {
|
|
return this.identities.unlink({ id: user.id, role: user.role }, body);
|
|
}
|
|
|
|
@Get('duplicates')
|
|
@ResponseContract(placesLibraryDuplicatesResponseSchema)
|
|
async listDuplicates(@CurrentUser() user: User, @Query() query: PlacesLibraryDuplicatesQueryDto) {
|
|
return this.duplicates.list({ id: user.id, role: user.role }, query);
|
|
}
|
|
|
|
@Post('duplicates/dismiss')
|
|
@HttpCode(200)
|
|
@ResponseContract(successResponseSchema)
|
|
async dismiss(@CurrentUser() user: User, @Body() body: PlacesLibraryPairDto) {
|
|
return this.identities.dismiss(user.id, body.a, body.b);
|
|
}
|
|
|
|
@Post('merges')
|
|
@HttpCode(200)
|
|
@ResponseContract(placesLibraryMergeResponseSchema)
|
|
async merge(@CurrentUser() user: User, @Body() body: PlacesLibraryMergeDto) {
|
|
return this.identities.merge({ id: user.id, role: user.role }, body.leading, body.other);
|
|
}
|
|
|
|
@Post('merges/:id/undo')
|
|
@HttpCode(200)
|
|
@ResponseContract(successResponseSchema)
|
|
async undoMerge(@CurrentUser() user: User, @Param('id', rowId('Merge not found')) id: number) {
|
|
return this.identities.undoMerge({ id: user.id, role: user.role }, id);
|
|
}
|
|
}
|