fix: add user deetail in get all user
This commit is contained in:
parent
bd469fe66a
commit
e43ec5129d
|
@ -10,6 +10,7 @@ import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { hashPassword } from '../../helper/hash_password';
|
import { hashPassword } from '../../helper/hash_password';
|
||||||
import { Partner } from './partner.entity';
|
import { Partner } from './partner.entity';
|
||||||
import { UserDetail } from './user_detail.entity';
|
import { UserDetail } from './user_detail.entity';
|
||||||
|
import { COA } from '../../transaction/entities/coa.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User extends BaseModel {
|
export class User extends BaseModel {
|
||||||
|
@ -57,4 +58,8 @@ export class User extends BaseModel {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
partner: Partner;
|
partner: Partner;
|
||||||
|
|
||||||
|
user_detail: UserDetail;
|
||||||
|
|
||||||
|
coa: COA;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,14 +114,10 @@ export class UsersController {
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(@Request() req, @Query('page') page: number) {
|
async findAll(@Request() req, @Query('page') page: number) {
|
||||||
const [data, count] = await this.usersService.findAll(
|
const data = await this.usersService.findAll(page, req.user.userId);
|
||||||
page,
|
|
||||||
req.user.userId,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
...data,
|
||||||
count,
|
|
||||||
statusCode: HttpStatus.OK,
|
statusCode: HttpStatus.OK,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { RoleService } from 'src/configurable/roles.service';
|
||||||
import { InputCoaDto } from 'src/transaction/dto/input-coa.dto';
|
import { InputCoaDto } from 'src/transaction/dto/input-coa.dto';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { UserDetail } from './entities/user_detail.entity';
|
import { UserDetail } from './entities/user_detail.entity';
|
||||||
|
import { COA } from '../transaction/entities/coa.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
@ -112,17 +113,38 @@ export class UsersService {
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll(page: number, id: string) {
|
async findAll(page: number, id: string) {
|
||||||
return this.usersRepository.findAndCount({
|
const baseQuery = this.usersRepository
|
||||||
skip: page * 10,
|
.createQueryBuilder('user')
|
||||||
take: 10,
|
.where('user.id != :id', {
|
||||||
order: {
|
id: id,
|
||||||
version: 'DESC',
|
})
|
||||||
},
|
.leftJoinAndSelect('user.roles', 'roles', `roles.id = user.roles_id`)
|
||||||
where: {
|
.leftJoinAndMapOne(
|
||||||
id: Not(Equal(id)),
|
'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) {
|
findByRoles(relationId: string, page: number) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user