Merge branch 'development' of gitlab.com:empatnusabangsa/ppob/ppob-backend into development

# Conflicts:
#	package.json
This commit is contained in:
ilham
2021-12-14 21:52:36 +07:00
9 changed files with 282 additions and 18 deletions

View File

@@ -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,11 +233,50 @@ 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;
}
setStatus = async (id: string, type: string) => {
const userData = new User();
if (type === 'active') {
userData.isActive = true;
} else {
userData.isActive = false;
}
await this.connection.transaction(async (manager) => {
await manager.update(User, { id: id }, userData);
});
return userData;
};
async remove(id: string) {
try {
await this.usersRepository.findOneOrFail(id);
@@ -266,4 +305,27 @@ export class UsersService {
relations: ['roles', 'partner'],
});
}
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;
}
}
}
}