fix: add user deetail in get all user

This commit is contained in:
ilham 2021-12-16 15:33:44 +07:00
parent bd469fe66a
commit e43ec5129d
3 changed files with 40 additions and 17 deletions

View File

@ -10,6 +10,7 @@ import { BaseModel } from '../../config/basemodel.entity';
import { hashPassword } from '../../helper/hash_password';
import { Partner } from './partner.entity';
import { UserDetail } from './user_detail.entity';
import { COA } from '../../transaction/entities/coa.entity';
@Entity()
export class User extends BaseModel {
@ -57,4 +58,8 @@ export class User extends BaseModel {
},
)
partner: Partner;
user_detail: UserDetail;
coa: COA;
}

View File

@ -114,14 +114,10 @@ export class UsersController {
@Get()
async findAll(@Request() req, @Query('page') page: number) {
const [data, count] = await this.usersService.findAll(
page,
req.user.userId,
);
const data = await this.usersService.findAll(page, req.user.userId);
return {
data,
count,
...data,
statusCode: HttpStatus.OK,
message: 'success',
};

View File

@ -24,6 +24,7 @@ import { RoleService } from 'src/configurable/roles.service';
import { InputCoaDto } from 'src/transaction/dto/input-coa.dto';
import * as uuid from 'uuid';
import { UserDetail } from './entities/user_detail.entity';
import { COA } from '../transaction/entities/coa.entity';
@Injectable()
export class UsersService {
@ -112,17 +113,38 @@ export class UsersService {
return userData;
}
findAll(page: number, id: string) {
return this.usersRepository.findAndCount({
skip: page * 10,
take: 10,
order: {
version: 'DESC',
},
where: {
id: Not(Equal(id)),
},
});
async findAll(page: number, id: string) {
const baseQuery = this.usersRepository
.createQueryBuilder('user')
.where('user.id != :id', {
id: id,
})
.leftJoinAndSelect('user.roles', 'roles', `roles.id = user.roles_id`)
.leftJoinAndMapOne(
'user.user_detail',
UserDetail,
'user_detail',
`user_detail.user = user.id`,
)
.select([
'user.id',
'user.username',
'user.isActive',
'roles.name',
'user_detail',
]);
const data = await baseQuery
.skip(page * 10)
.take(10)
.getMany();
const totalData = await baseQuery.getCount();
return {
data,
count: totalData,
};
}
findByRoles(relationId: string, page: number) {