Merge branch 'development' into 'devops-staging'
fix: order history See merge request empatnusabangsa/ppob/ppob-backend!76
This commit is contained in:
commit
034df71492
|
@ -1,11 +1,10 @@
|
||||||
import {
|
import {
|
||||||
|
CreateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
Column,
|
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
DeleteDateColumn,
|
|
||||||
VersionColumn,
|
VersionColumn,
|
||||||
CreateDateColumn,
|
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
@Entity()
|
@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 { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { Roles } from './roles.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';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
export class CreateCategoriesProductDto {
|
export class CreateCategoriesProductDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
export class UploadProductDto {
|
export class UploadProductDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
import {
|
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
Entity,
|
|
||||||
Column,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
UpdateDateColumn,
|
|
||||||
DeleteDateColumn,
|
|
||||||
VersionColumn,
|
|
||||||
CreateDateColumn,
|
|
||||||
OneToMany,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { ProductSubCategories } from './product-sub-category.entity';
|
import { ProductSubCategories } from './product-sub-category.entity';
|
||||||
import { BaseModel } from '../../config/basemodel.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 { Product } from './product.entity';
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { productType } from '../../helper/enum-list';
|
import { productType } from '../../helper/enum-list';
|
||||||
import { User } from '../../users/entities/user.entity';
|
|
||||||
import { Partner } from '../../users/entities/partner.entity';
|
import { Partner } from '../../users/entities/partner.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
Entity,
|
|
||||||
Column,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
ManyToOne,
|
|
||||||
OneToMany,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { ProductCategories } from './product-category.entity';
|
import { ProductCategories } from './product-category.entity';
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { Product } from './product.entity';
|
import { Product } from './product.entity';
|
||||||
|
|
|
@ -1,14 +1,4 @@
|
||||||
import {
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
Entity,
|
|
||||||
Column,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
UpdateDateColumn,
|
|
||||||
DeleteDateColumn,
|
|
||||||
VersionColumn,
|
|
||||||
CreateDateColumn,
|
|
||||||
OneToMany,
|
|
||||||
ManyToOne,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { ProductSubCategories } from './product-sub-category.entity';
|
import { ProductSubCategories } from './product-sub-category.entity';
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { Supplier } from '../../users/entities/supplier.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 { parsingFile } from '../helper/csv-parser';
|
||||||
import { PartnerService } from '../users/partner/partner.service';
|
import { PartnerService } from '../users/partner/partner.service';
|
||||||
import { mapSeries } from 'bluebird';
|
import { mapSeries } from 'bluebird';
|
||||||
import { isNull } from 'util';
|
|
||||||
|
|
||||||
export class ProductService {
|
export class ProductService {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
import {
|
import { forwardRef, HttpException, HttpStatus, Inject } from '@nestjs/common';
|
||||||
forwardRef,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Inject,
|
|
||||||
Injectable,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { COA } from './entities/coa.entity';
|
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 { InputCoaDto } from './dto/input-coa.dto';
|
||||||
import { UsersService } from 'src/users/users.service';
|
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 {
|
export class AddSaldoSupplier {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
import { balanceType, coaType, statusTransaction, typeTransaction } from 'src/helper/enum-list';
|
import { statusTransaction, typeTransaction } from 'src/helper/enum-list';
|
||||||
import { EntityManager } from 'typeorm';
|
import { EntityManager } from 'typeorm';
|
||||||
import { Transactions } from '../entities/transactions.entity';
|
import { Transactions } from '../entities/transactions.entity';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
export class DistributeTransactionDto {
|
export class DistributeTransactionDto {
|
||||||
@IsNotEmpty()
|
@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 {
|
export class OrderTransactionDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
productCode: string;
|
productCode: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@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 { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { coaType, balanceType } from '../../helper/enum-list';
|
import { balanceType, coaType } from '../../helper/enum-list';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class COA extends BaseModel {
|
export class COA extends BaseModel {
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
import {
|
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||||
Entity,
|
|
||||||
Column,
|
|
||||||
ManyToOne,
|
|
||||||
ManyToMany,
|
|
||||||
JoinTable,
|
|
||||||
OneToOne,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { COA } from './coa.entity';
|
import { COA } from './coa.entity';
|
||||||
import { Transactions } from './transactions.entity';
|
import { Transactions } from './transactions.entity';
|
||||||
|
|
|
@ -1,20 +1,7 @@
|
||||||
import {
|
import { Column, Entity, ManyToOne } from 'typeorm';
|
||||||
Entity,
|
|
||||||
Column,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
UpdateDateColumn,
|
|
||||||
DeleteDateColumn,
|
|
||||||
VersionColumn,
|
|
||||||
CreateDateColumn,
|
|
||||||
ManyToOne,
|
|
||||||
ManyToMany,
|
|
||||||
JoinTable,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
||||||
import { Partner } from '../../users/entities/partner.entity';
|
|
||||||
import { ProductHistoryPrice } from '../../product/entities/product-history-price.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 { UserDetail } from '../../users/entities/user_detail.entity';
|
||||||
import { TransactionJournal } from './transaction-journal.entity';
|
import { TransactionJournal } from './transaction-journal.entity';
|
||||||
|
|
||||||
|
@ -48,6 +35,11 @@ export class Transactions extends BaseModel {
|
||||||
})
|
})
|
||||||
image_prove: string;
|
image_prove: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
destination: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
|
@ -56,7 +48,7 @@ export class Transactions extends BaseModel {
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
phone_number: string;
|
partner_trx_id: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
|
@ -1,17 +1,5 @@
|
||||||
import {
|
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Body,
|
|
||||||
Patch,
|
|
||||||
Param,
|
|
||||||
Delete,
|
|
||||||
HttpStatus,
|
|
||||||
Logger,
|
|
||||||
Req,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
|
||||||
import { FastifyRequest } from 'fastify';
|
import { FastifyRequest } from 'fastify';
|
||||||
import { Public } from '../auth/public.decorator';
|
import { Public } from '../auth/public.decorator';
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
import {
|
import { Body, Controller, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
HttpStatus,
|
|
||||||
Param,
|
|
||||||
ParseUUIDPipe,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Query,
|
|
||||||
Request,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
||||||
|
@ -117,15 +106,15 @@ export class TransactionController {
|
||||||
async getHistoryTransactionUser(
|
async getHistoryTransactionUser(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('pageSize') pageSize: number,
|
@Query('pageSize') pageSize: number,
|
||||||
@Query('startDate') startDate: string,
|
@Query('start') startDate: string,
|
||||||
@Query('endDate') endDate: string,
|
@Query('end') endDate: string,
|
||||||
@Request() req,
|
@Request() req,
|
||||||
) {
|
) {
|
||||||
const data = await this.transactionService.transactionHistoryByUser(
|
const data = await this.transactionService.transactionHistoryByUser(
|
||||||
page,
|
page,
|
||||||
req.user.userId,
|
req.user.userId,
|
||||||
startDate,
|
startDate == 'null' ? null : startDate,
|
||||||
endDate,
|
endDate == 'null' ? null : endDate,
|
||||||
pageSize,
|
pageSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,7 @@ import { CoaService } from './coa.service';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import { uniq } from 'lodash';
|
import { uniq } from 'lodash';
|
||||||
import { Decimal } from 'decimal.js';
|
import { Decimal } from 'decimal.js';
|
||||||
import {
|
import { balanceType, coaType, statusTransaction, typeTransaction } from '../helper/enum-list';
|
||||||
balanceType,
|
|
||||||
coaType,
|
|
||||||
statusTransaction,
|
|
||||||
typeTransaction,
|
|
||||||
} from '../helper/enum-list';
|
|
||||||
import { ProductService } from '../product/product.service';
|
import { ProductService } from '../product/product.service';
|
||||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||||
import { UsersService } from 'src/users/users.service';
|
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 { doTransaction } from '../helper/irs-api';
|
||||||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
||||||
|
|
||||||
interface JournalEntry {
|
|
||||||
coa_id: string;
|
|
||||||
debit?: string;
|
|
||||||
credit?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionService {
|
export class TransactionService {
|
||||||
private readonly logger = new Logger(TransactionService.name);
|
private readonly logger = new Logger(TransactionService.name);
|
||||||
|
@ -387,7 +376,7 @@ export class TransactionService {
|
||||||
transactionData.status = statusTransaction.SUCCESS;
|
transactionData.status = statusTransaction.SUCCESS;
|
||||||
transactionData.type = typeTransaction.ORDER;
|
transactionData.type = typeTransaction.ORDER;
|
||||||
transactionData.product_price = product_price;
|
transactionData.product_price = product_price;
|
||||||
transactionData.phone_number = orderTransactionDto.phoneNumber;
|
transactionData.destination = orderTransactionDto.destination;
|
||||||
await manager.insert(Transactions, transactionData);
|
await manager.insert(Transactions, transactionData);
|
||||||
|
|
||||||
await this.accountingTransaction({
|
await this.accountingTransaction({
|
||||||
|
@ -409,6 +398,7 @@ export class TransactionService {
|
||||||
debit: product_price.mark_up_price + product_price.price,
|
debit: product_price.mark_up_price + product_price.price,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
coa_id: coaSales.id,
|
coa_id: coaSales.id,
|
||||||
credit: product_price.mark_up_price + product_price.price,
|
credit: product_price.mark_up_price + product_price.price,
|
||||||
},
|
},
|
||||||
|
@ -444,12 +434,14 @@ export class TransactionService {
|
||||||
//TODO HIT API SUPPLIER
|
//TODO HIT API SUPPLIER
|
||||||
const trxId = Array(6)
|
const trxId = Array(6)
|
||||||
.fill(null)
|
.fill(null)
|
||||||
.map(() => Math.round(Math.random() * 16).toString(16))
|
.map(() => {
|
||||||
|
return Math.round(Math.random() * 16).toString(16);
|
||||||
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
const hitSupplier = await doTransaction(
|
const hitSupplier = await doTransaction(
|
||||||
orderTransactionDto.productCode,
|
orderTransactionDto.productCode,
|
||||||
orderTransactionDto.phoneNumber,
|
orderTransactionDto.destination,
|
||||||
trxId,
|
trxId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -465,7 +457,7 @@ export class TransactionService {
|
||||||
transactionData.user = userData.id;
|
transactionData.user = userData.id;
|
||||||
transactionData.type = typeTransaction.ORDER;
|
transactionData.type = typeTransaction.ORDER;
|
||||||
transactionData.product_price = product_price;
|
transactionData.product_price = product_price;
|
||||||
transactionData.phone_number = orderTransactionDto.phoneNumber;
|
transactionData.destination = orderTransactionDto.destination;
|
||||||
transactionData.supplier_trx_id = trxId;
|
transactionData.supplier_trx_id = trxId;
|
||||||
|
|
||||||
if (!hitSupplier.success) {
|
if (!hitSupplier.success) {
|
||||||
|
@ -487,6 +479,7 @@ export class TransactionService {
|
||||||
product_price.endDate = new Date();
|
product_price.endDate = new Date();
|
||||||
|
|
||||||
let newProductPrice = new ProductHistoryPrice();
|
let newProductPrice = new ProductHistoryPrice();
|
||||||
|
|
||||||
newProductPrice = product_price;
|
newProductPrice = product_price;
|
||||||
newProductPrice.id = uuid.v4();
|
newProductPrice.id = uuid.v4();
|
||||||
newProductPrice.price = hitSupplier.harga;
|
newProductPrice.price = hitSupplier.harga;
|
||||||
|
@ -653,6 +646,7 @@ export class TransactionService {
|
||||||
supplier_trx_id: supplier_trx_id,
|
supplier_trx_id: supplier_trx_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
dataTransaction.callback_json = callback;
|
dataTransaction.callback_json = callback;
|
||||||
|
|
||||||
|
@ -666,6 +660,7 @@ export class TransactionService {
|
||||||
},
|
},
|
||||||
relations: ['product_price'],
|
relations: ['product_price'],
|
||||||
});
|
});
|
||||||
|
|
||||||
dataTransaction.status = statusTransaction.FAILED;
|
dataTransaction.status = statusTransaction.FAILED;
|
||||||
dataTransaction.callback_json = callback;
|
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(
|
async transactionHistoryByUser(
|
||||||
page: number,
|
page: number,
|
||||||
user: string,
|
user: string,
|
||||||
|
@ -770,26 +810,48 @@ export class TransactionService {
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
) {
|
) {
|
||||||
const userData = await this.userService.findExist(user);
|
const userData = await this.userService.findExist(user);
|
||||||
let filterTransactionDate;
|
|
||||||
|
|
||||||
let userBySupperior = [];
|
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)
|
if (
|
||||||
userBySupperior = getListUser.data.map(x => x.id)
|
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 {
|
} else {
|
||||||
userBySupperior.push(user)
|
userBySupperior.push(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseQuery = this.transactionRepository
|
const baseQuery = this.transactionRepository
|
||||||
.createQueryBuilder('transaction')
|
.createQueryBuilder('transaction')
|
||||||
.select('transaction.id', 'id')
|
.select('transaction.id', 'id')
|
||||||
.addSelect('transaction.created_at', 'created_at')
|
.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,
|
id: userBySupperior,
|
||||||
})
|
})
|
||||||
|
.leftJoinAndMapOne(
|
||||||
|
'transaction.userData',
|
||||||
|
UserDetail,
|
||||||
|
'userData',
|
||||||
|
'userData.user = transaction.user',
|
||||||
|
)
|
||||||
.leftJoin('transaction.product_price', 'product_price')
|
.leftJoin('transaction.product_price', 'product_price')
|
||||||
.leftJoin('product_price.product', 'product')
|
.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.name', 'name')
|
||||||
.addSelect('product.id', 'product_id');
|
.addSelect('product.id', 'product_id');
|
||||||
|
|
||||||
|
@ -921,6 +983,7 @@ export class TransactionService {
|
||||||
data,
|
data,
|
||||||
count: totalData,
|
count: totalData,
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.transactionRepository.findAndCount({
|
return this.transactionRepository.findAndCount({
|
||||||
skip: page * (pageSize || 10),
|
skip: page * (pageSize || 10),
|
||||||
take: 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() {
|
async getTotalSell() {
|
||||||
const { total_amount } = await this.transactionRepository
|
const { total_amount } = await this.transactionRepository
|
||||||
.createQueryBuilder('transactions')
|
.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 { Partner } from '../entities/partner.entity';
|
||||||
import { Column } from 'typeorm';
|
|
||||||
|
|
||||||
export class CreateUserDto {
|
export class CreateUserDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { Roles } from 'src/configurable/entities/roles.entity';
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { hashPassword } from '../../helper/hash_password';
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Partner extends BaseModel {
|
export class Partner extends BaseModel {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { Roles } from 'src/configurable/entities/roles.entity';
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { hashPassword } from '../../helper/hash_password';
|
|
||||||
import { COA } from '../../transaction/entities/coa.entity';
|
import { COA } from '../../transaction/entities/coa.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
import { Roles } from 'src/configurable/entities/roles.entity';
|
import { Roles } from 'src/configurable/entities/roles.entity';
|
||||||
import {
|
import { Column, Entity, ManyToOne, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
Column,
|
|
||||||
Entity,
|
|
||||||
ManyToOne,
|
|
||||||
OneToOne,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { Partner } from './partner.entity';
|
import { Partner } from './partner.entity';
|
||||||
import { UserDetail } from './user_detail.entity';
|
import { UserDetail } from './user_detail.entity';
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
Column,
|
|
||||||
Entity,
|
|
||||||
JoinColumn,
|
|
||||||
OneToOne,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import {
|
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||||
forwardRef,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Inject,
|
|
||||||
Injectable,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
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 { CoaService } from '../../transaction/coa.service';
|
||||||
import { CreatePartnerDto } from '../dto/create-partner.dto';
|
import { CreatePartnerDto } from '../dto/create-partner.dto';
|
||||||
import { Partner } from '../entities/partner.entity';
|
import { Partner } from '../entities/partner.entity';
|
||||||
|
@ -15,7 +9,6 @@ import { UsersService } from '../users.service';
|
||||||
import { CreateUserDto } from '../dto/create-user.dto';
|
import { CreateUserDto } from '../dto/create-user.dto';
|
||||||
import { UpdatePartnerDto } from '../dto/update-partner.dto';
|
import { UpdatePartnerDto } from '../dto/update-partner.dto';
|
||||||
import { UpdateUserDto } from '../dto/update-user.dto';
|
import { UpdateUserDto } from '../dto/update-user.dto';
|
||||||
import { when } from 'joi';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PartnerService {
|
export class PartnerService {
|
||||||
|
|
|
@ -114,13 +114,13 @@ export class UsersController {
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll(
|
async findAll(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('superior') superior: string,
|
@Query('superior') superior: string,
|
||||||
@Query('type') type: string,
|
@Query('type') type: string,
|
||||||
) {
|
) {
|
||||||
const data = await this.usersService.findAll(
|
const data = await this.usersService.findAll(
|
||||||
page,
|
page,
|
||||||
req.user.userId,
|
req.user.userId,
|
||||||
superior == 'null' ? null : superior,
|
superior == 'null' ? null : superior,
|
||||||
type == 'null' ? null : type,
|
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')
|
@Get('partner')
|
||||||
async findAllPartner(
|
async findAllPartner(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||||
forwardRef,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Inject,
|
|
||||||
Injectable,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
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 * 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';
|
import { COA } from '../transaction/entities/coa.entity';
|
||||||
|
import { mapSeries } from 'bluebird';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
@ -148,10 +143,10 @@ export class UsersService {
|
||||||
'coa.amount',
|
'coa.amount',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(superior){
|
if (superior) {
|
||||||
baseQuery.where('user.superior = :id_supperior',{
|
baseQuery.where('user.superior = :id_supperior', {
|
||||||
id_supperior:superior
|
id_supperior: superior,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type){
|
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) {
|
findByRoles(relationId: string, page: number, pageSize?: number) {
|
||||||
return this.usersRepository.findAndCount({
|
return this.usersRepository.findAndCount({
|
||||||
skip: page * (pageSize || 10),
|
skip: page * (pageSize || 10),
|
||||||
|
@ -238,7 +269,7 @@ export class UsersService {
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
relations: ['superior','roles'],
|
relations: ['superior', 'roles'],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
@ -280,6 +311,7 @@ export class UsersService {
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
||||||
|
const coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userData = await this.usersRepository
|
const userData = await this.usersRepository
|
||||||
|
@ -308,6 +340,7 @@ export class UsersService {
|
||||||
return {
|
return {
|
||||||
...userData,
|
...userData,
|
||||||
wallet: coa.amount,
|
wallet: coa.amount,
|
||||||
|
profit: coaProfit.amount,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user