import { Controller, Get, Patch, Body, Req, UseInterceptors, ClassSerializerInterceptor, UsePipes, } from "@nestjs/common"; import { UsersService } from "./users.service"; import { ZodValidationPipe } from "@bff/core/validation"; import { updateCustomerProfileRequestSchema, type UpdateCustomerProfileRequest, } from "@customer-portal/domain/auth"; import type { RequestWithUser } from "@bff/modules/auth/auth.types"; @Controller("me") @UseInterceptors(ClassSerializerInterceptor) export class UsersController { constructor(private usersService: UsersService) {} /** * GET /me - Get complete customer profile (includes address) * Profile data fetched from WHMCS (single source of truth) */ @Get() async getProfile(@Req() req: RequestWithUser) { return this.usersService.findById(req.user.id); } /** * GET /me/summary - Get dashboard summary */ @Get("summary") async getSummary(@Req() req: RequestWithUser) { return this.usersService.getUserSummary(req.user.id); } /** * PATCH /me - Update customer profile (can update profile fields and/or address) * All fields optional - only send what needs to be updated * Updates stored in WHMCS (single source of truth) * * Examples: * - Update name only: { firstname: "John", lastname: "Doe" } * - Update address only: { address1: "123 Main St", city: "Tokyo" } * - Update both: { firstname: "John", address1: "123 Main St" } */ @Patch() @UsePipes(new ZodValidationPipe(updateCustomerProfileRequestSchema)) async updateProfile(@Req() req: RequestWithUser, @Body() updateData: UpdateCustomerProfileRequest) { return this.usersService.updateProfile(req.user.id, updateData); } }