feat(pos): add update password functionality with DTO and service method
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
|
import { IsString } from 'class-validator'
|
||||||
|
|
||||||
|
export class UpdatePosAccountPasswordDto {
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
password: string
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import { PosInfo } from '@/common/decorators/posInfo.decorator'
|
import { PosInfo } from '@/common/decorators/posInfo.decorator'
|
||||||
import { TokenAccount } from '@/common/decorators/tokenInfo.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 { ApiTags } from '@nestjs/swagger'
|
||||||
import type {
|
import type {
|
||||||
PosServiceGetAccessibleResponseDto,
|
PosServiceGetAccessibleResponseDto,
|
||||||
PosServiceGetInfoResponseDto,
|
PosServiceGetInfoResponseDto,
|
||||||
PosServiceGetMeResponseDto,
|
PosServiceGetMeResponseDto,
|
||||||
} from './dto/pos-response.dto'
|
} from './dto/pos-response.dto'
|
||||||
|
import { UpdatePosAccountPasswordDto } from './dto/update-password-request.dto'
|
||||||
import { PosService } from './pos.service'
|
import { PosService } from './pos.service'
|
||||||
|
|
||||||
@ApiTags('Pos')
|
@ApiTags('Pos')
|
||||||
@@ -48,4 +49,13 @@ export class PosController {
|
|||||||
): Promise<PosServiceGetMeResponseDto> {
|
): Promise<PosServiceGetMeResponseDto> {
|
||||||
return await this.service.getMe(account_id, pos_id)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||||
|
import { PasswordUtil } from '@/common/utils'
|
||||||
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
|
import consumer_mappersUtil from '@/common/utils/mappers/consumer_mappers.util'
|
||||||
import { RedisKeyMaker } from '@/common/utils/redisKeyMaker'
|
import { RedisKeyMaker } from '@/common/utils/redisKeyMaker'
|
||||||
import { ConsumerStatus } from '@/generated/prisma/enums'
|
import { ConsumerStatus } from '@/generated/prisma/enums'
|
||||||
@@ -6,6 +7,7 @@ import { PrismaService } from '@/prisma/prisma.service'
|
|||||||
import { RedisService } from '@/redis/redis.service'
|
import { RedisService } from '@/redis/redis.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { 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'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PosService {
|
export class PosService {
|
||||||
@@ -210,4 +212,26 @@ export class PosService {
|
|||||||
this.meCacheTtlSeconds,
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user