fix: order history
This commit is contained in:
parent
bd6bf448a6
commit
146d0c8f96
|
@ -1,11 +1,10 @@
|
|||
import {
|
||||
CreateDateColumn,
|
||||
DeleteDateColumn,
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Entity, Column, OneToOne, JoinColumn } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { Roles } from './roles.entity';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Entity, Column } from 'typeorm';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
|
||||
@Entity()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class CreateCategoriesProductDto {
|
||||
@IsNotEmpty()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class UploadProductDto {
|
||||
@IsNotEmpty()
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { ProductSubCategories } from './product-sub-category.entity';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Product } from './product.entity';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { productType } from '../../helper/enum-list';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { Partner } from '../../users/entities/partner.entity';
|
||||
|
||||
@Entity()
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { ProductCategories } from './product-category.entity';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { Product } from './product.entity';
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn,
|
||||
OneToMany,
|
||||
ManyToOne,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { ProductSubCategories } from './product-sub-category.entity';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { Supplier } from '../../users/entities/supplier.entity';
|
||||
|
|
|
@ -13,7 +13,6 @@ import { SupplierService } from '../users/supplier/supplier.service';
|
|||
import { parsingFile } from '../helper/csv-parser';
|
||||
import { PartnerService } from '../users/partner/partner.service';
|
||||
import { mapSeries } from 'bluebird';
|
||||
import { isNull } from 'util';
|
||||
|
||||
export class ProductService {
|
||||
constructor(
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
import {
|
||||
forwardRef,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Injectable,
|
||||
} from '@nestjs/common';
|
||||
import { forwardRef, HttpException, HttpStatus, Inject } from '@nestjs/common';
|
||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { balanceType, coaType } from '../helper/enum-list';
|
||||
import { coaType } from '../helper/enum-list';
|
||||
import { InputCoaDto } from './dto/input-coa.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class AddSaldoSupplier {
|
||||
@IsNotEmpty()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { balanceType, coaType, statusTransaction, typeTransaction } from 'src/helper/enum-list';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
import { statusTransaction, typeTransaction } from 'src/helper/enum-list';
|
||||
import { EntityManager } from 'typeorm';
|
||||
import { Transactions } from '../entities/transactions.entity';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class DistributeTransactionDto {
|
||||
@IsNotEmpty()
|
||||
|
|
7
src/transaction/dto/order-transaction-partner.dto.ts
Normal file
7
src/transaction/dto/order-transaction-partner.dto.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { IsNotEmpty } from 'class-validator';
|
||||
import { OrderTransactionDto } from './order-transaction.dto';
|
||||
|
||||
export class OrderTransactionPartnerDto extends OrderTransactionDto {
|
||||
@IsNotEmpty()
|
||||
trx_id: string;
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class OrderTransactionDto {
|
||||
@IsNotEmpty()
|
||||
productCode: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
phoneNumber: string;
|
||||
destination: string;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Entity, Column } from 'typeorm';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { coaType, balanceType } from '../../helper/enum-list';
|
||||
import { balanceType, coaType } from '../../helper/enum-list';
|
||||
|
||||
@Entity()
|
||||
export class COA extends BaseModel {
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { COA } from './coa.entity';
|
||||
import { Transactions } from './transactions.entity';
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
VersionColumn,
|
||||
CreateDateColumn,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
||||
import { Partner } from '../../users/entities/partner.entity';
|
||||
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { UserDetail } from '../../users/entities/user_detail.entity';
|
||||
import { TransactionJournal } from './transaction-journal.entity';
|
||||
|
||||
|
@ -48,6 +35,11 @@ export class Transactions extends BaseModel {
|
|||
})
|
||||
image_prove: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
destination: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
|
@ -56,7 +48,7 @@ export class Transactions extends BaseModel {
|
|||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
phone_number: string;
|
||||
partner_trx_id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
|
|
|
@ -1,17 +1,5 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
HttpStatus,
|
||||
Logger,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { Public } from '../auth/public.decorator';
|
||||
|
||||
|
|
|
@ -1,15 +1,4 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpStatus,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
Request,
|
||||
} from '@nestjs/common';
|
||||
import { Body, Controller, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request } from '@nestjs/common';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
||||
|
@ -117,15 +106,15 @@ export class TransactionController {
|
|||
async getHistoryTransactionUser(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('startDate') startDate: string,
|
||||
@Query('endDate') endDate: string,
|
||||
@Query('start') startDate: string,
|
||||
@Query('end') endDate: string,
|
||||
@Request() req,
|
||||
) {
|
||||
const data = await this.transactionService.transactionHistoryByUser(
|
||||
page,
|
||||
req.user.userId,
|
||||
startDate,
|
||||
endDate,
|
||||
startDate == 'null' ? null : startDate,
|
||||
endDate == 'null' ? null : endDate,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,12 +10,7 @@ import { CoaService } from './coa.service';
|
|||
import * as uuid from 'uuid';
|
||||
import { uniq } from 'lodash';
|
||||
import { Decimal } from 'decimal.js';
|
||||
import {
|
||||
balanceType,
|
||||
coaType,
|
||||
statusTransaction,
|
||||
typeTransaction,
|
||||
} from '../helper/enum-list';
|
||||
import { balanceType, coaType, statusTransaction, typeTransaction } from '../helper/enum-list';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
|
@ -28,12 +23,6 @@ import { UserDetail } from '../users/entities/user_detail.entity';
|
|||
import { doTransaction } from '../helper/irs-api';
|
||||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
||||
|
||||
interface JournalEntry {
|
||||
coa_id: string;
|
||||
debit?: string;
|
||||
credit?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
private readonly logger = new Logger(TransactionService.name);
|
||||
|
@ -387,7 +376,7 @@ export class TransactionService {
|
|||
transactionData.status = statusTransaction.SUCCESS;
|
||||
transactionData.type = typeTransaction.ORDER;
|
||||
transactionData.product_price = product_price;
|
||||
transactionData.phone_number = orderTransactionDto.phoneNumber;
|
||||
transactionData.destination = orderTransactionDto.destination;
|
||||
await manager.insert(Transactions, transactionData);
|
||||
|
||||
await this.accountingTransaction({
|
||||
|
@ -409,6 +398,7 @@ export class TransactionService {
|
|||
debit: product_price.mark_up_price + product_price.price,
|
||||
},
|
||||
{
|
||||
// eslint-disable-next-line camelcase
|
||||
coa_id: coaSales.id,
|
||||
credit: product_price.mark_up_price + product_price.price,
|
||||
},
|
||||
|
@ -444,12 +434,14 @@ export class TransactionService {
|
|||
//TODO HIT API SUPPLIER
|
||||
const trxId = Array(6)
|
||||
.fill(null)
|
||||
.map(() => Math.round(Math.random() * 16).toString(16))
|
||||
.map(() => {
|
||||
return Math.round(Math.random() * 16).toString(16);
|
||||
})
|
||||
.join('');
|
||||
|
||||
const hitSupplier = await doTransaction(
|
||||
orderTransactionDto.productCode,
|
||||
orderTransactionDto.phoneNumber,
|
||||
orderTransactionDto.destination,
|
||||
trxId,
|
||||
);
|
||||
|
||||
|
@ -465,7 +457,7 @@ export class TransactionService {
|
|||
transactionData.user = userData.id;
|
||||
transactionData.type = typeTransaction.ORDER;
|
||||
transactionData.product_price = product_price;
|
||||
transactionData.phone_number = orderTransactionDto.phoneNumber;
|
||||
transactionData.destination = orderTransactionDto.destination;
|
||||
transactionData.supplier_trx_id = trxId;
|
||||
|
||||
if (!hitSupplier.success) {
|
||||
|
@ -487,6 +479,7 @@ export class TransactionService {
|
|||
product_price.endDate = new Date();
|
||||
|
||||
let newProductPrice = new ProductHistoryPrice();
|
||||
|
||||
newProductPrice = product_price;
|
||||
newProductPrice.id = uuid.v4();
|
||||
newProductPrice.price = hitSupplier.harga;
|
||||
|
@ -653,6 +646,7 @@ export class TransactionService {
|
|||
supplier_trx_id: supplier_trx_id,
|
||||
},
|
||||
});
|
||||
|
||||
dataTransaction.status = statusTransaction.FAILED;
|
||||
dataTransaction.callback_json = callback;
|
||||
|
||||
|
@ -666,6 +660,7 @@ export class TransactionService {
|
|||
},
|
||||
relations: ['product_price'],
|
||||
});
|
||||
|
||||
dataTransaction.status = statusTransaction.FAILED;
|
||||
dataTransaction.callback_json = callback;
|
||||
|
||||
|
@ -762,6 +757,51 @@ export class TransactionService {
|
|||
}
|
||||
}
|
||||
|
||||
async withdrawBenefit(user) {
|
||||
const userData = await this.userService.findExist(user);
|
||||
|
||||
const coaProfit = await this.coaService.findByUser(user, coaType.PROFIT);
|
||||
|
||||
const coaBank = await this.coaService.findByName(
|
||||
`${coaType[coaType.BANK]}-SYSTEM`,
|
||||
);
|
||||
|
||||
try {
|
||||
const transactionData = new Transactions();
|
||||
|
||||
transactionData.id = uuid.v4();
|
||||
transactionData.amount = coaProfit.amount;
|
||||
transactionData.user = userData.id;
|
||||
transactionData.status = statusTransaction.APPROVED;
|
||||
transactionData.type = typeTransaction.WITHDRAW;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.insert(Transactions, transactionData);
|
||||
|
||||
await this.accountingTransaction({
|
||||
createTransaction: false,
|
||||
transactionalEntityManager: manager,
|
||||
transaction: transactionData,
|
||||
amount: transactionData.amount,
|
||||
journals: [
|
||||
{
|
||||
coa_id: coaBank.id,
|
||||
credit: transactionData.amount,
|
||||
},
|
||||
{
|
||||
coa_id: coaProfit.id,
|
||||
debit: transactionData.amount,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return transactionData;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async transactionHistoryByUser(
|
||||
page: number,
|
||||
user: string,
|
||||
|
@ -770,26 +810,48 @@ export class TransactionService {
|
|||
pageSize?: number,
|
||||
) {
|
||||
const userData = await this.userService.findExist(user);
|
||||
let filterTransactionDate;
|
||||
|
||||
let userBySupperior = [];
|
||||
if(userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' && userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'){
|
||||
const getListUser = await this.userService.findBySuperrior(userData.id,100)
|
||||
userBySupperior = getListUser.data.map(x => x.id)
|
||||
|
||||
if (
|
||||
userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' &&
|
||||
userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'
|
||||
) {
|
||||
let roleNumber;
|
||||
|
||||
if (userData.roles.id == '3196cdf4-ae5f-4677-9bcd-98be35c72321') {
|
||||
roleNumber = 3;
|
||||
} else if (userData.roles.id == '3196cdf4-ae5f-4677-9bcd-98be35c72322') {
|
||||
roleNumber = 2;
|
||||
} else if (userData.roles.id == 'e4dfb6a3-2348-464a-8fb8-5cbc089d4209') {
|
||||
roleNumber = 1;
|
||||
}
|
||||
|
||||
userBySupperior = await this.userService.findAllSubordinate(
|
||||
userData.id,
|
||||
roleNumber,
|
||||
);
|
||||
} else {
|
||||
userBySupperior.push(user)
|
||||
userBySupperior.push(user);
|
||||
}
|
||||
|
||||
const baseQuery = this.transactionRepository
|
||||
.createQueryBuilder('transaction')
|
||||
.select('transaction.id', 'id')
|
||||
.addSelect('transaction.created_at', 'created_at')
|
||||
.where('transaction.user = IN (:...id) and transaction.type = 1', {
|
||||
.where('transaction.user IN (:...id) and transaction.type = 1', {
|
||||
id: userBySupperior,
|
||||
})
|
||||
.leftJoinAndMapOne(
|
||||
'transaction.userData',
|
||||
UserDetail,
|
||||
'userData',
|
||||
'userData.user = transaction.user',
|
||||
)
|
||||
.leftJoin('transaction.product_price', 'product_price')
|
||||
.leftJoin('product_price.product', 'product')
|
||||
.addSelect('transaction.amount', 'mark_up_price')
|
||||
.addSelect('transaction.amount', 'price')
|
||||
.addSelect('userData.name', 'buyer')
|
||||
.addSelect('product.name', 'name')
|
||||
.addSelect('product.id', 'product_id');
|
||||
|
||||
|
@ -921,6 +983,7 @@ export class TransactionService {
|
|||
data,
|
||||
count: totalData,
|
||||
};
|
||||
|
||||
return this.transactionRepository.findAndCount({
|
||||
skip: page * (pageSize || 10),
|
||||
take: pageSize || 10,
|
||||
|
@ -934,51 +997,6 @@ export class TransactionService {
|
|||
});
|
||||
}
|
||||
|
||||
async withdrawBenefit(user) {
|
||||
const userData = await this.userService.findExist(user);
|
||||
|
||||
const coaProfit = await this.coaService.findByUser(user, coaType.PROFIT);
|
||||
|
||||
const coaBank = await this.coaService.findByName(
|
||||
`${coaType[coaType.BANK]}-SYSTEM`,
|
||||
);
|
||||
|
||||
try {
|
||||
const transactionData = new Transactions();
|
||||
|
||||
transactionData.id = uuid.v4();
|
||||
transactionData.amount = coaProfit.amount;
|
||||
transactionData.user = userData.id;
|
||||
transactionData.status = statusTransaction.APPROVED;
|
||||
transactionData.type = typeTransaction.WITHDRAW;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
await manager.insert(Transactions, transactionData);
|
||||
|
||||
await this.accountingTransaction({
|
||||
createTransaction: false,
|
||||
transactionalEntityManager: manager,
|
||||
transaction: transactionData,
|
||||
amount: transactionData.amount,
|
||||
journals: [
|
||||
{
|
||||
coa_id: coaBank.id,
|
||||
credit: transactionData.amount,
|
||||
},
|
||||
{
|
||||
coa_id: coaProfit.id,
|
||||
debit: transactionData.amount,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return transactionData;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async getTotalSell() {
|
||||
const { total_amount } = await this.transactionRepository
|
||||
.createQueryBuilder('transactions')
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user