Assist_Design/apps/bff/src/modules/users/users.controller.ts

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-08-22 17:02:49 +09:00
import {
Controller,
Get,
Patch,
Body,
Req,
UseInterceptors,
ClassSerializerInterceptor,
UsePipes,
2025-08-22 17:02:49 +09:00
} from "@nestjs/common";
2025-08-21 15:24:40 +09:00
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";
2025-08-21 15:24:40 +09:00
@Controller("me")
2025-08-22 17:02:49 +09:00
@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) {
2025-08-27 10:54:05 +09:00
return this.usersService.findById(req.user.id);
}
/**
* GET /me/summary - Get dashboard summary
*/
2025-08-21 15:24:40 +09:00
@Get("summary")
async getSummary(@Req() req: RequestWithUser) {
2025-08-27 10:54:05 +09:00
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);
}
}