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

70 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-08-22 17:02:49 +09:00
import {
Controller,
Get,
Patch,
Body,
Req,
UseInterceptors,
ClassSerializerInterceptor,
} 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";
import * as UserDto from "./dto/update-user.dto";
// import * as BillingDto from "./dto/update-billing.dto"; // No longer exposed as an endpoint
import { UpdateAddressDto } from "./dto/update-address.dto";
import type { RequestWithUser } from "../auth/auth.types";
2025-08-21 15:24:40 +09:00
@ApiTags("users")
@Controller("me")
2025-08-22 17:02:49 +09:00
@ApiBearerAuth()
@UseInterceptors(ClassSerializerInterceptor)
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" })
async getProfile(@Req() req: RequestWithUser) {
2025-08-27 10:54:05 +09:00
return this.usersService.findById(req.user.id);
}
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" })
async getSummary(@Req() req: RequestWithUser) {
2025-08-27 10:54:05 +09:00
return this.usersService.getUserSummary(req.user.id);
}
@Patch()
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" })
async updateProfile(@Req() req: RequestWithUser, @Body() updateData: UserDto.UpdateUserDto) {
2025-08-27 10:54:05 +09:00
return this.usersService.update(req.user.id, updateData);
}
2025-08-28 16:57:57 +09:00
@Get("billing")
@ApiOperation({ summary: "Get billing information" })
@ApiResponse({ status: 200, description: "Billing information retrieved successfully" })
@ApiResponse({ status: 401, description: "Unauthorized" })
async getBilling(@Req() req: RequestWithUser) {
return this.usersService.getBillingInfo(req.user.id);
}
// Removed PATCH /me/billing in favor of PATCH /me/address to keep address updates explicit.
@Patch("address")
@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" })
async updateAddress(@Req() req: RequestWithUser, @Body() address: UpdateAddressDto) {
await this.usersService.updateAddress(req.user.id, address);
// Return fresh billing info snapshot (source of truth from WHMCS)
return this.usersService.getBillingInfo(req.user.id);
}
}