2025-08-22 17:02:49 +09:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Patch,
|
|
|
|
|
Body,
|
|
|
|
|
Req,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
ClassSerializerInterceptor,
|
2025-09-24 18:00:49 +09:00
|
|
|
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";
|
2025-08-22 17:02:49 +09:00
|
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from "@nestjs/swagger";
|
2025-09-24 18:00:49 +09:00
|
|
|
import { ZodValidationPipe } from "@bff/core/validation";
|
2025-09-19 16:34:10 +09:00
|
|
|
import {
|
|
|
|
|
updateProfileRequestSchema,
|
|
|
|
|
updateAddressRequestSchema,
|
|
|
|
|
type UpdateProfileRequest,
|
|
|
|
|
type UpdateAddressRequest
|
|
|
|
|
} from "@customer-portal/domain";
|
2025-09-17 18:43:43 +09:00
|
|
|
import type { RequestWithUser } from "@bff/modules/auth/auth.types";
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@ApiTags("users")
|
|
|
|
|
@Controller("me")
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2025-08-20 18:02:50 +09:00
|
|
|
export class UsersController {
|
|
|
|
|
constructor(private usersService: UsersService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
2025-08-21 15:24:40 +09:00
|
|
|
@ApiOperation({ summary: "Get current user profile" })
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiResponse({ status: 200, description: "User profile retrieved successfully" })
|
|
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-08-23 17:24:37 +09:00
|
|
|
async getProfile(@Req() req: RequestWithUser) {
|
2025-08-27 10:54:05 +09:00
|
|
|
return this.usersService.findById(req.user.id);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@Get("summary")
|
|
|
|
|
@ApiOperation({ summary: "Get user dashboard summary" })
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiResponse({ status: 200, description: "User summary retrieved successfully" })
|
|
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-08-23 17:24:37 +09:00
|
|
|
async getSummary(@Req() req: RequestWithUser) {
|
2025-08-27 10:54:05 +09:00
|
|
|
return this.usersService.getUserSummary(req.user.id);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Patch()
|
2025-09-24 18:00:49 +09:00
|
|
|
@UsePipes(new ZodValidationPipe(updateProfileRequestSchema))
|
2025-08-21 15:24:40 +09:00
|
|
|
@ApiOperation({ summary: "Update user profile" })
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiResponse({ status: 200, description: "Profile updated successfully" })
|
|
|
|
|
@ApiResponse({ status: 400, description: "Invalid input data" })
|
|
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-09-24 18:00:49 +09:00
|
|
|
async updateProfile(@Req() req: RequestWithUser, @Body() updateData: UpdateProfileRequest) {
|
2025-08-27 10:54:05 +09:00
|
|
|
return this.usersService.update(req.user.id, updateData);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 18:43:43 +09:00
|
|
|
@Get("address")
|
|
|
|
|
@ApiOperation({ summary: "Get mailing address" })
|
|
|
|
|
@ApiResponse({ status: 200, description: "Address retrieved successfully" })
|
2025-08-28 16:57:57 +09:00
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-09-17 18:43:43 +09:00
|
|
|
async getAddress(@Req() req: RequestWithUser) {
|
|
|
|
|
return this.usersService.getAddress(req.user.id);
|
2025-08-28 16:57:57 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-02 13:52:13 +09:00
|
|
|
// Removed PATCH /me/billing in favor of PATCH /me/address to keep address updates explicit.
|
|
|
|
|
|
|
|
|
|
@Patch("address")
|
2025-09-24 18:00:49 +09:00
|
|
|
@UsePipes(new ZodValidationPipe(updateAddressRequestSchema))
|
2025-09-02 13:52:13 +09:00
|
|
|
@ApiOperation({ summary: "Update mailing address" })
|
|
|
|
|
@ApiResponse({ status: 200, description: "Address updated successfully" })
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiResponse({ status: 400, description: "Invalid input data" })
|
|
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-09-24 18:00:49 +09:00
|
|
|
async updateAddress(@Req() req: RequestWithUser, @Body() address: UpdateAddressRequest) {
|
2025-09-02 13:52:13 +09:00
|
|
|
await this.usersService.updateAddress(req.user.id, address);
|
2025-09-17 18:43:43 +09:00
|
|
|
// Return fresh address snapshot
|
|
|
|
|
return this.usersService.getAddress(req.user.id);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
}
|