dorfteich/apps/api/src/watches/watches.controller.ts
Claude Fable 5 f4f27cbe78
All checks were successful
CI / Lint, typecheck, test (push) Successful in 3m23s
CI / Build container images (push) Has been skipped
CD / Build and push images (push) Successful in 3m47s
CD / Deploy to Test (push) Successful in 11s
CD / Smoke tests against Test (push) Successful in 1m14s
CD / Promote to Int (push) Successful in 10s
CI / Auth e2e pack (push) Successful in 5m28s
CI / Import/export fidelity gate (push) Successful in 46s
Add watches: follow pages and ponds with auto-watch preferences (#93)
New watches table (polymorphic target, unique per user+target; page purge
removes its rows via the trash service, and the list endpoint drops
targets the user can no longer read). Endpoints: idempotent PUT/DELETE
/watches/{page|pond}/:id gated by read access (404 hides the target),
GET state for the header toggles, and GET /users/me/watches resolving
names and links. Auto-watch hooks: creating a page and commenting
subscribe the actor, each behind a new user preference
(autoWatchOwnPages / autoWatchOnComment, default on) editable via the
profile PATCH and surfaced as checkboxes in the settings. UI: watch
toggle on the page header and the pond settings header, watch list with
unwatch in the account settings; new watches i18n namespace (de+en).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
2026-07-11 22:59:11 +02:00

60 lines
1.8 KiB
TypeScript

import { Controller, Delete, Get, Param, Put, Req } from '@nestjs/common';
import {
WATCH_TARGET_TYPES,
type WatchListView,
type WatchStateView,
type WatchTargetType,
} from '@dorfteich/shared';
import { NotFoundException } from '@nestjs/common';
import { AuthedRequest } from '../auth/auth.guard';
import { AuthenticatedOnly } from '../permissions/permission.decorators';
import { WatchesService } from './watches.service';
function asTargetType(value: string): WatchTargetType {
if (!(WATCH_TARGET_TYPES as readonly string[]).includes(value)) throw new NotFoundException();
return value as WatchTargetType;
}
/** Watch/unwatch pages and ponds + the account's watch list (issue #93). */
@Controller()
export class WatchesController {
constructor(private readonly watches: WatchesService) {}
@Get('users/me/watches')
@AuthenticatedOnly()
async list(@Req() request: AuthedRequest): Promise<WatchListView> {
return this.watches.listOwn(request.user!);
}
@Get('watches/:targetType/:id')
@AuthenticatedOnly()
async state(
@Param('targetType') targetType: string,
@Param('id') id: string,
@Req() request: AuthedRequest,
): Promise<WatchStateView> {
return this.watches.state(request.user!, asTargetType(targetType), id);
}
@Put('watches/:targetType/:id')
@AuthenticatedOnly()
async watch(
@Param('targetType') targetType: string,
@Param('id') id: string,
@Req() request: AuthedRequest,
): Promise<WatchStateView> {
return this.watches.watch(request.user!, asTargetType(targetType), id);
}
@Delete('watches/:targetType/:id')
@AuthenticatedOnly()
async unwatch(
@Param('targetType') targetType: string,
@Param('id') id: string,
@Req() request: AuthedRequest,
): Promise<WatchStateView> {
return this.watches.unwatch(request.user!, asTargetType(targetType), id);
}
}