2025-08-22 17:02:49 +09:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Patch,
|
|
|
|
|
Body,
|
|
|
|
|
Req,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
ClassSerializerInterceptor,
|
2025-11-06 16:32:29 +09:00
|
|
|
UseGuards,
|
2025-08-22 17:02:49 +09:00
|
|
|
} from "@nestjs/common";
|
2025-12-10 16:08:34 +09:00
|
|
|
import { UsersFacade } from "./application/users.facade.js";
|
2025-12-26 13:04:15 +09:00
|
|
|
import { createZodDto, ZodResponse, ZodSerializerDto } from "nestjs-zod";
|
|
|
|
|
import { updateCustomerProfileRequestSchema } from "@customer-portal/domain/auth";
|
|
|
|
|
import { dashboardSummarySchema } from "@customer-portal/domain/dashboard";
|
|
|
|
|
import { addressSchema, userSchema } from "@customer-portal/domain/customer";
|
feat: Enhance Public VPN Plans view with marketing content and new components
- Added detailed service highlights, how it works steps, and FAQs to the Public VPN Plans view.
- Introduced new components: CtaButton, FeaturedServiceCard, ProcessStep, ServiceCard, ServiceShowcaseCard, TrustBadge, TrustIndicators, HowItWorks, ServiceCTA, and ServiceFAQ for improved layout and functionality.
- Implemented a new design for the landing page with enhanced visuals and user engagement elements.
- Updated the VPN plans section to include a more informative and visually appealing layout.
2026-01-13 18:19:58 +09:00
|
|
|
import { bilingualAddressSchema } from "@customer-portal/domain/address";
|
2025-12-10 16:08:34 +09:00
|
|
|
import type { Address } from "@customer-portal/domain/customer";
|
2025-12-26 13:04:15 +09:00
|
|
|
import type { User } from "@customer-portal/domain/customer";
|
2025-12-10 16:08:34 +09:00
|
|
|
import type { RequestWithUser } from "@bff/modules/auth/auth.types.js";
|
|
|
|
|
import { SalesforceReadThrottleGuard } from "@bff/integrations/salesforce/guards/salesforce-read-throttle.guard.js";
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-12-26 13:04:15 +09:00
|
|
|
class UpdateAddressDto extends createZodDto(addressSchema.partial()) {}
|
feat: Enhance Public VPN Plans view with marketing content and new components
- Added detailed service highlights, how it works steps, and FAQs to the Public VPN Plans view.
- Introduced new components: CtaButton, FeaturedServiceCard, ProcessStep, ServiceCard, ServiceShowcaseCard, TrustBadge, TrustIndicators, HowItWorks, ServiceCTA, and ServiceFAQ for improved layout and functionality.
- Implemented a new design for the landing page with enhanced visuals and user engagement elements.
- Updated the VPN plans section to include a more informative and visually appealing layout.
2026-01-13 18:19:58 +09:00
|
|
|
class UpdateBilingualAddressDto extends createZodDto(bilingualAddressSchema) {}
|
2025-12-26 13:04:15 +09:00
|
|
|
class UpdateCustomerProfileRequestDto extends createZodDto(updateCustomerProfileRequestSchema) {}
|
|
|
|
|
class AddressDto extends createZodDto(addressSchema) {}
|
|
|
|
|
class UserDto extends createZodDto(userSchema) {}
|
|
|
|
|
class DashboardSummaryDto extends createZodDto(dashboardSummarySchema) {}
|
|
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
@Controller("me")
|
2025-08-22 17:02:49 +09:00
|
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
2025-08-20 18:02:50 +09:00
|
|
|
export class UsersController {
|
2025-11-04 13:28:36 +09:00
|
|
|
constructor(private usersFacade: UsersFacade) {}
|
2025-08-20 18:02:50 +09:00
|
|
|
|
2025-10-07 17:38:39 +09:00
|
|
|
/**
|
|
|
|
|
* GET /me - Get complete customer profile (includes address)
|
|
|
|
|
* Profile data fetched from WHMCS (single source of truth)
|
|
|
|
|
*/
|
2025-11-06 16:32:29 +09:00
|
|
|
@UseGuards(SalesforceReadThrottleGuard)
|
2025-08-20 18:02:50 +09:00
|
|
|
@Get()
|
2025-12-26 13:04:15 +09:00
|
|
|
@ZodResponse({ description: "Get user profile", type: UserDto })
|
|
|
|
|
async getProfile(@Req() req: RequestWithUser): Promise<User> {
|
|
|
|
|
// This endpoint represents the authenticated user; treat missing user as an error.
|
|
|
|
|
return this.usersFacade.getProfile(req.user.id);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
2025-10-07 17:38:39 +09:00
|
|
|
/**
|
|
|
|
|
* GET /me/summary - Get dashboard summary
|
|
|
|
|
*/
|
2025-11-06 16:32:29 +09:00
|
|
|
@UseGuards(SalesforceReadThrottleGuard)
|
2025-08-21 15:24:40 +09:00
|
|
|
@Get("summary")
|
2025-12-26 13:04:15 +09:00
|
|
|
@ZodResponse({ description: "Get dashboard summary", type: DashboardSummaryDto })
|
2025-08-23 17:24:37 +09:00
|
|
|
async getSummary(@Req() req: RequestWithUser) {
|
2025-11-04 13:28:36 +09:00
|
|
|
return this.usersFacade.getUserSummary(req.user.id);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
|
2025-10-20 14:54:04 +09:00
|
|
|
/**
|
|
|
|
|
* GET /me/address - Get customer address only
|
|
|
|
|
*/
|
2025-11-06 16:32:29 +09:00
|
|
|
@UseGuards(SalesforceReadThrottleGuard)
|
2025-10-20 14:54:04 +09:00
|
|
|
@Get("address")
|
2025-12-26 13:04:15 +09:00
|
|
|
@ZodSerializerDto(addressSchema.nullable())
|
2025-10-20 14:54:04 +09:00
|
|
|
async getAddress(@Req() req: RequestWithUser): Promise<Address | null> {
|
2025-11-04 13:28:36 +09:00
|
|
|
return this.usersFacade.getAddress(req.user.id);
|
2025-10-20 14:54:04 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PATCH /me/address - Update address fields
|
|
|
|
|
*/
|
|
|
|
|
@Patch("address")
|
2025-12-26 13:04:15 +09:00
|
|
|
@ZodResponse({ description: "Update address", type: AddressDto })
|
2025-10-20 14:54:04 +09:00
|
|
|
async updateAddress(
|
|
|
|
|
@Req() req: RequestWithUser,
|
2025-12-26 13:04:15 +09:00
|
|
|
@Body() address: UpdateAddressDto
|
2025-10-20 14:54:04 +09:00
|
|
|
): Promise<Address> {
|
2025-11-04 13:28:36 +09:00
|
|
|
return this.usersFacade.updateAddress(req.user.id, address);
|
2025-10-20 14:54:04 +09:00
|
|
|
}
|
|
|
|
|
|
feat: Enhance Public VPN Plans view with marketing content and new components
- Added detailed service highlights, how it works steps, and FAQs to the Public VPN Plans view.
- Introduced new components: CtaButton, FeaturedServiceCard, ProcessStep, ServiceCard, ServiceShowcaseCard, TrustBadge, TrustIndicators, HowItWorks, ServiceCTA, and ServiceFAQ for improved layout and functionality.
- Implemented a new design for the landing page with enhanced visuals and user engagement elements.
- Updated the VPN plans section to include a more informative and visually appealing layout.
2026-01-13 18:19:58 +09:00
|
|
|
/**
|
|
|
|
|
* PATCH /me/address/bilingual - Update address with Japanese + English fields
|
|
|
|
|
*
|
|
|
|
|
* Dual-write: English to WHMCS (source of truth), Japanese to Salesforce
|
|
|
|
|
*
|
|
|
|
|
* Use this endpoint when you have both Japanese and English address data
|
|
|
|
|
* (e.g., from Japan Post ZIP code lookup).
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* {
|
|
|
|
|
* "postcode": "1000001",
|
|
|
|
|
* "prefecture": "Tokyo",
|
|
|
|
|
* "prefectureJa": "東京都",
|
|
|
|
|
* "city": "Chiyoda-ku",
|
|
|
|
|
* "cityJa": "千代田区",
|
|
|
|
|
* "town": "Chiyoda",
|
|
|
|
|
* "townJa": "千代田",
|
|
|
|
|
* "buildingName": "Example Building",
|
|
|
|
|
* "roomNumber": "101",
|
|
|
|
|
* "residenceType": "apartment"
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
@Patch("address/bilingual")
|
|
|
|
|
@ZodResponse({ description: "Update bilingual address", type: AddressDto })
|
|
|
|
|
async updateBilingualAddress(
|
|
|
|
|
@Req() req: RequestWithUser,
|
|
|
|
|
@Body() address: UpdateBilingualAddressDto
|
|
|
|
|
): Promise<Address> {
|
|
|
|
|
return this.usersFacade.updateBilingualAddress(req.user.id, address);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 17:38:39 +09:00
|
|
|
/**
|
|
|
|
|
* 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)
|
2025-10-22 10:58:16 +09:00
|
|
|
*
|
2025-10-07 17:38:39 +09:00
|
|
|
* 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" }
|
|
|
|
|
*/
|
2025-08-20 18:02:50 +09:00
|
|
|
@Patch()
|
2025-12-26 13:04:15 +09:00
|
|
|
@ZodResponse({ description: "Update profile", type: UserDto })
|
2025-10-22 10:58:16 +09:00
|
|
|
async updateProfile(
|
|
|
|
|
@Req() req: RequestWithUser,
|
2025-12-26 13:04:15 +09:00
|
|
|
@Body() updateData: UpdateCustomerProfileRequestDto
|
2025-10-22 10:58:16 +09:00
|
|
|
) {
|
2025-11-04 13:28:36 +09:00
|
|
|
return this.usersFacade.updateProfile(req.user.id, updateData);
|
2025-08-20 18:02:50 +09:00
|
|
|
}
|
|
|
|
|
}
|