Merge branch 'development' into 'devops-staging'
add: update user See merge request empatnusabangsa/ppob/ppob-backend!60
This commit is contained in:
commit
3e7d76fcee
|
@ -19,6 +19,8 @@ export class UsersService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
private usersRepository: Repository<User>,
|
private usersRepository: Repository<User>,
|
||||||
|
@InjectRepository(UserDetail)
|
||||||
|
private userDetailRepository: Repository<UserDetail>,
|
||||||
@Inject(
|
@Inject(
|
||||||
forwardRef(() => {
|
forwardRef(() => {
|
||||||
return CoaService;
|
return CoaService;
|
||||||
|
@ -289,8 +291,16 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, updateUserDto: UpdateUserDto, currentUser: any) {
|
async update(id: string, updateUserDto: UpdateUserDto, currentUser: any) {
|
||||||
|
let userData;
|
||||||
|
let userDetailData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.usersRepository.findOneOrFail(id);
|
userData = await this.usersRepository.findOneOrFail(id);
|
||||||
|
userDetailData = await this.userDetailRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
user: userData,
|
||||||
|
},
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
@ -320,14 +330,15 @@ export class UsersService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userData = new User();
|
|
||||||
|
|
||||||
userData.id = id;
|
|
||||||
userData.username = updateUserDto.username;
|
userData.username = updateUserDto.username;
|
||||||
userData.partner = updateUserDto.partner;
|
userData.partner = updateUserDto.partner;
|
||||||
|
userDetailData.name = updateUserDto.name;
|
||||||
|
userDetailData.phone_number = updateUserDto.phone_number;
|
||||||
|
|
||||||
|
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
const result = await manager.update(User, { id: id }, userData);
|
await manager.save(userData);
|
||||||
|
await manager.save(userDetailData);
|
||||||
});
|
});
|
||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user