diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index 4655b14..2bd222c 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -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; } diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 6151726..4b377ee 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -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', }; diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 21132cc..a4c1aa2 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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) {