feat(pos): enhance password update process with current password validation

This commit is contained in:
2026-06-11 17:53:08 +03:30
parent 23bfe1ecbe
commit d2bd576277
2 changed files with 32 additions and 5 deletions
@@ -1,8 +1,13 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsString } from 'class-validator'
import { IsString, Length } from 'class-validator'
export class UpdatePosAccountPasswordDto {
@IsString()
@ApiProperty({ required: true })
@IsString()
currentPassword: string
@ApiProperty({ required: true })
@IsString()
@Length(6, 32)
password: string
}
+25 -3
View File
@@ -5,7 +5,7 @@ import { RedisKeyMaker } from '@/common/utils/redisKeyMaker'
import { ConsumerStatus } from '@/generated/prisma/enums'
import { PrismaService } from '@/prisma/prisma.service'
import { RedisService } from '@/redis/redis.service'
import { Injectable } from '@nestjs/common'
import { BadRequestException, Injectable } from '@nestjs/common'
import { ResponseMapper } from 'common/response/response-mapper'
import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto'
@@ -218,7 +218,29 @@ export class PosService {
accountId: string,
data: UpdatePosAccountPasswordDto,
) {
const consumer = await this.prisma.consumerAccount.update({
const currentCustomerAccount = await this.prisma.consumerAccount.findUniqueOrThrow({
where: {
id: accountId,
consumer_id,
},
select: {
account: {
select: {
password: true,
},
},
},
})
const isCurrentPasswordValid = await PasswordUtil.compare(
data.currentPassword,
currentCustomerAccount.account.password,
)
if (!isCurrentPasswordValid) {
throw new BadRequestException('رمز عبور فعلی اشتباه است')
}
const consumerAccount = await this.prisma.consumerAccount.update({
where: {
id: accountId,
consumer_id,
@@ -232,6 +254,6 @@ export class PosService {
},
})
return ResponseMapper.update(consumer)
return ResponseMapper.update(consumerAccount)
}
}