diff --git a/src/modules/pos/dto/update-password-request.dto.ts b/src/modules/pos/dto/update-password-request.dto.ts new file mode 100644 index 0000000..babc15e --- /dev/null +++ b/src/modules/pos/dto/update-password-request.dto.ts @@ -0,0 +1,8 @@ +import { ApiProperty } from '@nestjs/swagger' +import { IsString } from 'class-validator' + +export class UpdatePosAccountPasswordDto { + @IsString() + @ApiProperty({ required: true }) + password: string +} diff --git a/src/modules/pos/pos.controller.ts b/src/modules/pos/pos.controller.ts index 0b34d37..d7a21d3 100644 --- a/src/modules/pos/pos.controller.ts +++ b/src/modules/pos/pos.controller.ts @@ -1,12 +1,13 @@ import { PosInfo } from '@/common/decorators/posInfo.decorator' import { TokenAccount } from '@/common/decorators/tokenInfo.decorator' -import { Controller, Get, Res } from '@nestjs/common' +import { Body, Controller, Get, Put, Res } from '@nestjs/common' import { ApiTags } from '@nestjs/swagger' import type { PosServiceGetAccessibleResponseDto, PosServiceGetInfoResponseDto, PosServiceGetMeResponseDto, } from './dto/pos-response.dto' +import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto' import { PosService } from './pos.service' @ApiTags('Pos') @@ -48,4 +49,13 @@ export class PosController { ): Promise { return await this.service.getMe(account_id, pos_id) } + + @Put('update-password') + async updatePassword( + @TokenAccount('userId') consumerId: string, + @TokenAccount('account_id') accountId: string, + @Body() data: UpdatePosAccountPasswordDto, + ) { + return this.service.updatePassword(consumerId, accountId, data) + } } diff --git a/src/modules/pos/pos.service.ts b/src/modules/pos/pos.service.ts index d5311dd..aaf4db6 100644 --- a/src/modules/pos/pos.service.ts +++ b/src/modules/pos/pos.service.ts @@ -1,4 +1,5 @@ import { QUERY_CONSTANTS } from '@/common/queryConstants' +import { PasswordUtil } from '@/common/utils' import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util' import { RedisKeyMaker } from '@/common/utils/redisKeyMaker' import { ConsumerStatus } from '@/generated/prisma/enums' @@ -6,6 +7,7 @@ import { PrismaService } from '@/prisma/prisma.service' import { RedisService } from '@/redis/redis.service' import { Injectable } from '@nestjs/common' import { ResponseMapper } from 'common/response/response-mapper' +import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto' @Injectable() export class PosService { @@ -210,4 +212,26 @@ export class PosService { this.meCacheTtlSeconds, ) } + + async updatePassword( + consumer_id: string, + accountId: string, + data: UpdatePosAccountPasswordDto, + ) { + const consumer = await this.prisma.consumerAccount.update({ + where: { + id: accountId, + consumer_id, + }, + data: { + account: { + update: { + password: await PasswordUtil.hash(data.password), + }, + }, + }, + }) + + return ResponseMapper.update(consumer) + } }