feat(pos): enhance password update process with current password validation
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger'
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
import { IsString } from 'class-validator'
|
import { IsString, Length } from 'class-validator'
|
||||||
|
|
||||||
export class UpdatePosAccountPasswordDto {
|
export class UpdatePosAccountPasswordDto {
|
||||||
@IsString()
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
|
@IsString()
|
||||||
|
currentPassword: string
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsString()
|
||||||
|
@Length(6, 32)
|
||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { RedisKeyMaker } from '@/common/utils/redisKeyMaker'
|
|||||||
import { ConsumerStatus } from '@/generated/prisma/enums'
|
import { ConsumerStatus } from '@/generated/prisma/enums'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { RedisService } from '@/redis/redis.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 { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto'
|
import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto'
|
||||||
|
|
||||||
@@ -218,7 +218,29 @@ export class PosService {
|
|||||||
accountId: string,
|
accountId: string,
|
||||||
data: UpdatePosAccountPasswordDto,
|
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: {
|
where: {
|
||||||
id: accountId,
|
id: accountId,
|
||||||
consumer_id,
|
consumer_id,
|
||||||
@@ -232,6 +254,6 @@ export class PosService {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return ResponseMapper.update(consumer)
|
return ResponseMapper.update(consumerAccount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user