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";
|
2025-09-01 15:11:42 +09:00
|
|
|
import * as UserDto from "./dto/update-user.dto";
|
2025-09-02 13:52:13 +09:00
|
|
|
// import * as BillingDto from "./dto/update-billing.dto"; // No longer exposed as an endpoint
|
|
|
|
|
import { UpdateAddressDto } from "./dto/update-address.dto";
|
2025-09-01 15:11:42 +09:00
|
|
|
import type { RequestWithUser } from "../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-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-01 15:11:42 +09:00
|
|
|
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-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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")
|
|
|
|
|
@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-02 13:52:13 +09:00
|
|
|
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);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
}
|