feat: add update partner endpoint
This commit is contained in:
@@ -216,7 +216,7 @@ export class UsersService {
|
||||
}
|
||||
}
|
||||
|
||||
async update(id: string, updateUserDto: UpdateUserDto) {
|
||||
async update(id: string, updateUserDto: UpdateUserDto, currentUser: any) {
|
||||
try {
|
||||
await this.usersRepository.findOneOrFail(id);
|
||||
} catch (e) {
|
||||
@@ -233,9 +233,32 @@ export class UsersService {
|
||||
}
|
||||
}
|
||||
|
||||
// const result = await this.usersRepository.update(id, updateUserDto);
|
||||
const check = await this.usersRepository.findOne({
|
||||
username: updateUserDto.username,
|
||||
id: Not(id),
|
||||
});
|
||||
|
||||
return this.usersRepository.findOneOrFail(id);
|
||||
if (check) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_ACCEPTABLE,
|
||||
error: 'Username Already Exist',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const userData = new User();
|
||||
|
||||
userData.id = id;
|
||||
userData.username = updateUserDto.username;
|
||||
userData.partner = updateUserDto.partner;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
const result = await manager.update(User, { id: id }, userData);
|
||||
});
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
@@ -266,4 +289,27 @@ export class UsersService {
|
||||
relations: ['roles'],
|
||||
});
|
||||
}
|
||||
|
||||
async findOneByPartner(partnerId: string) {
|
||||
try {
|
||||
return this.usersRepository.findOneOrFail({
|
||||
relations: ['roles'],
|
||||
where: {
|
||||
partner: partnerId,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Data not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user