feat: add trip preference overrides with precedence resolution

This commit is contained in:
Bastian Wagner
2026-08-17 15:38:03 +02:00
parent ee7ec94ea0
commit dedb3fff40
12 changed files with 373 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import {
Body,
Controller,
Delete,
ForbiddenException,
Get,
Param,
Put,
UseGuards,
} from '@nestjs/common';
import { OidcAuthGuard } from '../../../../libs/auth/src';
import type { AuthenticatedUser } from '../../../../libs/auth/src';
import {
TripMembershipGuard,
TripPreferenceOverridesService,
} from '../../../../libs/trips/src';
import type {
TripMemberRole,
TripPreferenceOverride,
UpsertPreferenceOverrideDto,
} from '../../../../libs/trips/src';
import { CurrentUser } from '../auth/current-user.decorator';
import { CurrentTripRole } from './current-trip-role.decorator';
@Controller('trips/:tripId/preference-overrides')
@UseGuards(OidcAuthGuard, TripMembershipGuard)
export class TripPreferenceOverridesController {
constructor(private readonly service: TripPreferenceOverridesService) {}
@Get()
list(@Param('tripId') tripId: string): Promise<TripPreferenceOverride[]> {
return this.service.listOverrides(tripId);
}
@Put()
async upsert(
@Param('tripId') tripId: string,
@CurrentUser() currentUser: AuthenticatedUser,
@CurrentTripRole() role: TripMemberRole,
@Body() dto: UpsertPreferenceOverrideDto,
): Promise<TripPreferenceOverride> {
const isOwnUserOverride =
dto.subject.type === 'USER' && dto.subject.userId === currentUser.id;
if (role !== 'OWNER' && !isOwnUserOverride) {
throw new ForbiddenException(
'Only the trip owner may set preference overrides for other members or travelers',
);
}
return this.service.upsertOverride(tripId, dto.subject, dto.overrides);
}
@Delete(':overrideId')
remove(
@Param('tripId') tripId: string,
@Param('overrideId') overrideId: string,
): Promise<void> {
return this.service.removeOverride(tripId, overrideId);
}
}