Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
85d8bcd3ec | ||
|
c301af2d8d |
|
@ -16,7 +16,7 @@ FROM node:16-alpine as builder
|
||||||
|
|
||||||
ENV NODE_ENV build
|
ENV NODE_ENV build
|
||||||
|
|
||||||
#USER node
|
USER node
|
||||||
WORKDIR /home/node
|
WORKDIR /home/node
|
||||||
|
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
|
|
|
@ -6,10 +6,9 @@ metadata:
|
||||||
annotations:
|
annotations:
|
||||||
kubernetes.io/ingress.class: "traefik"
|
kubernetes.io/ingress.class: "traefik"
|
||||||
cert-manager.io/cluster-issuer: letsencrypt-prod
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
traefik.ingress.kubernetes.io/router.middlewares: empatnusabangsa-production-redirect-https@kubernetescrd
|
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- host: "api.wndsolutions.id"
|
- host: "ppob-backend.k3s.bangun-kreatif.com"
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- pathType: Prefix
|
- pathType: Prefix
|
||||||
|
@ -21,5 +20,5 @@ spec:
|
||||||
number: 5000
|
number: 5000
|
||||||
tls:
|
tls:
|
||||||
- hosts:
|
- hosts:
|
||||||
- "api.wndsolutions.id"
|
- "ppob-backend.k3s.bangun-kreatif.com"
|
||||||
secretName: api-wndsolutions-id-tls
|
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:watch": "jest --watch",
|
||||||
"test:cov": "jest --coverage",
|
"test:cov": "jest --coverage",
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"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": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^8.0.0",
|
"@nestjs/common": "^8.0.0",
|
||||||
|
@ -33,22 +35,17 @@
|
||||||
"@nestjs/typeorm": "^8.0.2",
|
"@nestjs/typeorm": "^8.0.2",
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
"bluebird": "^3.7.2",
|
"bluebird": "^3.7.2",
|
||||||
"blueimp-md5": "^2.19.0",
|
|
||||||
"class-transformer": "^0.4.0",
|
"class-transformer": "^0.4.0",
|
||||||
"class-validator": "^0.13.1",
|
"class-validator": "^0.13.1",
|
||||||
"crypto": "^1.0.1",
|
"crypto": "^1.0.1",
|
||||||
"crypto-md5": "^1.0.0",
|
|
||||||
"csv-parser": "^3.0.0",
|
"csv-parser": "^3.0.0",
|
||||||
"decimal.js": "^10.3.1",
|
"decimal.js": "^10.3.1",
|
||||||
"exceljs": "^4.3.0",
|
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"joi": "^17.4.2",
|
"joi": "^17.4.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"md5-hash": "^1.0.1",
|
|
||||||
"moment": "^2.29.4",
|
|
||||||
"nestjs-pino": "^2.3.1",
|
"nestjs-pino": "^2.3.1",
|
||||||
"passport": "^0.4.0",
|
"passport": "^0.5.0",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"pg": "^8.7.1",
|
"pg": "^8.7.1",
|
||||||
|
@ -57,9 +54,9 @@
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.2.0",
|
"rxjs": "^7.2.0",
|
||||||
"tmp": "^0.2.1",
|
|
||||||
"typeorm": "^0.2.37",
|
"typeorm": "^0.2.37",
|
||||||
"typeorm-naming-strategies": "^2.0.0"
|
"typeorm-naming-strategies": "^2.0.0",
|
||||||
|
"typeorm-seeding": "^1.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^8.0.0",
|
"@nestjs/cli": "^8.0.0",
|
||||||
|
|
|
@ -45,9 +45,11 @@ import { MulterModule } from '@nestjs/platform-express';
|
||||||
password: configService.get<string>('database.password'),
|
password: configService.get<string>('database.password'),
|
||||||
database: configService.get<string>('database.name'),
|
database: configService.get<string>('database.name'),
|
||||||
entities: [],
|
entities: [],
|
||||||
synchronize: false,
|
synchronize: true,
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
logging: true,
|
logging: true,
|
||||||
|
seeds: ['src/seeds/**/*{.ts,.js}'],
|
||||||
|
factories: ['src/factories/**/*{.ts,.js}'],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,233 +1,19 @@
|
||||||
import axios from 'axios';
|
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_id = 'PT0005';
|
||||||
const irs_pin = '04JFGC';
|
const irs_pin = '04JFGC';
|
||||||
const irs_user = 'D10BD0';
|
const irs_user = 'D10BD0';
|
||||||
const irs_pass = '6251F3';
|
const irs_pass = '6251F3';
|
||||||
|
|
||||||
export const doTransaction = async (
|
export const doTransaction = async (productCode, destination, idtrx) => {
|
||||||
productCode,
|
|
||||||
destination,
|
|
||||||
idtrx,
|
|
||||||
supplier,
|
|
||||||
authorization,
|
|
||||||
typePaid,
|
|
||||||
billTrxId,
|
|
||||||
productVocaSubCategoryId,
|
|
||||||
productPrice
|
|
||||||
) => {
|
|
||||||
try {
|
try {
|
||||||
if (supplier.code == 'IRS') {
|
const res = await axios.get(
|
||||||
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}`,
|
||||||
`${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,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@ export const createTransaction = async (kode, tujuan) => {
|
||||||
|
|
||||||
return axios.default
|
return axios.default
|
||||||
.get(
|
.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) => {
|
.then((response) => {
|
||||||
return response.data;
|
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()
|
@IsNotEmpty()
|
||||||
type: productType;
|
type: productType;
|
||||||
|
|
||||||
@IsNotEmpty()
|
|
||||||
productType: string;
|
|
||||||
|
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
|
|
||||||
endDate: Date;
|
endDate: Date;
|
||||||
|
|
|
@ -32,14 +32,4 @@ export class ProductHistoryPrice extends BaseModel {
|
||||||
|
|
||||||
@Column('text')
|
@Column('text')
|
||||||
type: productType;
|
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;
|
code: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
code_voca: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
@ManyToOne(() => ProductCategories, (categories) => categories.sub_categories)
|
||||||
category: ProductCategories;
|
category: ProductCategories;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ 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';
|
||||||
import { ProductHistoryPrice } from './product-history-price.entity';
|
import { ProductHistoryPrice } from './product-history-price.entity';
|
||||||
import {ProductHistoryStatus} from "./product-history-status.entity";
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Product extends BaseModel {
|
export class Product extends BaseModel {
|
||||||
|
@ -29,16 +28,6 @@ export class Product extends BaseModel {
|
||||||
})
|
})
|
||||||
basePrice: number;
|
basePrice: number;
|
||||||
|
|
||||||
@Column({
|
|
||||||
default: 'prepaid',
|
|
||||||
})
|
|
||||||
type: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'uuid'
|
|
||||||
})
|
|
||||||
sub_categories_id: string;
|
|
||||||
|
|
||||||
@ManyToOne(
|
@ManyToOne(
|
||||||
() => {
|
() => {
|
||||||
return ProductSubCategories;
|
return ProductSubCategories;
|
||||||
|
@ -59,19 +48,6 @@ export class Product extends BaseModel {
|
||||||
)
|
)
|
||||||
supplier: Supplier;
|
supplier: Supplier;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(
|
|
||||||
() => {
|
|
||||||
return ProductHistoryStatus;
|
|
||||||
},
|
|
||||||
(php) => {
|
|
||||||
return php.product;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
statusHistory: ProductHistoryStatus;
|
|
||||||
|
|
||||||
currentStatus: ProductHistoryStatus;
|
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => {
|
() => {
|
||||||
return ProductHistoryPrice;
|
return ProductHistoryPrice;
|
||||||
|
|
|
@ -69,9 +69,6 @@ export class ProductHistoryPriceService {
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
console.log("pricenotfound1", "msk")
|
|
||||||
console.log("pricenotfound1product", product)
|
|
||||||
console.log("pricenotfound1partner", partner)
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
@ -95,7 +92,6 @@ export class ProductHistoryPriceService {
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
console.log("pricenotfound2", "msk")
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
@ -119,8 +115,8 @@ export class ProductHistoryPriceService {
|
||||||
const query = this.productHistoryPriceRepository
|
const query = this.productHistoryPriceRepository
|
||||||
.createQueryBuilder('product_history_price')
|
.createQueryBuilder('product_history_price')
|
||||||
.leftJoin('product_history_price.product', 'product')
|
.leftJoin('product_history_price.product', 'product')
|
||||||
.where({ product: productId });
|
.where({ product: productId })
|
||||||
// .andWhere('product_history_price.endDate IS NULL');
|
.andWhere('product_history_price.endDate IS NULL');
|
||||||
|
|
||||||
if (supplierId !== 'null' && supplierId) {
|
if (supplierId !== 'null' && supplierId) {
|
||||||
query.andWhere('product.supplier = :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 { ProductSubCategoriesService } from './product-sub-categories.service';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
import { ProductHistoryPriceService } from './history-price/history-price.service';
|
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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -19,7 +17,6 @@ import {ProductHistoryStatusService} from "./history-status/history-status.servi
|
||||||
Product,
|
Product,
|
||||||
ProductCategories,
|
ProductCategories,
|
||||||
ProductHistoryPrice,
|
ProductHistoryPrice,
|
||||||
ProductHistoryStatus,
|
|
||||||
ProductSubCategories,
|
ProductSubCategories,
|
||||||
]),
|
]),
|
||||||
forwardRef(() => UsersModule),
|
forwardRef(() => UsersModule),
|
||||||
|
@ -30,8 +27,7 @@ import {ProductHistoryStatusService} from "./history-status/history-status.servi
|
||||||
ProductCategoriesService,
|
ProductCategoriesService,
|
||||||
ProductSubCategoriesService,
|
ProductSubCategoriesService,
|
||||||
ProductHistoryPriceService,
|
ProductHistoryPriceService,
|
||||||
ProductHistoryStatusService,
|
|
||||||
],
|
],
|
||||||
exports: [ProductService, ProductHistoryPriceService, ProductHistoryStatusService, ProductSubCategoriesService],
|
exports: [ProductService, ProductHistoryPriceService],
|
||||||
})
|
})
|
||||||
export class ProductModule {}
|
export class ProductModule {}
|
||||||
|
|
|
@ -13,25 +13,22 @@ 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 { ProductHistoryStatus } from './entities/product-history-status.entity';
|
|
||||||
|
|
||||||
export class ProductService {
|
export class ProductService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Product)
|
@InjectRepository(Product)
|
||||||
private productRepository: Repository<Product>,
|
private productRepository: Repository<Product>,
|
||||||
@InjectRepository(ProductHistoryPrice)
|
@InjectRepository(ProductHistoryPrice)
|
||||||
private productHistoryPrice: Repository<ProductHistoryPrice>,
|
private productHistoryPrice: Repository<ProductHistoryPrice>,
|
||||||
@InjectRepository(ProductHistoryStatus)
|
private productSubCategoriesService: ProductSubCategoriesService,
|
||||||
private productHistoryStatus: Repository<ProductHistoryStatus>,
|
private usersService: UsersService,
|
||||||
private productSubCategoriesService: ProductSubCategoriesService,
|
private supplierService: SupplierService,
|
||||||
private usersService: UsersService,
|
private partnerService: PartnerService,
|
||||||
private supplierService: SupplierService,
|
|
||||||
private partnerService: PartnerService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(createProductDto: CreateProductDto) {
|
async create(createProductDto: CreateProductDto) {
|
||||||
const subCategories = await this.productSubCategoriesService.findOne(
|
const subCategories = await this.productSubCategoriesService.findOne(
|
||||||
createProductDto.subCategoriesId,
|
createProductDto.subCategoriesId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.productRepository.insert({
|
const result = await this.productRepository.insert({
|
||||||
|
@ -58,15 +55,13 @@ export class ProductService {
|
||||||
const supplierData = await this.supplierService.findByCode(supplierCode);
|
const supplierData = await this.supplierService.findByCode(supplierCode);
|
||||||
|
|
||||||
const data = await parsingFile(uploadFile);
|
const data = await parsingFile(uploadFile);
|
||||||
|
|
||||||
data.shift();
|
data.shift();
|
||||||
await mapSeries(data, async (it) => {
|
await mapSeries(data, async (it) => {
|
||||||
let dataHistoryPrice;
|
let dataHistoryPrice;
|
||||||
let partnerData;
|
let partnerData;
|
||||||
let productStatusPartner;
|
|
||||||
|
|
||||||
const subCategories =
|
const subCategories =
|
||||||
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
await this.productSubCategoriesService.findOneForCSVParser(it[2]);
|
||||||
|
|
||||||
if (!subCategories) {
|
if (!subCategories) {
|
||||||
return;
|
return;
|
||||||
|
@ -76,35 +71,15 @@ export class ProductService {
|
||||||
code: it[0],
|
code: it[0],
|
||||||
supplier: supplierData,
|
supplier: supplierData,
|
||||||
});
|
});
|
||||||
|
|
||||||
const productStatus = await this.productHistoryStatus.findOne({
|
|
||||||
product: productData,
|
|
||||||
partner: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (productData) {
|
if (productData) {
|
||||||
//TODO : Handle Update Product
|
//TODO : Handle Update Product
|
||||||
productData.name = it[1];
|
productData.name = it[1];
|
||||||
productData.status = it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE';
|
productData.status = it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE';
|
||||||
productData.sub_categories_id = subCategories.id;
|
|
||||||
await this.productRepository.save(productData);
|
await this.productRepository.save(productData);
|
||||||
|
|
||||||
//TODO : Handle History Price
|
//TODO : Handle History Price
|
||||||
if (it[6] != '-' && it[6] != '') {
|
if (it[6] != '-' && it[6] != '') {
|
||||||
partnerData = await this.partnerService.findOne(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({
|
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||||
where: {
|
where: {
|
||||||
product: productData.id,
|
product: productData.id,
|
||||||
|
@ -113,17 +88,6 @@ export class ProductService {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} 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({
|
dataHistoryPrice = await this.productHistoryPrice.findOne({
|
||||||
product: productData,
|
product: productData,
|
||||||
partner: IsNull(),
|
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({
|
await this.productHistoryPrice.insert({
|
||||||
product: productData,
|
product: productData,
|
||||||
mark_up_price: it[4],
|
mark_up_price: it[4],
|
||||||
|
@ -150,29 +108,18 @@ export class ProductService {
|
||||||
type: productType.NORMAL,
|
type: productType.NORMAL,
|
||||||
startDate: new Date(),
|
startDate: new Date(),
|
||||||
partner: it[6] != '-' ? partnerData : null,
|
partner: it[6] != '-' ? partnerData : null,
|
||||||
admin_price: it[8],
|
|
||||||
partner_fee: it[9],
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let partnerData;
|
let partnerData;
|
||||||
|
|
||||||
if (it[6] != '-' && it[6] != '') {
|
if (it[6] != '-' && it[6] != '') {
|
||||||
partnerData = await this.partnerService.findOne(it[6]);
|
partnerData = await this.partnerService.findOne(it[6]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedProduct = await this.productRepository.insert({
|
const savedProduct = await this.productRepository.insert({
|
||||||
name: it[1],
|
name: it[1],
|
||||||
code: it[0],
|
code: it[0],
|
||||||
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
status: it[5] == 'active' ? 'ACTIVE' : 'NOT ACTIVE',
|
||||||
sub_categories: subCategories,
|
sub_categories: subCategories,
|
||||||
supplier: supplierData,
|
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({
|
return await this.productHistoryPrice.insert({
|
||||||
|
@ -183,8 +130,6 @@ export class ProductService {
|
||||||
startDate: new Date(),
|
startDate: new Date(),
|
||||||
endDate: null,
|
endDate: null,
|
||||||
partner: partnerData,
|
partner: partnerData,
|
||||||
admin_price: it[8],
|
|
||||||
partner_fee: it[9],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -193,10 +138,10 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(
|
async findAll(
|
||||||
page: number,
|
page: number,
|
||||||
supplier: string,
|
supplier: string,
|
||||||
subCategories: string,
|
subCategories: string,
|
||||||
pageSize?: number,
|
pageSize?: number,
|
||||||
) {
|
) {
|
||||||
let filterSupplier, filterSubCategories;
|
let filterSupplier, filterSubCategories;
|
||||||
|
|
||||||
|
@ -213,40 +158,30 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseQuery = this.productRepository
|
const baseQuery = this.productRepository
|
||||||
.createQueryBuilder('product')
|
.createQueryBuilder('product')
|
||||||
.leftJoin('product.sub_categories', 'sub_categories')
|
.leftJoin('product.sub_categories', 'sub_categories')
|
||||||
.leftJoin('sub_categories.category', 'category')
|
.leftJoin('sub_categories.category', 'category')
|
||||||
.leftJoin('product.supplier', 'supplier')
|
.leftJoin('product.supplier', 'supplier')
|
||||||
.where('supplier.status = :status', { status: true })
|
.where('supplier.status = :status', { status: true })
|
||||||
.innerJoinAndMapOne(
|
.innerJoinAndMapOne(
|
||||||
'product.currentPrice',
|
'product.currentPrice',
|
||||||
'product.priceHistory',
|
'product.priceHistory',
|
||||||
'current_price',
|
'current_price',
|
||||||
'current_price.end_date is NULL',
|
'current_price.partner_id is null and current_price.end_date is NULL',
|
||||||
)
|
)
|
||||||
.innerJoinAndMapOne(
|
.select(['product.id'])
|
||||||
'product.currentStatus',
|
.addSelect([
|
||||||
'product.statusHistory',
|
'product.name',
|
||||||
'history_status',
|
'product.code',
|
||||||
'history_status.deleted_at is NULL',
|
'sub_categories.name',
|
||||||
)
|
'supplier.name',
|
||||||
.select(['product.id'])
|
'category.name',
|
||||||
.addSelect([
|
'product.status',
|
||||||
'product.name',
|
])
|
||||||
'product.code',
|
.addSelect('current_price.price')
|
||||||
'sub_categories.name',
|
.addSelect(
|
||||||
'supplier.name',
|
'(current_price.price + current_price.mark_up_price) as mark_up_price',
|
||||||
'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();
|
|
||||||
|
|
||||||
if (subCategories && filterSubCategories.length > 0) {
|
if (subCategories && filterSubCategories.length > 0) {
|
||||||
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
baseQuery.where('product.sub_categories_id IN (:...subCategoryId)', {
|
||||||
|
@ -261,9 +196,9 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await baseQuery
|
const data = await baseQuery
|
||||||
.offset(page * (pageSize || 10))
|
.offset(page * (pageSize || 10))
|
||||||
.limit(pageSize || 10)
|
.limit(pageSize || 10)
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
|
|
||||||
const totalData = await baseQuery.getCount();
|
const totalData = await baseQuery.getCount();
|
||||||
|
|
||||||
|
@ -275,26 +210,26 @@ export class ProductService {
|
||||||
|
|
||||||
async findAllByCategories(page, subCategories, supplier) {
|
async findAllByCategories(page, subCategories, supplier) {
|
||||||
const baseQuery = this.productRepository
|
const baseQuery = this.productRepository
|
||||||
.createQueryBuilder('product')
|
.createQueryBuilder('product')
|
||||||
.leftJoin('product.sub_categories', 'sub_categories')
|
.leftJoin('product.sub_categories', 'sub_categories')
|
||||||
.where(
|
.where(
|
||||||
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
|
'sub_categories.category_id = :id and product.supplier_id = :supplier_id',
|
||||||
{
|
{
|
||||||
id: subCategories,
|
id: subCategories,
|
||||||
supplier_id: supplier,
|
supplier_id: supplier,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.leftJoinAndMapOne(
|
.leftJoinAndMapOne(
|
||||||
'product.currentPrice',
|
'product.currentPrice',
|
||||||
'product.priceHistory',
|
'product.priceHistory',
|
||||||
'current_price',
|
'current_price',
|
||||||
'current_price.partner_id is null',
|
'current_price.partner_id is null',
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await baseQuery
|
const data = await baseQuery
|
||||||
.skip(page * 10)
|
.skip(page * 10)
|
||||||
.take(10)
|
.take(10)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
const totalData = await baseQuery.getCount();
|
const totalData = await baseQuery.getCount();
|
||||||
|
|
||||||
|
@ -309,68 +244,37 @@ export class ProductService {
|
||||||
supplier = (await this.supplierService.findByActive()).id;
|
supplier = (await this.supplierService.findByActive()).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(supplier, 'asldklaksd')
|
|
||||||
|
|
||||||
const baseQuery = this.productRepository
|
const baseQuery = this.productRepository
|
||||||
.createQueryBuilder('product')
|
.createQueryBuilder('product')
|
||||||
.leftJoin('product.sub_categories', 'sub_categories')
|
.leftJoin('product.sub_categories', 'sub_categories')
|
||||||
.leftJoin('product.supplier', 'supplier')
|
.where(
|
||||||
|
`product.supplier_id = :supplier_id and product.status = 'ACTIVE'`,
|
||||||
// .leftJoin('product.statusHistory', 'status_history')
|
{
|
||||||
|
supplier_id: supplier,
|
||||||
.leftJoinAndMapOne(
|
},
|
||||||
'product.currentPrice',
|
)
|
||||||
'product.priceHistory',
|
.leftJoinAndMapOne(
|
||||||
'current_price',
|
'product.currentPrice',
|
||||||
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
'product.priceHistory',
|
||||||
)
|
'current_price',
|
||||||
.innerJoinAndMapOne(
|
'current_price.partner_id is NULL and current_price.end_date is NULL',
|
||||||
'product.currentStatus',
|
)
|
||||||
'product.statusHistory',
|
.select(['product.id'])
|
||||||
'history_status',
|
.addSelect(['product.name', 'product.code', 'sub_categories.name'])
|
||||||
`history_status.status = 'ACTIVE' and history_status.deleted_at is NULL`,
|
.addSelect(
|
||||||
{
|
'(current_price.price + current_price.mark_up_price) as price',
|
||||||
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();
|
|
||||||
|
|
||||||
if (subCategories != 'null' && subCategories) {
|
if (subCategories != 'null' && subCategories) {
|
||||||
baseQuery.andWhere('product.sub_categories_id = :id', {
|
baseQuery.where('product.sub_categories_id = :id', {
|
||||||
id: subCategories,
|
id: subCategories,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await baseQuery
|
const data = await baseQuery
|
||||||
.offset(page * 1000)
|
.offset(page * 10)
|
||||||
.limit(1000)
|
.limit(10)
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
|
|
||||||
const totalData = await baseQuery.getCount();
|
const totalData = await baseQuery.getCount();
|
||||||
|
|
||||||
|
@ -381,136 +285,52 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllForPartner(
|
async findAllForPartner(
|
||||||
page: number,
|
page: number,
|
||||||
pageSize: number,
|
pageSize: number,
|
||||||
subCategories: string,
|
subCategories: string,
|
||||||
username: string,
|
username: string,
|
||||||
) {
|
) {
|
||||||
let filterSubCategories;
|
|
||||||
const user = await this.usersService.findOneByUsername(username);
|
const user = await this.usersService.findOneByUsername(username);
|
||||||
|
const supplier = await this.supplierService.findByActive();
|
||||||
|
|
||||||
if (subCategories) {
|
const baseQuery = this.productRepository
|
||||||
filterSubCategories = subCategories.split(',').map((data) => {
|
.createQueryBuilder('product')
|
||||||
return data.trim();
|
.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
|
const data = await baseQuery
|
||||||
.offset(page * pageSize)
|
.offset(page * pageSize)
|
||||||
.limit(pageSize)
|
.limit(pageSize)
|
||||||
.getRawMany();
|
.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,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const totalData = await baseQuery.getCount();
|
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 {
|
try {
|
||||||
return await this.productRepository.findOneOrFail({
|
return await this.productRepository.findOneOrFail({
|
||||||
relations: ['supplier'],
|
relations: ['supplier'],
|
||||||
where: {
|
where: {
|
||||||
code: code,
|
code: code,
|
||||||
id: productId
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
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) {
|
async findOneById(id: string) {
|
||||||
try {
|
try {
|
||||||
return await this.productRepository.findOneOrFail({
|
return await this.productRepository.findOneOrFail({
|
||||||
|
@ -584,11 +374,11 @@ export class ProductService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -602,11 +392,11 @@ export class ProductService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -614,19 +404,9 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const subCategories = await this.productSubCategoriesService.findOne(
|
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, {
|
const result = await this.productRepository.update(id, {
|
||||||
name: updateProductDto.name,
|
name: updateProductDto.name,
|
||||||
code: updateProductDto.code,
|
code: updateProductDto.code,
|
||||||
|
@ -638,19 +418,19 @@ export class ProductService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updatePrice(
|
async updatePrice(
|
||||||
code: string,
|
code: string,
|
||||||
updatePriceProductDto: UpdatePriceProductDto,
|
updatePriceProductDto: UpdatePriceProductDto,
|
||||||
) {
|
) {
|
||||||
// const product = await this.findOne(code, updatePriceProductDto.productType);
|
const product = await this.findOne(code);
|
||||||
|
|
||||||
// await this.productHistoryPrice.insert({
|
await this.productHistoryPrice.insert({
|
||||||
// product: product,
|
product: product,
|
||||||
// type: updatePriceProductDto.type,
|
type: updatePriceProductDto.type,
|
||||||
// price: updatePriceProductDto.price,
|
price: updatePriceProductDto.price,
|
||||||
// mark_up_price: updatePriceProductDto.markUpPrice,
|
mark_up_price: updatePriceProductDto.markUpPrice,
|
||||||
// startDate: updatePriceProductDto.startDate,
|
startDate: updatePriceProductDto.startDate,
|
||||||
// endDate: updatePriceProductDto.endDate,
|
endDate: updatePriceProductDto.endDate,
|
||||||
// });
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -661,11 +441,11 @@ export class ProductService {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
{
|
{
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
error: 'Product not found',
|
error: 'Product not found',
|
||||||
},
|
},
|
||||||
HttpStatus.NOT_FOUND,
|
HttpStatus.NOT_FOUND,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
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) {
|
async findByUser(id: string, typeOfCoa: coaType) {
|
||||||
console.log('findbyuser', 'msk')
|
|
||||||
try {
|
try {
|
||||||
return await this.coaRepository.findOneOrFail({
|
return await this.coaRepository.findOneOrFail({
|
||||||
user: id,
|
user: id,
|
||||||
|
@ -73,7 +72,6 @@ export class CoaService {
|
||||||
|
|
||||||
async findByTwoUser(from: string, destination: string, typeOfCoa: coaType) {
|
async findByTwoUser(from: string, destination: string, typeOfCoa: coaType) {
|
||||||
try {
|
try {
|
||||||
console.log('findbytwouser', 'msk')
|
|
||||||
return await this.coaRepository.findOneOrFail({
|
return await this.coaRepository.findOneOrFail({
|
||||||
user: from,
|
user: from,
|
||||||
relatedUser: destination,
|
relatedUser: destination,
|
||||||
|
@ -122,10 +120,8 @@ export class CoaService {
|
||||||
|
|
||||||
async findByName(name: string) {
|
async findByName(name: string) {
|
||||||
try {
|
try {
|
||||||
console.log('coaname', name);
|
|
||||||
return await this.coaRepository.findOneOrFail({ name: name });
|
return await this.coaRepository.findOneOrFail({ name: name });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('coaerror', e);
|
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
throw new HttpException(
|
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';
|
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||||
|
|
||||||
export class OrderTransactionDto {
|
export class OrderTransactionDto {
|
||||||
|
|
||||||
@IsNotEmpty()
|
|
||||||
productId: string;
|
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
productCode: string;
|
productCode: string;
|
||||||
|
|
||||||
|
@ -13,7 +9,4 @@ export class OrderTransactionDto {
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
trx_id: string;
|
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()
|
@Column()
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
@Column()
|
|
||||||
balance_remaining: number;
|
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
status: statusTransaction;
|
status: statusTransaction;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
type: typeTransaction;
|
type: typeTransaction;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
check_bill: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'uuid',
|
type: 'uuid',
|
||||||
nullable: true,
|
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 {
|
import { Controller, Get, HttpStatus, Logger, Req } from '@nestjs/common';
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Logger, Post,
|
|
||||||
Req,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { TransactionService } from './transaction.service';
|
import { TransactionService } from './transaction.service';
|
||||||
import { FastifyRequest } from 'fastify';
|
import { FastifyRequest } from 'fastify';
|
||||||
import { Public } from '../auth/public.decorator';
|
import { Public } from '../auth/public.decorator';
|
||||||
import { EntityNotFoundError } from 'typeorm';
|
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'ppob_callback',
|
path: 'ppob_callback',
|
||||||
|
@ -27,179 +19,26 @@ export class PpobCallbackController {
|
||||||
|
|
||||||
if (response['statuscode'] == 2) {
|
if (response['statuscode'] == 2) {
|
||||||
//TODO: UPDATE GAGAL
|
//TODO: UPDATE GAGAL
|
||||||
await this.transactionService.checkCallbackOrderFailed(
|
const updateTransaction =
|
||||||
response['clientid'],
|
await this.transactionService.callbackOrderFailed(
|
||||||
response,
|
response['clientid'],
|
||||||
);
|
|
||||||
} 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'],
|
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log('masuksukseshemat', 'msk')
|
|
||||||
//TODO: UPDATE BERHASIL
|
//TODO: UPDATE BERHASIL
|
||||||
await this.transactionService.checkCallbackOrderSuccess(
|
const updateTransaction =
|
||||||
response['data']['idtransaction'],
|
await this.transactionService.callbackOrderSuccess(
|
||||||
|
response['clientid'],
|
||||||
response,
|
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 {
|
import { Body, Controller, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Header,
|
|
||||||
HttpStatus,
|
|
||||||
Param,
|
|
||||||
ParseUUIDPipe,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Query,
|
|
||||||
Request, Res
|
|
||||||
} 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';
|
||||||
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
||||||
import { DepositReturnDto } from './dto/deposit_return.dto';
|
import { DepositReturnDto } from './dto/deposit_return.dto';
|
||||||
import { ExportTransactionDto } from './dto/export-transaction.dto';
|
|
||||||
|
|
||||||
@Controller({
|
@Controller({
|
||||||
path: 'transaction',
|
path: 'transaction',
|
||||||
|
@ -89,50 +76,9 @@ export class TransactionController {
|
||||||
async orderTransactionProd(
|
async orderTransactionProd(
|
||||||
@Body() orderTransactionDto: OrderTransactionDto,
|
@Body() orderTransactionDto: OrderTransactionDto,
|
||||||
@Request() req,
|
@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 {
|
return {
|
||||||
data: await this.transactionService.orderTransactionBillProd(
|
data: await this.transactionService.orderTransactionProd(
|
||||||
orderTransactionDto,
|
|
||||||
req.user,
|
|
||||||
),
|
|
||||||
statusCode: HttpStatus.CREATED,
|
|
||||||
message: 'success',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('check-bill')
|
|
||||||
async checkBill(
|
|
||||||
@Body() orderTransactionDto: OrderTransactionDto,
|
|
||||||
@Request() req,
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
data: await this.transactionService.checkBill(
|
|
||||||
orderTransactionDto,
|
orderTransactionDto,
|
||||||
req.user,
|
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')
|
@Get('history')
|
||||||
async getHistoryTransactionUser(
|
async getHistoryTransactionUser(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('pageSize') pageSize: number,
|
@Query('pageSize') pageSize: number,
|
||||||
@Query('start') startDate: string,
|
@Query('start') startDate: string,
|
||||||
@Query('end') endDate: string,
|
@Query('end') endDate: string,
|
||||||
@Query('trxId') trxId: string,
|
|
||||||
@Query('partnerTrxId') partnerTrxId: string,
|
|
||||||
@Request() req,
|
@Request() req,
|
||||||
) {
|
) {
|
||||||
const data = await this.transactionService.transactionHistoryByUser(
|
const data = await this.transactionService.transactionHistoryByUser(
|
||||||
|
@ -205,8 +115,6 @@ export class TransactionController {
|
||||||
req.user.userId,
|
req.user.userId,
|
||||||
startDate == 'null' ? null : startDate,
|
startDate == 'null' ? null : startDate,
|
||||||
endDate == 'null' ? null : endDate,
|
endDate == 'null' ? null : endDate,
|
||||||
trxId == 'null' ? null : trxId,
|
|
||||||
partnerTrxId == 'null' ? null : partnerTrxId,
|
|
||||||
pageSize,
|
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')
|
@Get('history-user/:id')
|
||||||
async getHistoryTransactionUserByParam(
|
async getHistoryTransactionUserByParam(
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('pageSize') pageSize: number,
|
@Query('pageSize') pageSize: number,
|
||||||
@Query('start') startDate: string,
|
@Query('start') startDate: string,
|
||||||
@Query('end') endDate: string,
|
@Query('end') endDate: string,
|
||||||
@Query('trxId') trxId: string,
|
|
||||||
@Query('partnerTrxId') partnerTrxId: string,
|
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
) {
|
) {
|
||||||
const data = await this.transactionService.transactionHistoryByUser(
|
const data = await this.transactionService.transactionHistoryByUser(
|
||||||
|
@ -253,8 +138,6 @@ export class TransactionController {
|
||||||
id,
|
id,
|
||||||
startDate == 'null' ? null : startDate,
|
startDate == 'null' ? null : startDate,
|
||||||
endDate == 'null' ? null : endDate,
|
endDate == 'null' ? null : endDate,
|
||||||
trxId == 'null' ? null : trxId,
|
|
||||||
partnerTrxId == 'null' ? null : partnerTrxId,
|
|
||||||
pageSize,
|
pageSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -276,29 +159,6 @@ export class TransactionController {
|
||||||
page,
|
page,
|
||||||
req.user.userId,
|
req.user.userId,
|
||||||
userDestination,
|
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,
|
pageSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -10,32 +10,15 @@ import { CoaService } from './coa.service';
|
||||||
import { ProductModule } from '../product/product.module';
|
import { ProductModule } from '../product/product.module';
|
||||||
import { UsersModule } from 'src/users/users.module';
|
import { UsersModule } from 'src/users/users.module';
|
||||||
import { ConfigurableModule } from '../configurable/configurable.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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([
|
TypeOrmModule.forFeature([COA, TransactionJournal, Transactions]),
|
||||||
COA,
|
|
||||||
TransactionJournal,
|
|
||||||
Transactions,
|
|
||||||
CheckBillHistory,
|
|
||||||
CallbackPartner,
|
|
||||||
ProductHistoryPrice,
|
|
||||||
ProductHistoryStatus,
|
|
||||||
ProductSubCategories
|
|
||||||
]),
|
|
||||||
ProductModule,
|
ProductModule,
|
||||||
ConfigurableModule,
|
ConfigurableModule,
|
||||||
forwardRef(() => {
|
forwardRef(() => UsersModule),
|
||||||
return UsersModule;
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
controllers: [TransactionController, PpobCallbackController, ExcelController],
|
controllers: [TransactionController, PpobCallbackController],
|
||||||
providers: [TransactionService, CoaService],
|
providers: [TransactionService, CoaService],
|
||||||
exports: [CoaService],
|
exports: [CoaService],
|
||||||
})
|
})
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,19 +6,4 @@ export class CreateSupplierDto {
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
code: string;
|
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 })
|
@Column({ default: true })
|
||||||
status: boolean;
|
status: boolean;
|
||||||
|
|
||||||
@Column({
|
|
||||||
default: '',
|
|
||||||
})
|
|
||||||
callback_url: string;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,31 +16,6 @@ export class Supplier extends BaseModel {
|
||||||
@Column()
|
@Column()
|
||||||
status: boolean;
|
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: COA;
|
||||||
|
|
||||||
coa_undistribute: COA;
|
coa_undistribute: COA;
|
||||||
|
|
|
@ -22,7 +22,7 @@ export class SupplierService {
|
||||||
)
|
)
|
||||||
private coaService: CoaService,
|
private coaService: CoaService,
|
||||||
private connection: Connection,
|
private connection: Connection,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
async create(createSupplierDto: CreateSupplierDto) {
|
async create(createSupplierDto: CreateSupplierDto) {
|
||||||
const check = await this.supplierRepository.findOne({
|
const check = await this.supplierRepository.findOne({
|
||||||
|
@ -43,11 +43,6 @@ export class SupplierService {
|
||||||
supplierData.id = uuid.v4();
|
supplierData.id = uuid.v4();
|
||||||
supplierData.name = createSupplierDto.name;
|
supplierData.name = createSupplierDto.name;
|
||||||
supplierData.code = createSupplierDto.code;
|
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;
|
supplierData.status = false;
|
||||||
|
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
|
@ -104,11 +99,6 @@ export class SupplierService {
|
||||||
const supplierData = new Supplier();
|
const supplierData = new Supplier();
|
||||||
|
|
||||||
supplierData.name = updateSupplierDto.name;
|
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;
|
supplierData.status = true;
|
||||||
|
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
|
|
|
@ -20,15 +20,12 @@ 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';
|
import { mapSeries } from 'bluebird';
|
||||||
import { Partner } from './entities/partner.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
private usersRepository: Repository<User>,
|
private usersRepository: Repository<User>,
|
||||||
@InjectRepository(Partner)
|
|
||||||
private partnerRepository: Repository<Partner>,
|
|
||||||
@InjectRepository(UserDetail)
|
@InjectRepository(UserDetail)
|
||||||
private userDetailRepository: Repository<UserDetail>,
|
private userDetailRepository: Repository<UserDetail>,
|
||||||
@Inject(
|
@Inject(
|
||||||
|
@ -70,20 +67,14 @@ export class UsersService {
|
||||||
|
|
||||||
if (createUserDto.superior) {
|
if (createUserDto.superior) {
|
||||||
let approvalRole = '';
|
let approvalRole = '';
|
||||||
if (superior.superior) {
|
if(superior.roles.name == 'Sales'){
|
||||||
if(superior.roles.name == 'Sales'){
|
approvalRole = 'Supervisor';
|
||||||
approvalRole = 'Supervisor';
|
|
||||||
} else {
|
|
||||||
approvalRole = 'Admin';
|
|
||||||
}
|
|
||||||
|
|
||||||
userData.superior = superior;
|
|
||||||
userData.status_approval = superior.superior.id;
|
|
||||||
userData.is_active = false;
|
|
||||||
} else {
|
} else {
|
||||||
userData.superior = superior;
|
approvalRole = 'Admin';
|
||||||
userData.is_active = true;
|
|
||||||
}
|
}
|
||||||
|
userData.superior = superior;
|
||||||
|
userData.status_approval = superior.superior.id;
|
||||||
|
userData.is_active = false;
|
||||||
} else {
|
} else {
|
||||||
userData.superior = null;
|
userData.superior = null;
|
||||||
userData.partner = createUserDto.partner;
|
userData.partner = createUserDto.partner;
|
||||||
|
@ -366,7 +357,7 @@ export class UsersService {
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
relations: ['superior', 'roles', 'partner'],
|
relations: ['superior', 'roles'],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
@ -413,7 +404,6 @@ export class UsersService {
|
||||||
.leftJoinAndSelect('users.roles', 'roles')
|
.leftJoinAndSelect('users.roles', 'roles')
|
||||||
.leftJoinAndSelect('users.superior', 'superior')
|
.leftJoinAndSelect('users.superior', 'superior')
|
||||||
.leftJoinAndSelect('users.userDetail', 'userDetail')
|
.leftJoinAndSelect('users.userDetail', 'userDetail')
|
||||||
.leftJoinAndSelect('users.partner', 'partner')
|
|
||||||
.where('users.id = :id', {
|
.where('users.id = :id', {
|
||||||
id: id,
|
id: id,
|
||||||
})
|
})
|
||||||
|
@ -433,17 +423,8 @@ export class UsersService {
|
||||||
'userDetail.identity_number',
|
'userDetail.identity_number',
|
||||||
'userDetail.image_identity',
|
'userDetail.image_identity',
|
||||||
'userDetail.image_store',
|
'userDetail.image_store',
|
||||||
'partner.id',
|
|
||||||
'partner.name',
|
|
||||||
'partner.code',
|
|
||||||
'partner.npwp',
|
|
||||||
'partner.address',
|
|
||||||
'partner.phone_number',
|
|
||||||
'partner.callback_url'
|
|
||||||
|
|
||||||
])
|
])
|
||||||
.getOne();
|
.getOne();
|
||||||
console.log('coamsk11', 'coa')
|
|
||||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
||||||
let coaProfit;
|
let coaProfit;
|
||||||
|
|
||||||
|
@ -451,7 +432,6 @@ export class UsersService {
|
||||||
userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' &&
|
userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' &&
|
||||||
userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'
|
userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'
|
||||||
) {
|
) {
|
||||||
console.log('coamsk12', 'coa')
|
|
||||||
coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
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