feat(favorites): keep customer favourites on the server, as legacy did (FAV-01)

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>
This commit is contained in:
s.esmaeili
2026-10-08 10:54:17 +03:30
co-authored by Claude Opus 5.5
parent 5480398a93
commit 5d386bf752
10 changed files with 257 additions and 34 deletions
@@ -0,0 +1,30 @@
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);
}
}