fix: order history

This commit is contained in:
ilham
2021-12-30 06:47:35 +07:00
parent bd6bf448a6
commit 146d0c8f96
30 changed files with 192 additions and 219 deletions

View File

@@ -1,6 +1,5 @@
import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator';
import { IsNotEmpty, IsUUID } from 'class-validator';
import { Partner } from '../entities/partner.entity';
import { Column } from 'typeorm';
export class CreateUserDto {
@IsNotEmpty()

View File

@@ -1,7 +1,5 @@
import { Roles } from 'src/configurable/entities/roles.entity';
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BaseModel } from '../../config/basemodel.entity';
import { hashPassword } from '../../helper/hash_password';
@Entity()
export class Partner extends BaseModel {

View File

@@ -1,7 +1,5 @@
import { Roles } from 'src/configurable/entities/roles.entity';
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BaseModel } from '../../config/basemodel.entity';
import { hashPassword } from '../../helper/hash_password';
import { COA } from '../../transaction/entities/coa.entity';
@Entity()

View File

@@ -1,11 +1,5 @@
import { Roles } from 'src/configurable/entities/roles.entity';
import {
Column,
Entity,
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Column, Entity, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { BaseModel } from '../../config/basemodel.entity';
import { Partner } from './partner.entity';
import { UserDetail } from './user_detail.entity';

View File

@@ -1,10 +1,4 @@
import {
Column,
Entity,
JoinColumn,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { User } from './user.entity';
@Entity()

View File

@@ -1,12 +1,6 @@
import {
forwardRef,
HttpException,
HttpStatus,
Inject,
Injectable,
} from '@nestjs/common';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
import { Connection, Not, Repository } from 'typeorm';
import { CoaService } from '../../transaction/coa.service';
import { CreatePartnerDto } from '../dto/create-partner.dto';
import { Partner } from '../entities/partner.entity';
@@ -15,7 +9,6 @@ import { UsersService } from '../users.service';
import { CreateUserDto } from '../dto/create-user.dto';
import { UpdatePartnerDto } from '../dto/update-partner.dto';
import { UpdateUserDto } from '../dto/update-user.dto';
import { when } from 'joi';
@Injectable()
export class PartnerService {

View File

@@ -114,13 +114,13 @@ export class UsersController {
@Get()
async findAll(
@Request() req,
@Request() req,
@Query('page') page: number,
@Query('superior') superior: string,
@Query('type') type: string,
) {
const data = await this.usersService.findAll(
page,
page,
req.user.userId,
superior == 'null' ? null : superior,
type == 'null' ? null : type,
@@ -149,6 +149,17 @@ export class UsersController {
};
}
@Get('test')
async test(@Request() req) {
const data = await this.usersService.findAllSubordinate(req.user.userId, 3);
return {
data,
statusCode: HttpStatus.OK,
message: 'success',
};
}
@Get('partner')
async findAllPartner(
@Query('page') page: number,

View File

@@ -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) {