Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
85d8bcd3ec | ||
|
c301af2d8d |
|
@ -16,7 +16,7 @@ FROM node:16-alpine as builder
|
|||
|
||||
ENV NODE_ENV build
|
||||
|
||||
#USER node
|
||||
USER node
|
||||
WORKDIR /home/node
|
||||
|
||||
COPY package.json .
|
||||
|
|
|
@ -6,10 +6,9 @@ metadata:
|
|||
annotations:
|
||||
kubernetes.io/ingress.class: "traefik"
|
||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||
traefik.ingress.kubernetes.io/router.middlewares: empatnusabangsa-production-redirect-https@kubernetescrd
|
||||
spec:
|
||||
rules:
|
||||
- host: "api.wndsolutions.id"
|
||||
- host: "ppob-backend.k3s.bangun-kreatif.com"
|
||||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
|
@ -21,5 +20,5 @@ spec:
|
|||
number: 5000
|
||||
tls:
|
||||
- hosts:
|
||||
- "api.wndsolutions.id"
|
||||
secretName: api-wndsolutions-id-tls
|
||||
- "ppob-backend.k3s.bangun-kreatif.com"
|
||||
secretName: ppob-backend-k3s-bangun-kreatif-com-tls
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: redirect-https
|
||||
namespace: empatnusabangsa-production
|
||||
spec:
|
||||
redirectScheme:
|
||||
scheme: https
|
||||
permanent: true
|
18837
package-lock.json
generated
18837
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
|
@ -19,7 +19,9 @@
|
|||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"seed:config": "ts-node ./node_modules/typeorm-seeding/dist/cli.js config",
|
||||
"seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
|
@ -33,22 +35,17 @@
|
|||
"@nestjs/typeorm": "^8.0.2",
|
||||
"axios": "^0.24.0",
|
||||
"bluebird": "^3.7.2",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"class-transformer": "^0.4.0",
|
||||
"class-validator": "^0.13.1",
|
||||
"crypto": "^1.0.1",
|
||||
"crypto-md5": "^1.0.0",
|
||||
"csv-parser": "^3.0.0",
|
||||
"decimal.js": "^10.3.1",
|
||||
"exceljs": "^4.3.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"fs-extra": "^10.0.0",
|
||||
"joi": "^17.4.2",
|
||||
"lodash": "^4.17.21",
|
||||
"md5-hash": "^1.0.1",
|
||||
"moment": "^2.29.4",
|
||||
"nestjs-pino": "^2.3.1",
|
||||
"passport": "^0.4.0",
|
||||
"passport": "^0.5.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^8.7.1",
|
||||
|
@ -57,9 +54,9 @@
|
|||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.2.0",
|
||||
"tmp": "^0.2.1",
|
||||
"typeorm": "^0.2.37",
|
||||
"typeorm-naming-strategies": "^2.0.0"
|
||||
"typeorm-naming-strategies": "^2.0.0",
|
||||
"typeorm-seeding": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^8.0.0",
|
||||
|
|
|
@ -45,9 +45,11 @@ import { MulterModule } from '@nestjs/platform-express';
|
|||
password: configService.get<string>('database.password'),
|
||||
database: configService.get<string>('database.name'),
|
||||
entities: [],
|
||||
synchronize: false,
|
||||
synchronize: true,
|
||||
autoLoadEntities: true,
|
||||
logging: true,
|
||||
seeds: ['src/seeds/**/*{.ts,.js}'],
|
||||
factories: ['src/factories/**/*{.ts,.js}'],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
};
|
||||
},
|
||||
|
|
|
@ -1,233 +1,19 @@
|
|||
import axios from 'axios';
|
||||
import {HttpException, HttpStatus, NotFoundException} from "@nestjs/common";
|
||||
import {createHmac} from "crypto";
|
||||
|
||||
const irs_url = 'http://h2h.elangpixiu.com/api/h2h';
|
||||
const irs_url = 'http://h2h.elangpangarep.com/api/h2h';
|
||||
const irs_id = 'PT0005';
|
||||
const irs_pin = '04JFGC';
|
||||
const irs_user = 'D10BD0';
|
||||
const irs_pass = '6251F3';
|
||||
const irs_pass = '6251F3';
|
||||
|
||||
export const doTransaction = async (
|
||||
productCode,
|
||||
destination,
|
||||
idtrx,
|
||||
supplier,
|
||||
authorization,
|
||||
typePaid,
|
||||
billTrxId,
|
||||
productVocaSubCategoryId,
|
||||
productPrice
|
||||
) => {
|
||||
export const doTransaction = async (productCode, destination, idtrx) => {
|
||||
try {
|
||||
if (supplier.code == 'IRS') {
|
||||
const res = await axios.get(
|
||||
`${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} else if (supplier.code == 'NIRS') {
|
||||
const res = await axios.get(
|
||||
`${supplier.url}?id=${supplier.irs_id}&pin=${supplier.irs_pin}&user=${supplier.irs_user}&pass=${supplier.irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} else if (supplier.code == 'Vocagame') {
|
||||
const merchantId = supplier.irs_id;
|
||||
const reference = idtrx
|
||||
const endpoint = `/transaction/${reference}`;
|
||||
const secretKey = supplier.irs_pass;
|
||||
const signature = createHmac('sha256', secretKey)
|
||||
.update(merchantId + endpoint)
|
||||
.digest('hex');
|
||||
|
||||
const options = {
|
||||
headers: {'Content-Type': 'application/json',
|
||||
'X-Merchant': `${merchantId}`},
|
||||
};
|
||||
|
||||
const mergedDestination = destination;
|
||||
const regex = /\(([^)]+)\)/;
|
||||
const match = regex.exec(mergedDestination);
|
||||
|
||||
let productDestination = ""
|
||||
let productRegion = ""
|
||||
if (match) {
|
||||
var productSplit = destination.split('(')
|
||||
productDestination = productSplit[0]
|
||||
const insideBrackets = match[1];
|
||||
productRegion = insideBrackets // This will print inside brackets
|
||||
} else {
|
||||
productDestination = destination
|
||||
}
|
||||
|
||||
const data =
|
||||
{
|
||||
productId: productVocaSubCategoryId, // Sub Kategori ID
|
||||
productItemId: productCode, // Product Code
|
||||
data: { // Get object from user input within endpoint /products/detail
|
||||
userId: productDestination,
|
||||
zoneId: productRegion // Optional
|
||||
},
|
||||
price: productPrice, // Price equals from items
|
||||
reference: reference, // Your reference I
|
||||
callbackUrl: "https://api.wndsolutions.id/v1/ppob_callback/vocagame" // Set your endpoint callback
|
||||
}
|
||||
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/v1/core/transaction?signature=${signature}`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
var responseVoca = res.data.data;
|
||||
console.log('iniresponsevoca', responseVoca)
|
||||
if (responseVoca != null) {
|
||||
const endpointDetail = `/transaction/${responseVoca.invoiceId}/detail`;
|
||||
const signatureDetail = createHmac('sha256', secretKey)
|
||||
.update(merchantId + endpointDetail)
|
||||
.digest('hex');
|
||||
const resDetail = await axios.get(
|
||||
`${supplier.url}/v1/core/transaction/${responseVoca.invoiceId}/detail?signature=${signatureDetail}`,
|
||||
options,
|
||||
);
|
||||
|
||||
return resDetail.data
|
||||
}
|
||||
|
||||
} else if (supplier.code == 'Digiflazz') {
|
||||
if (typePaid == 'INQUIRY') {
|
||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||
const md5Hash = require("blueimp-md5");
|
||||
|
||||
const options = {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
const data = {
|
||||
commands: 'inq-pasca',
|
||||
username: supplier.irs_user,
|
||||
customer_no: `${destination}`,
|
||||
buyer_sku_code: `${productCode}`,
|
||||
ref_id: `${idtrx}`,
|
||||
sign: md5Hash(md5HashDigiflazz),
|
||||
};
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/transaction`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
return res.data.data;
|
||||
} else if (typePaid == 'PAYMENT') {
|
||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||
const md5Hash = require("blueimp-md5");
|
||||
|
||||
const options = {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
const data = {
|
||||
commands: 'pay-pasca',
|
||||
username: supplier.irs_user,
|
||||
customer_no: `${destination}`,
|
||||
buyer_sku_code: `${productCode}`,
|
||||
ref_id: `${billTrxId}`,
|
||||
sign: md5Hash(md5HashDigiflazz),
|
||||
};
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/transaction`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
return res.data.data;
|
||||
} else {
|
||||
const md5HashDigiflazz = `${supplier.irs_user}${supplier.irs_pass}${idtrx}`;
|
||||
const md5Hash = require("blueimp-md5");
|
||||
console.log('testmd5', md5HashDigiflazz);
|
||||
const options = {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
};
|
||||
const data = {
|
||||
username: supplier.irs_user,
|
||||
customer_no: `${destination}`,
|
||||
buyer_sku_code: `${productCode}`,
|
||||
ref_id: `${idtrx}`,
|
||||
sign: md5Hash(md5HashDigiflazz),
|
||||
};
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/transaction`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
console.log('resdigiflazz', res);
|
||||
return res.data.data;
|
||||
}
|
||||
} else if (supplier.code == 'Hemat') {
|
||||
if (authorization != '') {
|
||||
console.log('initoken', authorization);
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${authorization}`,
|
||||
},
|
||||
};
|
||||
const data = {
|
||||
idtransaction: idtrx,
|
||||
destination: `${destination}`,
|
||||
code: `${productCode}`,
|
||||
type: `${typePaid}`,
|
||||
};
|
||||
const res = await axios.post(
|
||||
`${supplier.url}/v1/transaction/request`,
|
||||
data,
|
||||
options,
|
||||
);
|
||||
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${supplier.url}?memberID=${supplier.irs_id}&pin=${supplier.irs_pin}&password=${supplier.irs_pass}&product=${productCode}&dest=${destination}&counter=1&refID=${idtrx}`,
|
||||
);
|
||||
console.log('restransini', res);
|
||||
console.log('restransini1', res.status);
|
||||
if (res.data.includes('Saldo anda tidak mencukupi')) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: 'maaf saat ini transaksi sedang tidak bisa diproses, silahkan hubungi WND Solutions untuk bisa di proses kembali',
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} else {
|
||||
return res.data;
|
||||
}
|
||||
} catch (e) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: 'maaf saat ini transaksi sedang tidak bisa diproses, silahkan hubungi WND Solutions untuk bisa di proses kembali',
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('errtransaction', err);
|
||||
console.log('errtransaction2', err.response.data);
|
||||
console.log('errtransaction3', err.response.status);
|
||||
console.log('errtransaction4', err.message);
|
||||
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: 'maaf saat ini transaksi sedang tidak bisa diproses, silahkan hubungi WND Solutions untuk bisa di proses kembali',
|
||||
},
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
const res = await axios.get(
|
||||
`${irs_url}?id=${irs_id}&pin=${irs_pin}&user=${irs_user}&pass=${irs_pass}&kodeproduk=${productCode}&tujuan=${destination}&counter=1&idtrx=${idtrx}`,
|
||||
);
|
||||
|
||||
return res.data;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ export const createTransaction = async (kode, tujuan) => {
|
|||
|
||||
return axios.default
|
||||
.get(
|
||||
`http://h2h.elangpixiu.com/api/h2h?id=PT0005&pin=04JFGC&user=D10BD0&pass=6251F3&kodeproduk=${kode}&tujuan=${tujuan}&counter=1&idtrx=${codeTransaksi}`,
|
||||
`http://h2h.elangpangarep.com/api/h2h?id=PT0005&pin=04JFGC&user=D10BD0&pass=6251F3&kodeproduk=${kode}&tujuan=${tujuan}&counter=1&idtrx=${codeTransaksi}`,
|
||||
)
|
||||
.then((response) => {
|
||||
return response.data;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const doAuthorizeHemat = async (user, pass, supplier) => {
|
||||
try {
|
||||
const data = {
|
||||
username: `${user}`,
|
||||
password: `${pass}`,
|
||||
};
|
||||
const res = await axios.post(`${supplier.url}/authenticate`, data);
|
||||
|
||||
return res.data;
|
||||
} catch (err) {
|
||||
console.log('errauthhemat', err)
|
||||
throw err;
|
||||
}
|
||||
};
|
|
@ -11,9 +11,6 @@ export class UpdatePriceProductDto {
|
|||
@IsNotEmpty()
|
||||
type: productType;
|
||||
|
||||
@IsNotEmpty()
|
||||
productType: string;
|
||||
|
||||
startDate: Date;
|
||||
|
||||
endDate: Date;
|
||||
|
|
|
@ -32,14 +32,4 @@ export class ProductHistoryPrice extends BaseModel {
|
|||
|
||||
@Column('text')
|
||||
type: productType;
|
||||
|
||||
@Column({
|
||||
default: 0,
|
||||
})
|
||||
admin_price: number;
|
||||
|
||||
@Column({
|
||||
default: 0,
|
||||
})
|
||||
partner_fee: number;
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
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 { Partner } from '../../users/entities/partner.entity';
|
||||
|
||||
@Entity()
|
||||
export class ProductHistoryStatus extends BaseModel {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@ManyToOne(() => Product, (product) => product.id)
|
||||
product: Product;
|
||||
|
||||
@ManyToOne(() => Partner, (partner) => partner.id)
|
||||
partner: Partner;
|
||||
|
||||
@Column()
|
||||
status: string;
|
||||
}
|
|
@ -16,11 +16,6 @@ export class ProductSubCategories extends BaseModel {
|
|||
})
|
||||
code: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
code_voca: string;
|
||||
|
||||
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
||||
category: ProductCategories;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import { ProductSubCategories } from './product-sub-category.entity';
|
|||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { Supplier } from '../../users/entities/supplier.entity';
|
||||
import { ProductHistoryPrice } from './product-history-price.entity';
|
||||
import {ProductHistoryStatus} from "./product-history-status.entity";
|
||||
|
||||
@Entity()
|
||||
export class Product extends BaseModel {
|
||||
|
@ -29,16 +28,6 @@ export class Product extends BaseModel {
|
|||
})
|
||||
basePrice: number;
|
||||
|
||||
@Column({
|
||||
default: 'prepaid',
|
||||
})
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
type: 'uuid'
|
||||
})
|
||||
sub_categories_id: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => {
|
||||
return ProductSubCategories;
|
||||
|
@ -59,19 +48,6 @@ export class Product extends BaseModel {
|
|||
)
|
||||
supplier: Supplier;
|
||||
|
||||
|
||||
@OneToMany(
|
||||
() => {
|
||||
return ProductHistoryStatus;
|
||||
},
|
||||
(php) => {
|
||||
return php.product;
|
||||
},
|
||||
)
|
||||
statusHistory: ProductHistoryStatus;
|
||||
|
||||
currentStatus: ProductHistoryStatus;
|
||||
|
||||
@OneToMany(
|
||||
() => {
|
||||
return ProductHistoryPrice;
|
||||
|
|
|
@ -69,9 +69,6 @@ export class ProductHistoryPriceService {
|
|||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
console.log("pricenotfound1", "msk")
|
||||
console.log("pricenotfound1product", product)
|
||||
console.log("pricenotfound1partner", partner)
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
|
@ -95,7 +92,6 @@ export class ProductHistoryPriceService {
|
|||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
console.log("pricenotfound2", "msk")
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
|
@ -119,8 +115,8 @@ export class ProductHistoryPriceService {
|
|||
const query = this.productHistoryPriceRepository
|
||||
.createQueryBuilder('product_history_price')
|
||||
.leftJoin('product_history_price.product', 'product')
|
||||
.where({ product: productId });
|
||||
// .andWhere('product_history_price.endDate IS NULL');
|
||||
.where({ product: productId })
|
||||
.andWhere('product_history_price.endDate IS NULL');
|
||||
|
||||
if (supplierId !== 'null' && supplierId) {
|
||||
query.andWhere('product.supplier = :supplierId', {
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { EntityNotFoundError, IsNull, Repository } from 'typeorm';
|
||||
import { ProductHistoryStatus } from '../entities/product-history-status.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ProductHistoryStatusService {
|
||||
constructor(
|
||||
@InjectRepository(ProductHistoryStatus)
|
||||
private productHistoryStatusRepository: Repository<ProductHistoryStatus>,
|
||||
) {}
|
||||
|
||||
async create(dataProduct: ProductHistoryStatus) {
|
||||
const result = await this.productHistoryStatusRepository.insert(
|
||||
dataProduct,
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async findOneActive(productId: string, partnerId: string) {
|
||||
try {
|
||||
return await this.productHistoryStatusRepository.findOneOrFail({
|
||||
relations: ['product'],
|
||||
where: {
|
||||
product: productId,
|
||||
partner: partnerId,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not active',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,8 +10,6 @@ import { ProductSubCategories } from './entities/product-sub-category.entity';
|
|||
import { ProductSubCategoriesService } from './product-sub-categories.service';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { ProductHistoryPriceService } from './history-price/history-price.service';
|
||||
import {ProductHistoryStatus} from "./entities/product-history-status.entity";
|
||||
import {ProductHistoryStatusService} from "./history-status/history-status.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -19,7 +17,6 @@ import {ProductHistoryStatusService} from "./history-status/history-status.servi
|
|||
Product,
|
||||
ProductCategories,
|
||||
ProductHistoryPrice,
|
||||
ProductHistoryStatus,
|
||||
ProductSubCategories,
|
||||
]),
|
||||
forwardRef(() => UsersModule),
|
||||
|
@ -30,8 +27,7 @@ import {ProductHistoryStatusService} from "./history-status/history-status.servi
|
|||
ProductCategoriesService,
|
||||
ProductSubCategoriesService,
|
||||
ProductHistoryPriceService,
|
||||
ProductHistoryStatusService,
|
||||
],
|
||||
exports: [ProductService, ProductHistoryPriceService, ProductHistoryStatusService, ProductSubCategoriesService],
|
||||
exports: [ProductService, ProductHistoryPriceService],
|
||||
})
|
||||
export class ProductModule {}
|
||||
|
|
|
@ -13,25 +13,22 @@ 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 { ProductHistoryStatus } from './entities/product-history-status.entity';
|
||||
|
||||
export class ProductService {
|
||||
constructor(
|
||||
@InjectRepository(Product)
|
||||
private productRepository: Repository<Product>,
|
||||
@InjectRepository(ProductHistoryPrice)
|
||||
private productHistoryPrice: Repository<ProductHistoryPrice>,
|
||||
@InjectRepository(ProductHistoryStatus)
|
||||
private productHistoryStatus: Repository<ProductHistoryStatus>,
|
||||
private productSubCategoriesService: ProductSubCategoriesService,
|
||||
private usersService: UsersService,
|
||||
private supplierService: SupplierService,
|
||||
private partnerService: PartnerService,
|
||||
@InjectRepository(Product)
|
||||
private productRepository: Repository<Product>,
|
||||
@InjectRepository(ProductHistoryPrice)
|
||||
private productHistoryPrice: Repository<ProductHistoryPrice>,
|
||||
private productSubCategoriesService: ProductSubCategoriesService,
|
||||
private usersService: UsersService,
|
||||
private supplierService: SupplierService,
|
||||
private partnerService: PartnerService,
|
||||
) {}
|
||||
|
||||
async create(createProductDto: CreateProductDto) {
|
||||
const subCategories = await this.productSubCategoriesService.findOne(
|
||||
createProductDto.subCategoriesId,
|
||||
createProductDto.subCategoriesId,
|
||||
);
|
||||
|
||||
const result = await this.productRepository.insert({
|
||||
|
@ -58,15 +55,13 @@ export class ProductService {
|
|||
const supplierData = await this.supplierService.findByCode(supplierCode);
|
||||
|
||||
const data = await parsingFile(uploadFile);
|
||||
|
||||
data.shift();
|
||||
await mapSeries(data, async (it) => {
|
||||
let dataHistoryPrice;
|
||||
let partnerData;
|
||||
let productStatusPartner;
|
||||
|
||||
const subCategories =
|
||||
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
||||
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
||||
|
||||
if (!subCategories) {
|
||||
return;
|
||||
|
@ -76,35 +71,15 @@ export class ProductService {
|
|||
code: it[0],
|
||||
supplier: supplierData,
|
||||
});
|
||||
|
||||
const productStatus = await this.productHistoryStatus.findOne({
|
||||
product: productData,
|
||||
partner: null,
|
||||
});
|
||||
|
||||
if (productData) {
|
||||
//TODO : Handle Update Product
|
||||
productData.name = it[1];
|
||||
productData.status = it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE';
|
||||
productData.sub_categories_id = subCategories.id;
|
||||
await this.productRepository.save(productData);
|
||||
|
||||
//TODO : Handle History Price
|
||||
if (it[6] != '-' && it[6] != '') {
|
||||
partnerData = await this.partnerService.findOne(it[6]);
|
||||
productStatusPartner = await this.productHistoryStatus.findOne({
|
||||
product: productData,
|
||||
partner: partnerData.id,
|
||||
});
|
||||
|
||||
if (productStatusPartner === undefined) {
|
||||
await this.productHistoryStatus.insert({
|
||||
product: productData,
|
||||
partner: it[6] != '-' ? partnerData : null,
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
});
|
||||
}
|
||||
|
||||
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||
where: {
|
||||
product: productData.id,
|
||||
|
@ -113,17 +88,6 @@ export class ProductService {
|
|||
},
|
||||
});
|
||||
} else {
|
||||
if (productStatus != undefined) {
|
||||
productStatus.status = it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE';
|
||||
await this.productHistoryStatus.save(productStatus);
|
||||
} else {
|
||||
await this.productHistoryStatus.insert({
|
||||
product: productData,
|
||||
partner: it[6] != '-' ? partnerData : null,
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
});
|
||||
}
|
||||
|
||||
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||
product: productData,
|
||||
partner: IsNull(),
|
||||
|
@ -137,12 +101,6 @@ export class ProductService {
|
|||
});
|
||||
}
|
||||
|
||||
if (productStatusPartner) {
|
||||
await this.productHistoryStatus.update(productStatusPartner.id, {
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
});
|
||||
}
|
||||
|
||||
await this.productHistoryPrice.insert({
|
||||
product: productData,
|
||||
mark_up_price: it[4],
|
||||
|
@ -150,29 +108,18 @@ export class ProductService {
|
|||
type: productType.NORMAL,
|
||||
startDate: new Date(),
|
||||
partner: it[6] != '-' ? partnerData : null,
|
||||
admin_price: it[8],
|
||||
partner_fee: it[9],
|
||||
});
|
||||
} else {
|
||||
let partnerData;
|
||||
|
||||
if (it[6] != '-' && it[6] != '') {
|
||||
partnerData = await this.partnerService.findOne(it[6]);
|
||||
}
|
||||
|
||||
const savedProduct = await this.productRepository.insert({
|
||||
name: it[1],
|
||||
code: it[0],
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
sub_categories: subCategories,
|
||||
supplier: supplierData,
|
||||
type: it[7] == 'postpaid' ? 'postpaid' : 'prepaid',
|
||||
});
|
||||
|
||||
await this.productHistoryStatus.insert({
|
||||
product: savedProduct.identifiers[0],
|
||||
partner: partnerData,
|
||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||
});
|
||||
|
||||
return await this.productHistoryPrice.insert({
|
||||
|
@ -183,8 +130,6 @@ export class ProductService {
|
|||
startDate: new Date(),
|
||||
endDate: null,
|
||||
partner: partnerData,
|
||||
admin_price: it[8],
|
||||
partner_fee: it[9],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -193,10 +138,10 @@ export class ProductService {
|
|||
}
|
||||
|
||||
async findAll(
|
||||
page: number,
|
||||
supplier: string,
|
||||
subCategories: string,
|
||||
pageSize?: number,
|
||||
page: number,
|
||||
supplier: string,
|
||||
subCategories: string,
|
||||
pageSize?: number,
|
||||
) {
|
||||
let filterSupplier, filterSubCategories;
|
||||
|
||||
|
@ -213,40 +158,30 @@ export class ProductService {
|
|||
}
|
||||
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('sub_categories.category', 'category')
|
||||
.leftJoin('product.supplier', 'supplier')
|
||||
.where('supplier.status = :status', { status: true })
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.end_date is NULL',
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentStatus',
|
||||
'product.statusHistory',
|
||||
'history_status',
|
||||
'history_status.deleted_at is NULL',
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
'product.name',
|
||||
'product.code',
|
||||
'sub_categories.name',
|
||||
'supplier.name',
|
||||
'category.name',
|
||||
])
|
||||
.addSelect('history_status.status', 'status')
|
||||
.addSelect('current_price.price', 'price')
|
||||
.addSelect('current_price.partner_fee', 'partner_fee')
|
||||
.addSelect('current_price.admin_price', 'admin_price')
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
||||
)
|
||||
.orderBy('product.code')
|
||||
.distinct();
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('sub_categories.category', 'category')
|
||||
.leftJoin('product.supplier', 'supplier')
|
||||
.where('supplier.status = :status', { status: true })
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null and current_price.end_date is NULL',
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
'product.name',
|
||||
'product.code',
|
||||
'sub_categories.name',
|
||||
'supplier.name',
|
||||
'category.name',
|
||||
'product.status',
|
||||
])
|
||||
.addSelect('current_price.price')
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
||||
);
|
||||
|
||||
if (subCategories && filterSubCategories.length > 0) {
|
||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||
|
@ -261,9 +196,9 @@ export class ProductService {
|
|||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.offset(page * (pageSize || 10))
|
||||
.limit(pageSize || 10)
|
||||
.getRawMany();
|
||||
.offset(page * (pageSize || 10))
|
||||
.limit(pageSize || 10)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
|
@ -275,26 +210,26 @@ export class ProductService {
|
|||
|
||||
async findAllByCategories(page, subCategories, supplier) {
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.where(
|
||||
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
|
||||
{
|
||||
id: subCategories,
|
||||
supplier_id: supplier,
|
||||
},
|
||||
)
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null',
|
||||
);
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.where(
|
||||
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
|
||||
{
|
||||
id: subCategories,
|
||||
supplier_id: supplier,
|
||||
},
|
||||
)
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null',
|
||||
);
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.getMany();
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
|
@ -309,68 +244,37 @@ export class ProductService {
|
|||
supplier = (await this.supplierService.findByActive()).id;
|
||||
}
|
||||
|
||||
console.log(supplier, 'asldklaksd')
|
||||
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('product.supplier', 'supplier')
|
||||
|
||||
// .leftJoin('product.statusHistory', 'status_history')
|
||||
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentStatus',
|
||||
'product.statusHistory',
|
||||
'history_status',
|
||||
`history_status.status = 'ACTIVE' and history_status.deleted_at is NULL`,
|
||||
{
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
)
|
||||
// .where(
|
||||
// `product.supplier_id = :supplier_id`,
|
||||
// {
|
||||
// supplier_id: supplier,
|
||||
// },
|
||||
// )
|
||||
.where(
|
||||
`history_status.partner_id is NULL`,
|
||||
{
|
||||
partner_id: null,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
'supplier.status = TRUE',
|
||||
{
|
||||
status: true,
|
||||
},
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||
.addSelect('(current_price.price + current_price.mark_up_price) as price')
|
||||
.addSelect('product.supplier_id', 'supplier')
|
||||
.addSelect('supplier.status', 'status')
|
||||
.addSelect('history_status.partner_id', 'partner')
|
||||
.addSelect('product.type')
|
||||
.orderBy('price', 'ASC')
|
||||
.distinct();
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.where(
|
||||
`product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||
{
|
||||
supplier_id: supplier,
|
||||
},
|
||||
)
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as price',
|
||||
);
|
||||
|
||||
if (subCategories != 'null' && subCategories) {
|
||||
baseQuery.andWhere('product.sub_categories_id = :id', {
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.offset(page * 1000)
|
||||
.limit(1000)
|
||||
.getRawMany();
|
||||
.offset(page * 10)
|
||||
.limit(10)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
|
@ -381,136 +285,52 @@ export class ProductService {
|
|||
}
|
||||
|
||||
async findAllForPartner(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
subCategories: string,
|
||||
username: string,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
subCategories: string,
|
||||
username: string,
|
||||
) {
|
||||
let filterSubCategories;
|
||||
const user = await this.usersService.findOneByUsername(username);
|
||||
const supplier = await this.supplierService.findByActive();
|
||||
|
||||
if (subCategories) {
|
||||
filterSubCategories = subCategories.split(',').map((data) => {
|
||||
return data.trim();
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.where(
|
||||
`product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||
{
|
||||
supplier_id: supplier.id,
|
||||
},
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id = :id_partner and current_price.end_date is NULL',
|
||||
{
|
||||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
.select(['product.id'])
|
||||
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||
.addSelect(
|
||||
'(current_price.price + current_price.mark_up_price) as price',
|
||||
);
|
||||
|
||||
if (
|
||||
subCategories != 'null' &&
|
||||
subCategories &&
|
||||
subCategories != 'undefined'
|
||||
) {
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
}
|
||||
|
||||
if (user.partner === null) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Partner id not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const baseQuery = await this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('product.supplier', 'supplier')
|
||||
// .leftJoinAndSelect(
|
||||
// 'product.supplier',
|
||||
// 'supplier',
|
||||
// 'supplier.status = true',
|
||||
// {
|
||||
// status: true
|
||||
// }
|
||||
//
|
||||
// )
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id = :id_partner and current_price.end_date is NULL',
|
||||
{
|
||||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
.innerJoinAndMapOne(
|
||||
'product.currentStatus',
|
||||
'product.statusHistory',
|
||||
'history_status',
|
||||
'history_status.partner_id = :id_partner and history_status.deleted_at is NULL',
|
||||
{
|
||||
id_partner: user.partner.id,
|
||||
},
|
||||
)
|
||||
// .where(`history_status.partner_id = :id_partner`, {
|
||||
// partner: user.partner.id,
|
||||
// })
|
||||
.where(`history_status.status = 'ACTIVE'`, {
|
||||
status: 'ACTIVE',
|
||||
})
|
||||
.andWhere('supplier.status = TRUE', {
|
||||
status: true
|
||||
})
|
||||
.select(['product.id'])
|
||||
.addSelect([
|
||||
'product.name',
|
||||
'product.code',
|
||||
'product.type',
|
||||
'product.supplier_id',
|
||||
'sub_categories.name',
|
||||
'current_price.admin_price as admin_price',
|
||||
'current_price.mark_up_price as markup_price',
|
||||
'current_price.partner_fee as partner_fee',
|
||||
'current_price.price as price',
|
||||
])
|
||||
.addSelect('history_status.status', 'status')
|
||||
.distinct();
|
||||
// .addSelect(
|
||||
// '(current_price.price + current_price.mark_up_price) as price',
|
||||
// );
|
||||
|
||||
// if (
|
||||
// subCategories != 'null' &&
|
||||
// subCategories &&
|
||||
// subCategories != 'undefined'
|
||||
// ) {
|
||||
// baseQuery.where('product.sub_categories_id = :id', {
|
||||
// id: subCategories,
|
||||
// });
|
||||
// }
|
||||
|
||||
if (subCategories && filterSubCategories.length > 0) {
|
||||
baseQuery
|
||||
.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||
subCategoryId: filterSubCategories,
|
||||
})
|
||||
.andWhere(`history_status.status = 'ACTIVE'`);
|
||||
}
|
||||
|
||||
const newData = [];
|
||||
|
||||
const data = await baseQuery
|
||||
.offset(page * pageSize)
|
||||
.limit(pageSize)
|
||||
.getRawMany();
|
||||
|
||||
data.map((dataa) => {
|
||||
let actualPrice = 0;
|
||||
|
||||
if (dataa.product_type === 'prepaid') {
|
||||
actualPrice = Number(dataa['price']) + Number(dataa['markup_price']);
|
||||
}
|
||||
|
||||
if (dataa.product_type === 'postpaid') {
|
||||
actualPrice =
|
||||
Number(dataa['admin_price']) -
|
||||
(Number(dataa['partner_fee']) + Number(dataa['markup_price']));
|
||||
}
|
||||
|
||||
dataa.price = actualPrice;
|
||||
|
||||
if (user.username != 'admin') {
|
||||
delete dataa.markup_price;
|
||||
}
|
||||
|
||||
newData.push({
|
||||
...dataa,
|
||||
});
|
||||
});
|
||||
.offset(page * pageSize)
|
||||
.limit(pageSize)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
|
@ -520,23 +340,22 @@ export class ProductService {
|
|||
};
|
||||
}
|
||||
|
||||
async findOne(code: string, type: string, productId: string) {
|
||||
async findOne(code: string) {
|
||||
try {
|
||||
return await this.productRepository.findOneOrFail({
|
||||
relations: ['supplier'],
|
||||
where: {
|
||||
code: code,
|
||||
id: productId
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
|
@ -544,35 +363,6 @@ export class ProductService {
|
|||
}
|
||||
}
|
||||
|
||||
async findOneActive(
|
||||
code: string,
|
||||
type: string,
|
||||
productId: string
|
||||
) {
|
||||
try {
|
||||
return await this.productRepository.findOneOrFail({
|
||||
relations: ['supplier'],
|
||||
where: {
|
||||
code: code,
|
||||
id: productId
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async findOneById(id: string) {
|
||||
try {
|
||||
return await this.productRepository.findOneOrFail({
|
||||
|
@ -584,11 +374,11 @@ export class ProductService {
|
|||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
|
@ -602,11 +392,11 @@ export class ProductService {
|
|||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
|
@ -614,19 +404,9 @@ export class ProductService {
|
|||
}
|
||||
|
||||
const subCategories = await this.productSubCategoriesService.findOne(
|
||||
updateProductDto.subCategoriesId,
|
||||
updateProductDto.subCategoriesId,
|
||||
);
|
||||
|
||||
const dataStatus = await this.productHistoryStatus.findOne({
|
||||
where: {
|
||||
product: id,
|
||||
},
|
||||
});
|
||||
|
||||
await this.productHistoryStatus.update(dataStatus.id, {
|
||||
status: updateProductDto.status,
|
||||
});
|
||||
|
||||
const result = await this.productRepository.update(id, {
|
||||
name: updateProductDto.name,
|
||||
code: updateProductDto.code,
|
||||
|
@ -638,19 +418,19 @@ export class ProductService {
|
|||
}
|
||||
|
||||
async updatePrice(
|
||||
code: string,
|
||||
updatePriceProductDto: UpdatePriceProductDto,
|
||||
code: string,
|
||||
updatePriceProductDto: UpdatePriceProductDto,
|
||||
) {
|
||||
// const product = await this.findOne(code, updatePriceProductDto.productType);
|
||||
const product = await this.findOne(code);
|
||||
|
||||
// await this.productHistoryPrice.insert({
|
||||
// product: product,
|
||||
// type: updatePriceProductDto.type,
|
||||
// price: updatePriceProductDto.price,
|
||||
// mark_up_price: updatePriceProductDto.markUpPrice,
|
||||
// startDate: updatePriceProductDto.startDate,
|
||||
// endDate: updatePriceProductDto.endDate,
|
||||
// });
|
||||
await this.productHistoryPrice.insert({
|
||||
product: product,
|
||||
type: updatePriceProductDto.type,
|
||||
price: updatePriceProductDto.price,
|
||||
mark_up_price: updatePriceProductDto.markUpPrice,
|
||||
startDate: updatePriceProductDto.startDate,
|
||||
endDate: updatePriceProductDto.endDate,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -661,11 +441,11 @@ export class ProductService {
|
|||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Product not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
|
|
31
src/seeder/roles.ts
Normal file
31
src/seeder/roles.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Factory, Seeder } from 'typeorm-seeding';
|
||||
import { Connection } from 'typeorm';
|
||||
import { Roles } from '../configurable/entities/roles.entity';
|
||||
|
||||
export default class CreateUsers implements Seeder {
|
||||
public async run(factory: Factory, connection: Connection): Promise<any> {
|
||||
await connection
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into('roles')
|
||||
.values([
|
||||
{
|
||||
id: '3196cdf4-ae5f-4677-9bcd-98be35c72329',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
deleted_at: null,
|
||||
version: 1,
|
||||
name: 'Admin',
|
||||
},
|
||||
{
|
||||
id: '3196cdf4-ae5f-4677-9bcd-98be35c72328',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
deleted_at: null,
|
||||
version: 1,
|
||||
name: 'Supervisor',
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -50,7 +50,6 @@ export class CoaService {
|
|||
}
|
||||
|
||||
async findByUser(id: string, typeOfCoa: coaType) {
|
||||
console.log('findbyuser', 'msk')
|
||||
try {
|
||||
return await this.coaRepository.findOneOrFail({
|
||||
user: id,
|
||||
|
@ -73,7 +72,6 @@ export class CoaService {
|
|||
|
||||
async findByTwoUser(from: string, destination: string, typeOfCoa: coaType) {
|
||||
try {
|
||||
console.log('findbytwouser', 'msk')
|
||||
return await this.coaRepository.findOneOrFail({
|
||||
user: from,
|
||||
relatedUser: destination,
|
||||
|
@ -122,10 +120,8 @@ export class CoaService {
|
|||
|
||||
async findByName(name: string) {
|
||||
try {
|
||||
console.log('coaname', name);
|
||||
return await this.coaRepository.findOneOrFail({ name: name });
|
||||
} catch (e) {
|
||||
console.log('coaerror', e);
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||
|
||||
export class ExportTransactionDto {
|
||||
@IsNotEmpty()
|
||||
dateStart: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
dateEnd: string;
|
||||
|
||||
@IsOptional()
|
||||
supplier: string;
|
||||
|
||||
@IsOptional()
|
||||
buyer: string;
|
||||
|
||||
}
|
|
@ -1,10 +1,6 @@
|
|||
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||
|
||||
export class OrderTransactionDto {
|
||||
|
||||
@IsNotEmpty()
|
||||
productId: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
productCode: string;
|
||||
|
||||
|
@ -13,7 +9,4 @@ export class OrderTransactionDto {
|
|||
|
||||
@IsOptional()
|
||||
trx_id: string;
|
||||
|
||||
@IsOptional()
|
||||
bill_trx_id: string;
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
||||
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||
import { UserDetail } from '../../users/entities/user_detail.entity';
|
||||
import { TransactionJournal } from './transaction-journal.entity';
|
||||
|
||||
@Entity()
|
||||
export class CallbackPartner extends BaseModel {
|
||||
@Column()
|
||||
trx_id: string;
|
||||
|
||||
@Column()
|
||||
partner_trx_id: string;
|
||||
|
||||
@Column()
|
||||
url: string;
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { statusTransaction, typeTransaction } from '../../helper/enum-list';
|
||||
import { ProductHistoryPrice } from '../../product/entities/product-history-price.entity';
|
||||
import { UserDetail } from '../../users/entities/user_detail.entity';
|
||||
import { TransactionJournal } from './transaction-journal.entity';
|
||||
|
||||
@Entity()
|
||||
export class CheckBillHistory extends BaseModel {
|
||||
@Column()
|
||||
trx_id: string;
|
||||
|
||||
@Column()
|
||||
partner_trx_id: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
amount: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
admin_price: number;
|
||||
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
nullable: true,
|
||||
})
|
||||
user: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
destination: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
request_json: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
callback_json: string;
|
||||
|
||||
@Column()
|
||||
product_code: string;
|
||||
|
||||
@Column()
|
||||
status: string;
|
||||
|
||||
@ManyToOne(() => ProductHistoryPrice, (product) => product.id)
|
||||
product_price: ProductHistoryPrice;
|
||||
}
|
|
@ -10,20 +10,12 @@ export class Transactions extends BaseModel {
|
|||
@Column()
|
||||
amount: number;
|
||||
|
||||
@Column()
|
||||
balance_remaining: number;
|
||||
|
||||
@Column()
|
||||
status: statusTransaction;
|
||||
|
||||
@Column()
|
||||
type: typeTransaction;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
})
|
||||
check_bill: string;
|
||||
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
nullable: true,
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Res,
|
||||
Header,
|
||||
Post,
|
||||
Body,
|
||||
Request,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { ExportTransactionDto } from './dto/export-transaction.dto';
|
||||
|
||||
@Controller({
|
||||
path: 'excel',
|
||||
version: '1',
|
||||
})
|
||||
export class ExcelController {
|
||||
constructor(private transactionService: TransactionService) {}
|
||||
|
||||
@Post('history-user/export/:id')
|
||||
@Header('Content-Type', 'text/xlsx')
|
||||
async exportTransactionHistory(
|
||||
@Param('id') id: string,
|
||||
@Body() exportTransactionDto: ExportTransactionDto,
|
||||
@Request() req,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const result = await this.transactionService.exportDataExcel(
|
||||
exportTransactionDto.dateStart,
|
||||
exportTransactionDto.dateEnd,
|
||||
id,
|
||||
req.user,
|
||||
);
|
||||
|
||||
res.download(`${result}`);
|
||||
}
|
||||
|
||||
@Post('history-user/export-all')
|
||||
@Header('Content-Type', 'text/xlsx')
|
||||
async exportTransactionHistoryAll(
|
||||
@Body() exportTransactionDto: ExportTransactionDto,
|
||||
@Request() req,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
const result = await this.transactionService.exportDataExcelAll(
|
||||
exportTransactionDto.dateStart,
|
||||
exportTransactionDto.dateEnd,
|
||||
exportTransactionDto.supplier,
|
||||
exportTransactionDto.buyer,
|
||||
req.user,
|
||||
);
|
||||
|
||||
res.download(`${result}`);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,7 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Logger, Post,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { Public } from '../auth/public.decorator';
|
||||
import { EntityNotFoundError } from 'typeorm';
|
||||
|
||||
@Controller({
|
||||
path: 'ppob_callback',
|
||||
|
@ -27,179 +19,26 @@ export class PpobCallbackController {
|
|||
|
||||
if (response['statuscode'] == 2) {
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
} else {
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Get('/metro')
|
||||
async getMetro(@Req() request: FastifyRequest) {
|
||||
try {
|
||||
const response = request.query;
|
||||
|
||||
if (response['message'].toLowerCase().includes('CEK TAGIHAN')) {
|
||||
if (response['status'] != 20) {
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.updateBill(
|
||||
response['refid'],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
response['message'],
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
const splitMessage = response['message'].split('"');
|
||||
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.updateBill(
|
||||
response['refid'],
|
||||
Number(splitMessage[21].replace(/^\D+/g, '')),
|
||||
Number(splitMessage[17].replace(/^\D+/g, '')),
|
||||
true,
|
||||
response['message'],
|
||||
);
|
||||
//
|
||||
} else {
|
||||
console.log('statusapani', response['status']);
|
||||
console.log('statusapani2', response.toString());
|
||||
|
||||
if (response['status'].toString() != '20') {
|
||||
//TODO: UPDATE GAGAL
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
|
||||
return {
|
||||
updateTransaction,
|
||||
statusCode: HttpStatus.BAD_REQUEST,
|
||||
message: 'failed to proccess',
|
||||
};
|
||||
} else {
|
||||
|
||||
//TODO: UPDATE BERHASIL
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderSuccess(
|
||||
response['refid'],
|
||||
response,
|
||||
);
|
||||
|
||||
return {
|
||||
updateTransaction,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log({
|
||||
requestQuery: request.query,
|
||||
});
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Error callback',
|
||||
message: e
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('/hemat')
|
||||
async getHemat(@Req() request: FastifyRequest) {
|
||||
const response = request.body;
|
||||
console.log('responsehemat', response);
|
||||
console.log('responsehemat2', request.body);
|
||||
if (response['msg'] != 'Transaksi Sukses') {
|
||||
console.log('masukgagalhemat', 'msk')
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['data']['idtransaction'],
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderFailed(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
);
|
||||
} else {
|
||||
console.log('masuksukseshemat', 'msk')
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['data']['idtransaction'],
|
||||
const updateTransaction =
|
||||
await this.transactionService.callbackOrderSuccess(
|
||||
response['clientid'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('/digiflazz')
|
||||
async getDigiflazz(@Req() request: FastifyRequest) {
|
||||
const response = request.body;
|
||||
console.log('responsedigiflazz', response);
|
||||
if (response['data']['message'] != 'Transaksi Sukses') {
|
||||
//TODO: UPDATE GAGAL
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['data']['ref_id'],
|
||||
response['data'],
|
||||
);
|
||||
} else {
|
||||
//TODO: UPDATE BERHASIL
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['data']['ref_id'],
|
||||
response['data'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('/vocagame')
|
||||
async getVoca(@Req() request: FastifyRequest) {
|
||||
const response = request.body;
|
||||
console.log('responsevocagame', response);
|
||||
if (response['status'] != 'Success') {
|
||||
//TODO: UPDATE GAGAL
|
||||
console.log('responsevocagame1', response['status'])
|
||||
if (response['status'] != 'Processing') {
|
||||
console.log('responsevocagame2', response['status'])
|
||||
await this.transactionService.checkCallbackOrderFailed(
|
||||
response['reference'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
//TODO: UPDATE BERHASIL
|
||||
console.log('responsevocagame3', response['status'])
|
||||
if (response['status'] != 'Processing') {
|
||||
console.log('responsevocagame4', response['status'])
|
||||
await this.transactionService.checkCallbackOrderSuccess(
|
||||
response['reference'],
|
||||
response,
|
||||
);
|
||||
}
|
||||
}
|
||||
this.logger.log({
|
||||
requestQuery: request.query,
|
||||
});
|
||||
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Header,
|
||||
HttpStatus,
|
||||
Param,
|
||||
ParseUUIDPipe,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
Request, Res
|
||||
} 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';
|
||||
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
||||
import { DepositReturnDto } from './dto/deposit_return.dto';
|
||||
import { ExportTransactionDto } from './dto/export-transaction.dto';
|
||||
|
||||
@Controller({
|
||||
path: 'transaction',
|
||||
|
@ -89,50 +76,9 @@ export class TransactionController {
|
|||
async orderTransactionProd(
|
||||
@Body() orderTransactionDto: OrderTransactionDto,
|
||||
@Request() req,
|
||||
) {
|
||||
if (req.get('host').includes('ppob-backend.k3s.bangun-kreatif.com')) {
|
||||
return {
|
||||
data: await this.transactionService.orderTransaction(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: await this.transactionService.orderTransactionProd(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Post('order-bill-prod')
|
||||
async orderTransactioBillnProd(
|
||||
@Body() orderTransactionDto: OrderTransactionDto,
|
||||
@Request() req,
|
||||
) {
|
||||
return {
|
||||
data: await this.transactionService.orderTransactionBillProd(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
statusCode: HttpStatus.CREATED,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Post('check-bill')
|
||||
async checkBill(
|
||||
@Body() orderTransactionDto: OrderTransactionDto,
|
||||
@Request() req,
|
||||
) {
|
||||
return {
|
||||
data: await this.transactionService.checkBill(
|
||||
data: await this.transactionService.orderTransactionProd(
|
||||
orderTransactionDto,
|
||||
req.user,
|
||||
),
|
||||
|
@ -156,48 +102,12 @@ export class TransactionController {
|
|||
};
|
||||
}
|
||||
|
||||
@Post('rollback-jurnal')
|
||||
async rollbackJurnal(@Body() request, @Request() req) {
|
||||
const data = await this.transactionService.rollbackJurnal(request.trxId);
|
||||
return {
|
||||
data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('resend-partner/success/:code')
|
||||
async resendSuccess(@Request() req, @Param('code') code: string) {
|
||||
const data = await this.transactionService.resendOrderToPartner(code, true);
|
||||
return {
|
||||
data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('resend-partner/failed/:code')
|
||||
async resendFailed(@Request() req, @Param('code') code: string) {
|
||||
const data = await this.transactionService.resendOrderToPartner(
|
||||
code,
|
||||
false,
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('history')
|
||||
async getHistoryTransactionUser(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('start') startDate: string,
|
||||
@Query('end') endDate: string,
|
||||
@Query('trxId') trxId: string,
|
||||
@Query('partnerTrxId') partnerTrxId: string,
|
||||
@Request() req,
|
||||
) {
|
||||
const data = await this.transactionService.transactionHistoryByUser(
|
||||
|
@ -205,8 +115,6 @@ export class TransactionController {
|
|||
req.user.userId,
|
||||
startDate == 'null' ? null : startDate,
|
||||
endDate == 'null' ? null : endDate,
|
||||
trxId == 'null' ? null : trxId,
|
||||
partnerTrxId == 'null' ? null : partnerTrxId,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
|
@ -217,35 +125,12 @@ export class TransactionController {
|
|||
};
|
||||
}
|
||||
|
||||
@Get('check-bill-history')
|
||||
async getCheckBillHistory(
|
||||
@Param('id') id: string,
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Request() req,
|
||||
) {
|
||||
const [data, count] = await this.transactionService.findAll(
|
||||
req.user.userId,
|
||||
page,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
count,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('history-user/:id')
|
||||
async getHistoryTransactionUserByParam(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('start') startDate: string,
|
||||
@Query('end') endDate: string,
|
||||
@Query('trxId') trxId: string,
|
||||
@Query('partnerTrxId') partnerTrxId: string,
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
) {
|
||||
const data = await this.transactionService.transactionHistoryByUser(
|
||||
|
@ -253,8 +138,6 @@ export class TransactionController {
|
|||
id,
|
||||
startDate == 'null' ? null : startDate,
|
||||
endDate == 'null' ? null : endDate,
|
||||
trxId == 'null' ? null : trxId,
|
||||
partnerTrxId == 'null' ? null : partnerTrxId,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
|
@ -276,29 +159,6 @@ export class TransactionController {
|
|||
page,
|
||||
req.user.userId,
|
||||
userDestination,
|
||||
'detail',
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
...data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('history-deposit-profile')
|
||||
async getHistoryDepositUserProfile(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('user-destination') userDestination: string,
|
||||
@Request() req,
|
||||
) {
|
||||
const data = await this.transactionService.topUpHistoryByUser(
|
||||
page,
|
||||
req.user.userId,
|
||||
userDestination,
|
||||
'profile',
|
||||
pageSize,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,32 +10,15 @@ import { CoaService } from './coa.service';
|
|||
import { ProductModule } from '../product/product.module';
|
||||
import { UsersModule } from 'src/users/users.module';
|
||||
import { ConfigurableModule } from '../configurable/configurable.module';
|
||||
import { CheckBillHistory } from './entities/check-bill-history.entity';
|
||||
import { CallbackPartner } from './entities/callback-partner.entity';
|
||||
import { ProductHistoryPrice } from '../product/entities/product-history-price.entity';
|
||||
import { ProductHistoryStatus } from '../product/entities/product-history-status.entity';
|
||||
import { ExcelController } from './excel.controller';
|
||||
import {ProductSubCategories} from "../product/entities/product-sub-category.entity";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
COA,
|
||||
TransactionJournal,
|
||||
Transactions,
|
||||
CheckBillHistory,
|
||||
CallbackPartner,
|
||||
ProductHistoryPrice,
|
||||
ProductHistoryStatus,
|
||||
ProductSubCategories
|
||||
]),
|
||||
TypeOrmModule.forFeature([COA, TransactionJournal, Transactions]),
|
||||
ProductModule,
|
||||
ConfigurableModule,
|
||||
forwardRef(() => {
|
||||
return UsersModule;
|
||||
}),
|
||||
forwardRef(() => UsersModule),
|
||||
],
|
||||
controllers: [TransactionController, PpobCallbackController, ExcelController],
|
||||
controllers: [TransactionController, PpobCallbackController],
|
||||
providers: [TransactionService, CoaService],
|
||||
exports: [CoaService],
|
||||
})
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,19 +6,4 @@ export class CreateSupplierDto {
|
|||
|
||||
@IsNotEmpty()
|
||||
code: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
url: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
irs_id: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
irs_pin: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
irs_user: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
irs_pass: string;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,4 @@ export class Partner extends BaseModel {
|
|||
|
||||
@Column({ default: true })
|
||||
status: boolean;
|
||||
|
||||
@Column({
|
||||
default: '',
|
||||
})
|
||||
callback_url: string;
|
||||
}
|
||||
|
|
|
@ -16,31 +16,6 @@ export class Supplier extends BaseModel {
|
|||
@Column()
|
||||
status: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
url: string;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
irs_id: string;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
irs_pin: string;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
irs_user: string;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
irs_pass: string;
|
||||
|
||||
coa: COA;
|
||||
|
||||
coa_undistribute: COA;
|
||||
|
|
|
@ -22,7 +22,7 @@ export class SupplierService {
|
|||
)
|
||||
private coaService: CoaService,
|
||||
private connection: Connection,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async create(createSupplierDto: CreateSupplierDto) {
|
||||
const check = await this.supplierRepository.findOne({
|
||||
|
@ -43,11 +43,6 @@ export class SupplierService {
|
|||
supplierData.id = uuid.v4();
|
||||
supplierData.name = createSupplierDto.name;
|
||||
supplierData.code = createSupplierDto.code;
|
||||
supplierData.url = createSupplierDto.url;
|
||||
supplierData.irs_id = createSupplierDto.irs_id;
|
||||
supplierData.irs_pin = createSupplierDto.irs_pin;
|
||||
supplierData.irs_user = createSupplierDto.irs_user;
|
||||
supplierData.irs_pass = createSupplierDto.irs_pass;
|
||||
supplierData.status = false;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
|
@ -104,11 +99,6 @@ export class SupplierService {
|
|||
const supplierData = new Supplier();
|
||||
|
||||
supplierData.name = updateSupplierDto.name;
|
||||
supplierData.url = updateSupplierDto.url;
|
||||
supplierData.irs_id = updateSupplierDto.irs_id;
|
||||
supplierData.irs_pin = updateSupplierDto.irs_pin;
|
||||
supplierData.irs_user = updateSupplierDto.irs_user;
|
||||
supplierData.irs_pass = updateSupplierDto.irs_pass;
|
||||
supplierData.status = true;
|
||||
|
||||
await this.connection.transaction(async (manager) => {
|
||||
|
|
|
@ -20,15 +20,12 @@ import * as uuid from 'uuid';
|
|||
import { UserDetail } from './entities/user_detail.entity';
|
||||
import { COA } from '../transaction/entities/coa.entity';
|
||||
import { mapSeries } from 'bluebird';
|
||||
import { Partner } from './entities/partner.entity';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private usersRepository: Repository<User>,
|
||||
@InjectRepository(Partner)
|
||||
private partnerRepository: Repository<Partner>,
|
||||
@InjectRepository(UserDetail)
|
||||
private userDetailRepository: Repository<UserDetail>,
|
||||
@Inject(
|
||||
|
@ -70,20 +67,14 @@ export class UsersService {
|
|||
|
||||
if (createUserDto.superior) {
|
||||
let approvalRole = '';
|
||||
if (superior.superior) {
|
||||
if(superior.roles.name == 'Sales'){
|
||||
approvalRole = 'Supervisor';
|
||||
} else {
|
||||
approvalRole = 'Admin';
|
||||
}
|
||||
|
||||
userData.superior = superior;
|
||||
userData.status_approval = superior.superior.id;
|
||||
userData.is_active = false;
|
||||
if(superior.roles.name == 'Sales'){
|
||||
approvalRole = 'Supervisor';
|
||||
} else {
|
||||
userData.superior = superior;
|
||||
userData.is_active = true;
|
||||
approvalRole = 'Admin';
|
||||
}
|
||||
userData.superior = superior;
|
||||
userData.status_approval = superior.superior.id;
|
||||
userData.is_active = false;
|
||||
} else {
|
||||
userData.superior = null;
|
||||
userData.partner = createUserDto.partner;
|
||||
|
@ -366,7 +357,7 @@ export class UsersService {
|
|||
where: {
|
||||
id: id,
|
||||
},
|
||||
relations: ['superior', 'roles', 'partner'],
|
||||
relations: ['superior', 'roles'],
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
|
@ -413,7 +404,6 @@ export class UsersService {
|
|||
.leftJoinAndSelect('users.roles', 'roles')
|
||||
.leftJoinAndSelect('users.superior', 'superior')
|
||||
.leftJoinAndSelect('users.userDetail', 'userDetail')
|
||||
.leftJoinAndSelect('users.partner', 'partner')
|
||||
.where('users.id = :id', {
|
||||
id: id,
|
||||
})
|
||||
|
@ -433,17 +423,8 @@ export class UsersService {
|
|||
'userDetail.identity_number',
|
||||
'userDetail.image_identity',
|
||||
'userDetail.image_store',
|
||||
'partner.id',
|
||||
'partner.name',
|
||||
'partner.code',
|
||||
'partner.npwp',
|
||||
'partner.address',
|
||||
'partner.phone_number',
|
||||
'partner.callback_url'
|
||||
|
||||
])
|
||||
.getOne();
|
||||
console.log('coamsk11', 'coa')
|
||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
||||
let coaProfit;
|
||||
|
||||
|
@ -451,7 +432,6 @@ export class UsersService {
|
|||
userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' &&
|
||||
userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'
|
||||
) {
|
||||
console.log('coamsk12', 'coa')
|
||||
coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
||||
}
|
||||
|
||||
|
@ -690,26 +670,4 @@ export class UsersService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async findPartner(partnerId: string) {
|
||||
try {
|
||||
return this.partnerRepository.findOneOrFail({
|
||||
where: {
|
||||
id: partnerId,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'Partner not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user