fix: order history
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
forwardRef,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
||||
@@ -19,6 +13,7 @@ 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';
|
||||
import { mapSeries } from 'bluebird';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -148,10 +143,10 @@ export class UsersService {
|
||||
'coa.amount',
|
||||
]);
|
||||
|
||||
if(superior){
|
||||
baseQuery.where('user.superior = :id_supperior',{
|
||||
id_supperior:superior
|
||||
})
|
||||
if (superior) {
|
||||
baseQuery.where('user.superior = :id_supperior', {
|
||||
id_supperior: superior,
|
||||
});
|
||||
}
|
||||
|
||||
if(type){
|
||||
@@ -176,6 +171,42 @@ export class UsersService {
|
||||
};
|
||||
}
|
||||
|
||||
async findAllSubordinate(id: string, role: number) {
|
||||
let listUser = [];
|
||||
let listToFind = [];
|
||||
|
||||
const baseQuery = await this.usersRepository.find({
|
||||
where: {
|
||||
superior: id,
|
||||
},
|
||||
});
|
||||
const listId = baseQuery.map((x) => x.id);
|
||||
listUser = listUser.concat(listId);
|
||||
listToFind = listId;
|
||||
if (role == 1) {
|
||||
return listUser;
|
||||
} else {
|
||||
for (let it = 2; it <= role; it++) {
|
||||
let newListToFind = [];
|
||||
await mapSeries(listToFind, async (ltf) => {
|
||||
const getListUser = await this.usersRepository.find({
|
||||
where: {
|
||||
superior: ltf,
|
||||
},
|
||||
});
|
||||
if (getListUser.length > 0) {
|
||||
const listId = getListUser.map((x) => x.id);
|
||||
newListToFind = newListToFind.concat(listId);
|
||||
listUser = listUser.concat(listId);
|
||||
}
|
||||
});
|
||||
listToFind = newListToFind;
|
||||
}
|
||||
}
|
||||
|
||||
return listUser;
|
||||
}
|
||||
|
||||
findByRoles(relationId: string, page: number, pageSize?: number) {
|
||||
return this.usersRepository.findAndCount({
|
||||
skip: page * (pageSize || 10),
|
||||
@@ -238,7 +269,7 @@ export class UsersService {
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
relations: ['superior','roles'],
|
||||
relations: ['superior', 'roles'],
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
@@ -280,6 +311,7 @@ export class UsersService {
|
||||
|
||||
async findOne(id: string) {
|
||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
||||
const coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
||||
|
||||
try {
|
||||
const userData = await this.usersRepository
|
||||
@@ -308,6 +340,7 @@ export class UsersService {
|
||||
return {
|
||||
...userData,
|
||||
wallet: coa.amount,
|
||||
profit: coaProfit.amount,
|
||||
};
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
|
||||
Reference in New Issue
Block a user