mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-11 01:21:44 +00:00
50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
import { Body, Controller, Get, Headers, Patch, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { IJwtPayload } from '~/auth/interfaces';
|
|
import { DEVICE_ID_HEADER } from '~/common/constants';
|
|
import { AuthenticatedUser } from '~/common/decorators';
|
|
import { AccessTokenGuard } from '~/common/guards';
|
|
import { ApiDataResponse } from '~/core/decorators';
|
|
import { ResponseFactory } from '~/core/utils';
|
|
import { UpdateCustomerRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
|
|
import { CustomerResponseDto, NotificationSettingsResponseDto } from '../dtos/response';
|
|
import { CustomerService } from '../services';
|
|
|
|
@Controller('customers')
|
|
@ApiTags('Customers')
|
|
@ApiBearerAuth()
|
|
export class CustomerController {
|
|
constructor(private readonly customerService: CustomerService) {}
|
|
|
|
@Get('/profile')
|
|
@UseGuards(AccessTokenGuard)
|
|
@ApiDataResponse(CustomerResponseDto)
|
|
async getCustomerProfile(@AuthenticatedUser() { sub }: IJwtPayload) {
|
|
const customer = await this.customerService.findCustomerById(sub);
|
|
|
|
return ResponseFactory.data(new CustomerResponseDto(customer));
|
|
}
|
|
|
|
@Patch('')
|
|
@UseGuards(AccessTokenGuard)
|
|
@ApiDataResponse(CustomerResponseDto)
|
|
async updateCustomer(@AuthenticatedUser() { sub }: IJwtPayload, @Body() body: UpdateCustomerRequestDto) {
|
|
const customer = await this.customerService.updateCustomer(sub, body);
|
|
|
|
return ResponseFactory.data(new CustomerResponseDto(customer));
|
|
}
|
|
|
|
@Patch('settings/notifications')
|
|
@UseGuards(AccessTokenGuard)
|
|
@ApiDataResponse(NotificationSettingsResponseDto)
|
|
async updateNotificationSettings(
|
|
@AuthenticatedUser() { sub }: IJwtPayload,
|
|
@Body() body: UpdateNotificationsSettingsRequestDto,
|
|
@Headers(DEVICE_ID_HEADER) deviceId: string,
|
|
) {
|
|
const notificationSettings = await this.customerService.updateNotificationSettings(sub, body, deviceId);
|
|
|
|
return ResponseFactory.data(new NotificationSettingsResponseDto(notificationSettings));
|
|
}
|
|
}
|