add: update password partner
This commit is contained in:
parent
7fdcf03043
commit
36f343a306
|
@ -230,7 +230,20 @@ export class UsersController {
|
||||||
@Body() updateUserDto: UpdateUserDto,
|
@Body() updateUserDto: UpdateUserDto,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
data: await this.usersService.updatePassword(id, updateUserDto, req.user),
|
data: await this.usersService.updatePassword(id, updateUserDto),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('change-password-partner/:id')
|
||||||
|
async updatePasswordPartner(
|
||||||
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
@Request() req,
|
||||||
|
@Body() updateUserDto: UpdateUserDto,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.updatePassword(id, updateUserDto),
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
|
|
|
@ -358,11 +358,7 @@ export class UsersService {
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updatePassword(
|
async updatePassword(id: string, updateUserDto: UpdateUserDto) {
|
||||||
id: string,
|
|
||||||
updateUserDto: UpdateUserDto,
|
|
||||||
currentUser: any,
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
const dataUser = await this.usersRepository.findOneOrFail(id);
|
const dataUser = await this.usersRepository.findOneOrFail(id);
|
||||||
dataUser.password = await hashPassword(
|
dataUser.password = await hashPassword(
|
||||||
|
@ -386,6 +382,34 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updatePasswordPartner(id: string, updateUserDto: UpdateUserDto) {
|
||||||
|
try {
|
||||||
|
const dataUser = await this.usersRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
partner: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dataUser.password = await hashPassword(
|
||||||
|
updateUserDto.password,
|
||||||
|
dataUser.salt,
|
||||||
|
);
|
||||||
|
const result = await this.usersRepository.save(dataUser);
|
||||||
|
return dataUser;
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'User not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setStatus = async (id: string, type: string) => {
|
setStatus = async (id: string, type: string) => {
|
||||||
const userData = new User();
|
const userData = new User();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user