Both apps kept favourites in memory only, and the API had no route, so the 874 favourites imported from legacy major_favorites never showed. - GET customer/me/favorites, POST customer/me/favorites/toggle - apps load them on sign-in, clear on sign-out, toggle optimistically and roll back on failure Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common';
|
|
import { CurrentCustomer, CustomerAuth } from '../customer-auth/customer.guards';
|
|
import type { AuthenticatedCustomer } from '../customer-auth/customer-jwt.strategy';
|
|
import { CustomerFavoritesService } from './customer-favorites.service';
|
|
import { ToggleFavoriteDto } from './dto/toggle-favorite.dto';
|
|
|
|
/**
|
|
* Legacy endpoints (routes/api.php:84-85, customer guard):
|
|
* POST add-to-fav -> POST customer/me/favorites/toggle
|
|
* POST get-favorites -> GET customer/me/favorites
|
|
* The customer always comes from the token (D21); for a sales expert that is
|
|
* their trading account.
|
|
*/
|
|
@Controller('customer/me/favorites')
|
|
export class CustomerFavoritesController {
|
|
constructor(private readonly favorites: CustomerFavoritesService) {}
|
|
|
|
@CustomerAuth()
|
|
@Get()
|
|
list(@CurrentCustomer() me: AuthenticatedCustomer) {
|
|
return this.favorites.list(me.id);
|
|
}
|
|
|
|
@CustomerAuth()
|
|
@Post('toggle')
|
|
@HttpCode(200)
|
|
toggle(@Body() dto: ToggleFavoriteDto, @CurrentCustomer() me: AuthenticatedCustomer) {
|
|
return this.favorites.toggle(me.id, dto.productId);
|
|
}
|
|
}
|