mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +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.
142 lines
4.7 KiB
TypeScript
142 lines
4.7 KiB
TypeScript
import type { User } from '../../types';
|
|
import { CurrentUser } from '../auth-core/current-user.decorator';
|
|
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
|
import { AddTripPhotosDto, CreateAlbumLinkDto, RemoveTripPhotoDto, SetTripPhotoSharingDto } from './memories.dto';
|
|
import type { Selection } from './memories.helpers';
|
|
import { MemoriesService } from './memories.service';
|
|
import { Body, Controller, Delete, Get, Headers, HttpCode, Param, Post, Put, Res, UseGuards } from '@nestjs/common';
|
|
|
|
import type { Response } from 'express';
|
|
|
|
/**
|
|
* /api/integrations/memories/unified — provider-agnostic trip photo + album-link
|
|
* management.
|
|
*
|
|
* Byte-identical to the legacy Express router (server/src/routes/memories/unified.ts):
|
|
* bare `authenticate` (JwtAuthGuard), success bodies on 200, and the per-result
|
|
* error envelope `{ error }` at `result.error.status` reused from the unified
|
|
* service. Lenient hand-rolled body coercion is preserved — no Zod here.
|
|
*/
|
|
@Controller('api/integrations/memories/unified')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class UnifiedMemoriesController {
|
|
constructor(private readonly memories: MemoriesService) {}
|
|
|
|
@Get('trips/:tripId/photos')
|
|
async listPhotos(@CurrentUser() user: User, @Param('tripId') tripId: string, @Res() res: Response): Promise<void> {
|
|
const result = await this.memories.listTripPhotos(tripId, user.id);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ photos: result.data });
|
|
}
|
|
|
|
@Post('trips/:tripId/photos')
|
|
@HttpCode(200)
|
|
async addPhotos(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Body() body: AddTripPhotosDto,
|
|
@Headers('x-socket-id') sid: string,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const selections: Selection[] = Array.isArray(body?.selections) ? (body.selections as Selection[]) : [];
|
|
const shared = body?.shared === undefined ? true : !!body?.shared;
|
|
const result = await this.memories.addTripPhotos(tripId, user.id, shared, selections, sid);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ success: true, added: result.data.added });
|
|
}
|
|
|
|
@Put('trips/:tripId/photos/sharing')
|
|
async setSharing(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Body() body: SetTripPhotoSharingDto,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const result = await this.memories.setTripPhotoSharing(
|
|
tripId,
|
|
user.id,
|
|
Number(body?.photo_id),
|
|
body?.shared as boolean,
|
|
);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ success: true });
|
|
}
|
|
|
|
@Delete('trips/:tripId/photos')
|
|
async removePhoto(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Body() body: RemoveTripPhotoDto,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const result = await this.memories.removeTripPhoto(tripId, user.id, Number(body?.photo_id));
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ success: true });
|
|
}
|
|
|
|
@Get('trips/:tripId/album-links')
|
|
async listAlbumLinks(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const result = await this.memories.listTripAlbumLinks(tripId, user.id);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ links: result.data });
|
|
}
|
|
|
|
@Post('trips/:tripId/album-links')
|
|
@HttpCode(200)
|
|
async createAlbumLink(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Body() body: CreateAlbumLinkDto,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const passphrase = body?.passphrase ? String(body.passphrase) : undefined;
|
|
const result = await this.memories.createTripAlbumLink(
|
|
tripId,
|
|
user.id,
|
|
body?.provider,
|
|
body?.album_id,
|
|
body?.album_name,
|
|
passphrase,
|
|
);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ success: true });
|
|
}
|
|
|
|
@Delete('trips/:tripId/album-links/:linkId')
|
|
async removeAlbumLink(
|
|
@CurrentUser() user: User,
|
|
@Param('tripId') tripId: string,
|
|
@Param('linkId') linkId: string,
|
|
@Res() res: Response,
|
|
): Promise<void> {
|
|
const result = await this.memories.removeAlbumLink(tripId, linkId, user.id);
|
|
if ('error' in result) {
|
|
res.status(result.error.status).json({ error: result.error.message });
|
|
return;
|
|
}
|
|
res.json({ success: true });
|
|
}
|
|
}
|