2025-08-22 17:02:49 +09:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Patch,
|
|
|
|
|
Body,
|
|
|
|
|
UseGuards,
|
|
|
|
|
Req,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
ClassSerializerInterceptor,
|
|
|
|
|
} from "@nestjs/common";
|
2025-08-21 15:24:40 +09:00
|
|
|
import { UsersService } from "./users.service";
|
|
|
|
|
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
|
2025-08-22 17:02:49 +09:00
|
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from "@nestjs/swagger";
|
|
|
|
|
import { UpdateUserDto } from "./dto/update-user.dto";
|
|
|
|
|
import { UpdateBillingDto } from "./dto/update-billing.dto";
|
2025-08-23 17:24:37 +09:00
|
|
|
import { 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-20 18:02:50 +09:00
|
|
|
@UseGuards(JwtAuthGuard)
|
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) {
|
|
|
|
|
return this.usersService.findById(req.user.userId);
|
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) {
|
|
|
|
|
return this.usersService.getUserSummary(req.user.userId);
|
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-08-23 17:24:37 +09:00
|
|
|
async updateProfile(@Req() req: RequestWithUser, @Body() updateData: UpdateUserDto) {
|
|
|
|
|
return this.usersService.update(req.user.userId, updateData);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@Patch("billing")
|
|
|
|
|
@ApiOperation({ summary: "Update billing information" })
|
2025-08-22 17:02:49 +09:00
|
|
|
@ApiResponse({ status: 200, description: "Billing information updated successfully" })
|
|
|
|
|
@ApiResponse({ status: 400, description: "Invalid input data" })
|
|
|
|
|
@ApiResponse({ status: 401, description: "Unauthorized" })
|
2025-08-23 18:02:05 +09:00
|
|
|
updateBilling(@Req() _req: RequestWithUser, @Body() _billingData: UpdateBillingDto) {
|
2025-08-20 18:02:50 +09:00
|
|
|
// TODO: Sync to WHMCS custom fields
|
2025-08-21 15:24:40 +09:00
|
|
|
throw new Error("Not implemented");
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
}
|