Compare commits

...

31 Commits

Author SHA1 Message Date
Aswin Ashar Abdullah f4969a837c fix(SPG-595) Pemesanan - Penyesuaian flow booking 2024-07-10 17:37:43 +07:00
Firman Ramdhani 59cf933abc feat: fix export group
continuous-integration/drone/tag Build is passing Details
2024-07-09 19:28:11 +07:00
Firman Ramdhani 2f03f18d51 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development
continuous-integration/drone/tag Build is passing Details
2024-07-09 18:44:12 +07:00
Firman Ramdhani 12543ea00b feat: adjustment api get config report 2024-07-09 18:44:05 +07:00
irfan c9b55c3d91 Merge pull request 'fix/type-data' (#25) from fix/type-data into development
Reviewed-on: #25
2024-07-09 11:25:20 +00:00
shancheas 0d7951d5f0 ci: update env COUCHDB_CONFIG 2024-07-09 18:13:38 +07:00
shancheas 34909a30b0 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into fix/type-data 2024-07-09 17:53:37 +07:00
Aswin Ashar Abdullah 99847ce85b fix(SPG-593) Pemesanan - Update Pembayaran Pending - Tambahkan informasi pembayaran via dan no rekening 2024-07-09 17:52:46 +07:00
Aswin Ashar Abdullah 28dcac39f0 feat(SPG-405) DB Kode Diskon VIP 2024-07-09 17:52:04 +07:00
shancheas 6261592339 lint: update type data and lint 2024-07-09 17:47:15 +07:00
shancheas c87c852509 fix: update nano db configuration 2024-07-09 17:37:22 +07:00
shancheas 99261f37cd fix: change String type data to string 2024-07-09 17:20:10 +07:00
firmanr 56e7d25acd Merge pull request 'feat: fix filter boolean' (#24) from feat/report into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #24
2024-07-08 23:09:43 +00:00
Firman Ramdhani 66a5245e61 feat: fix filter boolean 2024-07-08 20:51:31 +07:00
aswin d149a15530 Merge pull request 'fix/transaction' (#23) from fix/transaction into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #23
2024-07-08 11:11:24 +00:00
firmanr 3f33ab6850 Merge pull request 'feat/report' (#22) from feat/report into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #22
2024-07-08 10:37:28 +00:00
Firman Ramdhani fa2bbbf5e2 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into feat/report 2024-07-08 17:36:08 +07:00
Firman Ramdhani be738bb49b feat: setup report transaction 2024-07-08 17:35:16 +07:00
firmanr edf8ab173d Merge pull request 'feat/report' (#21) from feat/report into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #21
2024-07-08 10:16:16 +00:00
Firman Ramdhani 7e50ef1bf8 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into feat/report 2024-07-08 17:14:04 +07:00
Firman Ramdhani 677732d511 feat: adjustment dto create export 2024-07-08 16:52:23 +07:00
irfan f023e01c6c docs: add formula calculation documentation 2024-07-08 09:46:48 +00:00
Firman Ramdhani 32ae6481e6 feat: get current applied bookmark 2024-07-08 16:22:55 +07:00
Firman Ramdhani 2038f0a74f feat: add condition on create bookmark 2024-07-08 13:43:22 +07:00
firmanr 1827cdb592 Merge pull request 'feat: set default file name on export' (#20) from feat/report into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #20
2024-07-08 05:48:47 +00:00
Firman Ramdhani a2e05b4d59 feat: set default file name on export 2024-07-08 12:48:28 +07:00
firmanr 94bb218d50 Merge pull request 'feat: set default file name on export' (#19) from feat/report into development
continuous-integration/drone/tag Build is failing Details
Reviewed-on: #19
2024-07-08 05:41:16 +00:00
Firman Ramdhani d48ac84244 feat: set default file name on export 2024-07-08 12:39:49 +07:00
firmanr 91a01a2857 Merge pull request 'feat/report' (#18) from feat/report into development
continuous-integration/drone/tag Build is passing Details
Reviewed-on: #18
2024-07-08 05:36:49 +00:00
Firman Ramdhani 313843591e Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into feat/report 2024-07-08 12:36:06 +07:00
Firman Ramdhani 36b48b9257 feat: set default file name on export 2024-07-08 12:35:42 +07:00
109 changed files with 1803 additions and 727 deletions

12
env/env.development vendored
View File

@ -6,6 +6,8 @@ JWT_REFRESH_EXPIRES="7d"
ENC_KEY="921c83f3b90c92dca4ba9b947f99b4c9" ENC_KEY="921c83f3b90c92dca4ba9b947f99b4c9"
IV="a671a96159e97a4f" IV="a671a96159e97a4f"
COUCHDB_CONFIG="http://root:password@172.10.10.2:5970"
DEFAULT_DB_HOST="postgres" DEFAULT_DB_HOST="postgres"
DEFAULT_DB_PORT="5432" DEFAULT_DB_PORT="5432"
DEFAULT_DB_USER="root" DEFAULT_DB_USER="root"
@ -16,4 +18,14 @@ ELASTIC_APM_ACTIVATE=true
ELASTIC_APM_SERVICE_NAME="Skyworld POS" ELASTIC_APM_SERVICE_NAME="Skyworld POS"
ELASTIC_APM_SERVER_URL="http://172.10.10.10:8200" ELASTIC_APM_SERVER_URL="http://172.10.10.10:8200"
CRON_MIDNIGHT="55 11 * * *"
CRON_EVERY_MINUTE="55 11 * * *"
CRON_EVERY_HOUR="0 * * * *"
MIDTRANS_URL=https://app.sandbox.midtrans.com
MIDTRANS_PRODUCTION=false
MIDTRANS_SERVER_KEY=SB-Mid-server-ITmSD6C0nXfIcmgi4TXm6J7i
MIDTRANS_CLIENT_KEY=SB-Mid-client-VFaU_cPL6kh2DKir
EXPORT_LIMIT_PARTITION=200 EXPORT_LIMIT_PARTITION=200
ASSETS="https://asset.sky.eigen.co.id/"

31
env/env.production vendored Normal file
View File

@ -0,0 +1,31 @@
PORT="3346"
JWT_SECRET="ftyYM4t4kjuj/0ixvIrS18gpdvBJw42NnW71GrFrEhcn0alQkkH7TQIHU5MFFJ1e"
JWT_EXPIRES="24h"
JWT_REFRESH_EXPIRES="7d"
ENC_KEY="921c83f3b90c92dca4ba9b947f99b4c9"
IV="a671a96159e97a4f"
COUCHDB_CONFIG="http://root:password@172.10.10.2:5970"
DEFAULT_DB_HOST="postgres"
DEFAULT_DB_PORT="5432"
DEFAULT_DB_USER="root"
DEFAULT_DB_PASS="password"
DEFAULT_DB_NAME="pos"
ELASTIC_APM_ACTIVATE=true
ELASTIC_APM_SERVICE_NAME="Skyworld POS"
ELASTIC_APM_SERVER_URL="http://172.10.10.10:8200"
CRON_MIDNIGHT="55 11 * * *"
CRON_EVERY_MINUTE="55 11 * * *"
CRON_EVERY_HOUR="0 * * * *"
MIDTRANS_URL=https://app.midtrans.com
MIDTRANS_PRODUCTION=true
MIDTRANS_SERVER_KEY=Mid-server-6lA4Nnmov2BSOcwVq1sLSOpC
MIDTRANS_CLIENT_KEY=Mid-client-JiPIkIPd_RGooF8U
EXPORT_LIMIT_PARTITION=200
ASSETS="https://asset.sky.eigen.co.id/"

42
formula-readme.md Normal file
View File

@ -0,0 +1,42 @@
## Formula Calculation
### Instalation
```
yarn add mathjs algebra.js
```
### Example
```ts
import * as math from 'mathjs'
import { Equation, parse } from 'algebra.js'
const formula = 'dpp - (dpp*ppn) - (dpp*retribusi) - (dpp*service) - (dpp*ppn3)'
const total = '300000'
const variable = {
ppn: 11,
retribusi: 5000,
service: 5,
ppn3: 5000
}
try {
const x1 = math.simplify(formula, variable).toString()
console.log('Formula ', x1)
const dppFormula = parse(x1)
const totalFormula = parse(total)
const equation = new Equation(totalFormula, dppFormula)
console.log(equation.toString())
const result = equation.solveFor('dpp').toString()
console.log(result)
const value = math.evaluate(result)
console.log(value)
} catch (e) {
console.log(e)
}
```

View File

@ -37,6 +37,7 @@
"@nestjs/schedule": "^4.1.0", "@nestjs/schedule": "^4.1.0",
"@nestjs/swagger": "^7.3.1", "@nestjs/swagger": "^7.3.1",
"@nestjs/typeorm": "^10.0.2", "@nestjs/typeorm": "^10.0.2",
"algebra.js": "^0.2.6",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
@ -44,6 +45,8 @@
"elastic-apm-node": "^4.5.4", "elastic-apm-node": "^4.5.4",
"exceljs": "^4.4.0", "exceljs": "^4.4.0",
"googleapis": "^140.0.0", "googleapis": "^140.0.0",
"mathjs": "^13.0.2",
"midtrans-client": "^1.3.1",
"moment": "^2.30.1", "moment": "^2.30.1",
"nano": "^10.1.3", "nano": "^10.1.3",
"pg": "^8.11.5", "pg": "^8.11.5",

View File

@ -54,6 +54,7 @@ import { ReportExportModule } from './modules/reports/report-export/report-expor
import { ReportBookmarkModel } from './modules/reports/shared/models/report-bookmark.model'; import { ReportBookmarkModel } from './modules/reports/shared/models/report-bookmark.model';
import { ExportReportHistoryModel } from './modules/reports/shared/models/export-report-history.model'; import { ExportReportHistoryModel } from './modules/reports/shared/models/export-report-history.model';
import { CronModule } from './modules/configuration/cron/cron.module'; import { CronModule } from './modules/configuration/cron/cron.module';
import { MidtransModule } from './modules/configuration/midtrans/midtrans.module';
@Module({ @Module({
imports: [ imports: [
@ -101,6 +102,7 @@ import { CronModule } from './modules/configuration/cron/cron.module';
CronModule, CronModule,
GoogleCalendarModule, GoogleCalendarModule,
LogModule, LogModule,
MidtransModule,
SessionModule, SessionModule,
// user // user

View File

@ -61,7 +61,7 @@ export class PrivilegeService {
} }
async privilegeConfiguration(): Promise<UserPrivilegeConfigurationEntity> { async privilegeConfiguration(): Promise<UserPrivilegeConfigurationEntity> {
const { module, menu, sub_menu, section } = this.moduleKey(); const { module, menu } = this.moduleKey();
return await this.repository.findOne({ return await this.repository.findOne({
select: ['id', 'view', 'create', 'edit', 'delete', 'cancel', 'confirm'], select: ['id', 'view', 'create', 'edit', 'delete', 'cancel', 'confirm'],
where: { where: {

View File

@ -25,7 +25,7 @@ export abstract class BaseBatchDeleteManager<Entity> extends BaseManager {
async process(): Promise<void> { async process(): Promise<void> {
let totalFailed = 0; let totalFailed = 0;
let totalSuccess = 0; let totalSuccess = 0;
let messages = []; const messages = [];
for (const id of this.dataIds) { for (const id of this.dataIds) {
try { try {

View File

@ -29,7 +29,7 @@ export abstract class BaseBatchUpdateStatusManager<Entity> extends BaseManager {
async process(): Promise<void> { async process(): Promise<void> {
let totalFailed = 0; let totalFailed = 0;
let totalSuccess = 0; let totalSuccess = 0;
let messages = []; const messages = [];
for (const id of this.dataIds) { for (const id of this.dataIds) {
try { try {

View File

@ -75,11 +75,21 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
if (!this.eventTopics.length) return; if (!this.eventTopics.length) return;
for (const topic of this.eventTopics) { for (const topic of this.eventTopics) {
let data;
if (!topic.data) {
data = await this.dataService.getOneByOptions({
where: {
id: this.result['id'],
},
relations: topic.relations,
});
}
this.eventBus.publishAll([ this.eventBus.publishAll([
new topic.topic({ new topic.topic({
id: this.result['id'], id: data?.['id'] ?? topic?.data?.['id'],
old: null, old: null,
data: topic.data, data: data ?? topic.data,
user: this.user, user: this.user,
description: '', description: '',
module: this.tableName, module: this.tableName,

View File

@ -4,9 +4,9 @@ import { BaseDataOrchestrator } from './base-data.orchestrator';
export abstract class BaseDataTransactionOrchestrator< export abstract class BaseDataTransactionOrchestrator<
Entity, Entity,
> extends BaseDataOrchestrator<Entity> { > extends BaseDataOrchestrator<Entity> {
abstract active(dataId: string): Promise<String>; abstract active(dataId: string): Promise<string>;
abstract confirm(dataId: string): Promise<String>; abstract confirm(dataId: string): Promise<string>;
abstract inactive(dataId: string): Promise<String>; abstract inactive(dataId: string): Promise<string>;
abstract batchConfirm(dataIds: string[]): Promise<BatchResult>; abstract batchConfirm(dataIds: string[]): Promise<BatchResult>;
abstract batchActive(dataIds: string[]): Promise<BatchResult>; abstract batchActive(dataIds: string[]): Promise<BatchResult>;
abstract batchInactive(dataIds: string[]): Promise<BatchResult>; abstract batchInactive(dataIds: string[]): Promise<BatchResult>;

View File

@ -3,6 +3,6 @@ import { BatchResult } from 'src/core/response/domain/ok-response.interface';
export abstract class BaseDataOrchestrator<Entity> { export abstract class BaseDataOrchestrator<Entity> {
abstract create(data: Entity): Promise<Entity>; abstract create(data: Entity): Promise<Entity>;
abstract update(dataId: string, data: Entity): Promise<Entity>; abstract update(dataId: string, data: Entity): Promise<Entity>;
abstract delete(dataId: string): Promise<String>; abstract delete(dataId: string): Promise<string>;
abstract batchDelete(dataIds: string[]): Promise<BatchResult>; abstract batchDelete(dataIds: string[]): Promise<BatchResult>;
} }

View File

@ -24,7 +24,7 @@ export interface validateRelations {
export interface columnUniques { export interface columnUniques {
column: string; column: string;
query?: Object; query?: any;
} }
export interface IEvent<Entity = any> { export interface IEvent<Entity = any> {

View File

@ -36,7 +36,7 @@ export class {{pascalCase name}}DataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -46,7 +46,7 @@ export class {{pascalCase name}}DataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -56,7 +56,7 @@ export class {{pascalCase name}}DataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -74,7 +74,7 @@ export class {{pascalCase name}}DataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -43,7 +43,7 @@ import {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -48,7 +48,7 @@ export class {{pascalCase name}}DataOrchestrator extends Base{{pascalCase orches
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}}); this.deleteManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}});
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -65,7 +65,7 @@ export class {{pascalCase name}}DataOrchestrator extends Base{{pascalCase orches
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}}); this.activeManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}});
await this.activeManager.execute(); await this.activeManager.execute();
@ -82,7 +82,7 @@ export class {{pascalCase name}}DataOrchestrator extends Base{{pascalCase orches
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}}); this.confirmManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}});
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -99,7 +99,7 @@ export class {{pascalCase name}}DataOrchestrator extends Base{{pascalCase orches
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService( this.inactiveManager.setService(
this.serviceData, this.serviceData,

View File

@ -36,7 +36,7 @@ export class {{pascalCase name}}DataOrchestrator extends Base{{pascalCase orches
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}}); this.deleteManager.setService(this.serviceData, TABLE_NAME.{{constantCase name}});
await this.deleteManager.execute(); await this.deleteManager.execute();

View File

@ -1,18 +1,29 @@
import { MigrationInterface, QueryRunner } from "typeorm"; import { MigrationInterface, QueryRunner } from 'typeorm';
export class UpdateTableTransaction1720436852936 implements MigrationInterface { export class UpdateTableTransaction1720436852936 implements MigrationInterface {
name = 'UpdateTableTransaction1720436852936' name = 'UpdateTableTransaction1720436852936';
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "transaction_taxes" ADD "tax_total_value" numeric`); await queryRunner.query(
await queryRunner.query(`ALTER TABLE "transaction_taxes" DROP COLUMN "taxt_value"`); `ALTER TABLE "transaction_taxes" ADD "tax_total_value" numeric`,
await queryRunner.query(`ALTER TABLE "transaction_taxes" ADD "taxt_value" numeric`); );
await queryRunner.query(
`ALTER TABLE "transaction_taxes" DROP COLUMN "taxt_value"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_taxes" ADD "taxt_value" numeric`,
);
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "transaction_taxes" DROP COLUMN "taxt_value"`); await queryRunner.query(
await queryRunner.query(`ALTER TABLE "transaction_taxes" ADD "taxt_value" character varying`); `ALTER TABLE "transaction_taxes" DROP COLUMN "taxt_value"`,
await queryRunner.query(`ALTER TABLE "transaction_taxes" DROP COLUMN "tax_total_value"`); );
await queryRunner.query(
`ALTER TABLE "transaction_taxes" ADD "taxt_value" character varying`,
);
await queryRunner.query(
`ALTER TABLE "transaction_taxes" DROP COLUMN "tax_total_value"`,
);
} }
} }

View File

@ -10,8 +10,6 @@ import { PaymentMethodType } from 'src/modules/transaction/payment-method/consta
@Controller('v1/constant') @Controller('v1/constant')
@Public(true) @Public(true)
export class ConstantController { export class ConstantController {
constructor() {}
@Get('master-data-status') @Get('master-data-status')
async masterDataStatus(): Promise<any> { async masterDataStatus(): Promise<any> {
return [STATUS.ACTIVE, STATUS.DRAFT, STATUS.INACTIVE]; return [STATUS.ACTIVE, STATUS.DRAFT, STATUS.INACTIVE];

View File

@ -1 +1 @@
export const DatabaseListen = ['transaction']; export const DatabaseListen = ['transaction', 'vip_code'];

View File

@ -37,6 +37,7 @@ import { TransactionDataService } from 'src/modules/transaction/transaction/data
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model'; import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model'; import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model'; import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
import { VipCodeCreatedHandler } from './domain/managers/vip-code.handler';
@Module({ @Module({
imports: [ imports: [
@ -59,6 +60,7 @@ import { TransactionItemModel } from 'src/modules/transaction/transaction/data/m
BookingDeletedEvent, BookingDeletedEvent,
PaymentMethodDeletedHandler, PaymentMethodDeletedHandler,
PaymentMethodUpdatedHandler, PaymentMethodUpdatedHandler,
VipCodeCreatedHandler,
VipCategoryDeletedHandler, VipCategoryDeletedHandler,
VipCategoryUpdatedHandler, VipCategoryUpdatedHandler,
SeasonPeriodDeletedHandler, SeasonPeriodDeletedHandler,

View File

@ -1,21 +1,32 @@
import { Injectable } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { DatabaseListen } from '../../constants'; import { DatabaseListen } from '../../constants';
import { EventBus } from '@nestjs/cqrs'; import { EventBus } from '@nestjs/cqrs';
import { ChangeDocEvent } from '../../domain/events/change-doc.event'; import { ChangeDocEvent } from '../../domain/events/change-doc.event';
import { ConfigService } from '@nestjs/config';
import * as Nano from 'nano';
@Injectable() @Injectable()
export class CouchService { export class CouchService {
constructor(private eventBus: EventBus) {} constructor(
private eventBus: EventBus,
private configService: ConfigService,
) {}
get nanoInstance() {
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
return Nano(couchConfiguration);
}
async onModuleInit() { async onModuleInit() {
const nano = require('nano')('http://root:password@172.10.10.2:5970'); const nano = this.nanoInstance;
for (const database of DatabaseListen) { for (const database of DatabaseListen) {
const db = nano.db.use(database); const db = nano.db.use(database);
db.changesReader.start({ includeDocs: true }).on('change', (change) => { db.changesReader.start({ includeDocs: true }).on('change', (change) => {
this.changeDoc(change, database); this.changeDoc(change, database);
}); });
console.log(`start listen database ${database}`); Logger.log(`start listen database ${database}`, 'CouchService');
} }
} }
@ -31,7 +42,7 @@ export class CouchService {
public async createDoc(data, database) { public async createDoc(data, database) {
try { try {
const nano = require('nano')('http://root:password@172.10.10.2:5970'); const nano = this.nanoInstance;
const db = nano.use(database); const db = nano.use(database);
return await db.insert(data); return await db.insert(data);
} catch (error) {} } catch (error) {}
@ -39,7 +50,7 @@ export class CouchService {
public async deleteDoc(data, database) { public async deleteDoc(data, database) {
try { try {
const nano = require('nano')('http://root:password@172.10.10.2:5970'); const nano = this.nanoInstance;
const db = nano.use(database); const db = nano.use(database);
const result = await db.get(data.id); const result = await db.get(data.id);
await db.destroy(data.id, result._rev); await db.destroy(data.id, result._rev);
@ -48,7 +59,7 @@ export class CouchService {
public async updateDoc(data, database) { public async updateDoc(data, database) {
try { try {
const nano = require('nano')('http://root:password@172.10.10.2:5970'); const nano = this.nanoInstance;
const db = nano.use(database); const db = nano.use(database);
const result = await db.get(data.id); const result = await db.get(data.id);
console.log(result, 'dsa'); console.log(result, 'dsa');

View File

@ -0,0 +1,22 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { CouchService } from '../../data/services/couch.service';
import { VipCodeCreatedEvent } from 'src/modules/transaction/vip-code/domain/entities/event/vip-code-created.event';
@EventsHandler(VipCodeCreatedEvent)
export class VipCodeCreatedHandler
implements IEventHandler<VipCodeCreatedEvent>
{
constructor(private couchService: CouchService) {}
async handle(event: VipCodeCreatedEvent) {
const data = event.data.data;
await this.couchService.createDoc(
{
_id: data.id,
...data,
},
'vip_code',
);
}
}

View File

@ -1,19 +1,28 @@
import { Body, Controller, Get, Post } from '@nestjs/common'; import { Body, Controller, Get, Injectable, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger'; import { ApiTags } from '@nestjs/swagger';
import { Unprotected } from 'src/core/guards'; import { Public } from 'src/core/guards';
import * as Nano from 'nano'; import * as Nano from 'nano';
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto'; import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
import { ConfigService } from '@nestjs/config';
@ApiTags(`couch`) @ApiTags(`couch`)
@Controller('v1/couch') @Controller('v1/couch')
@Unprotected() @Public()
@Injectable()
export class CouchDataController { export class CouchDataController {
constructor(private configService: ConfigService) {}
get nanoInstance() {
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
return Nano(couchConfiguration);
}
@Post() @Post()
async createDoc(@Body() entity: CreateUserPrivilegeDto) { async createDoc(@Body() entity: CreateUserPrivilegeDto) {
try { try {
let n = Nano('http://admin:secret@127.0.0.1:5984'); const n = this.nanoInstance;
let db = await n.db.create(entity.name); await n.db.create(entity.name);
} catch (error) { } catch (error) {
console.log(error, 'dsa'); console.log(error, 'dsa');
} }
@ -22,17 +31,17 @@ export class CouchDataController {
@Post('doc') @Post('doc')
async createDocs(@Body() entity: CreateUserPrivilegeDto) { async createDocs(@Body() entity: CreateUserPrivilegeDto) {
try { try {
const nano = require('nano')('http://admin:secret@127.0.0.1:5984'); const nano = this.nanoInstance;
const people = nano.db.use('string'); const people = nano.db.use('string');
console.log(await people.info()); console.log(await people.info(), entity);
const data = { // const data = {
id: '1212', // id: '1212',
name: 'dsadas', // name: 'dsadas',
}; // };
// await people.insert(data) // await people.insert(data)
people.changesReader people.changesReader
.start() .start({})
.on('change', (change) => { .on('change', (change) => {
console.log(change); console.log(change);
}) })
@ -53,9 +62,10 @@ export class CouchDataController {
@Get() @Get()
async getDoc() { async getDoc() {
try { try {
let n = Nano('http://admin:secret@127.0.0.1:5984'); const n = this.nanoInstance;
const people = n.use('string'); const people = n.db.get('user');
return people;
// return people.get(); // return people.get();
} catch (error) { } catch (error) {
console.log(error, 'dsa'); console.log(error, 'dsa');

View File

@ -1,3 +1,3 @@
export class CronMidnightEvent { export class CronMidnightEvent {
constructor(public readonly data: {}) {} // constructor(public readonly data: {}) {}
} }

View File

@ -16,6 +16,6 @@ export class MidnightCronManager {
console.log('Cron Event executed every 00:00 minutes.', now); console.log('Cron Event executed every 00:00 minutes.', now);
this.eventBus.publishAll([new CronMidnightEvent({})]); this.eventBus.publishAll([new CronMidnightEvent()]);
} }
} }

View File

@ -6,5 +6,7 @@ import { ErrorLogService } from '../../data/services/error-log.service';
export class RecordErrorLogHandler implements IEventHandler<RecordErrorLog> { export class RecordErrorLogHandler implements IEventHandler<RecordErrorLog> {
constructor(private dataservice: ErrorLogService) {} constructor(private dataservice: ErrorLogService) {}
async handle(event: RecordErrorLog) {} async handle(event: RecordErrorLog) {
// TODO: Implement logic here
}
} }

View File

@ -3,5 +3,7 @@ import { RecordLog } from '../entities/log.event';
@EventsHandler(RecordLog) @EventsHandler(RecordLog)
export class RecordLogHandler implements IEventHandler<RecordLog> { export class RecordLogHandler implements IEventHandler<RecordLog> {
async handle(event: RecordLog) {} async handle(event: RecordLog) {
// TODO: Implement logic here
}
} }

View File

@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import { EventBus } from '@nestjs/cqrs';
const midtransClient = require('midtrans-client');
@Injectable()
export class MidtransService {
constructor(private eventBus: EventBus) {}
get midtransInstance() {
return new midtransClient.Snap({
isProduction: false,
serverKey: process.env.MIDTRANS_SERVER_KEY,
clientKey: process.env.MIDTRANS_CLIENT_KEY,
});
}
async getStatus(orderId: string): Promise<any> {
return await this.midtransInstance.transaction.status(orderId);
}
async create(body): Promise<any> {
return await this.midtransInstance.createTransaction({
transaction_details: {
order_id: '123',
gross_amount: 10000,
},
credit_card: {
secure: true,
},
customer_details: {
first_name: 'budd',
last_name: 'pratama',
email: 'budi.pra@mail.com',
phone: '0822111111',
},
});
}
}

View File

@ -0,0 +1,8 @@
export class MidtransCallbackEvent {
constructor(public readonly data: IEventMidtrans) {}
}
export interface IEventMidtrans {
id: string;
data: any;
}

View File

@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
export class MidtransDto {
@ApiProperty({
type: String,
example: '123',
})
order_id: string;
}

View File

@ -0,0 +1,36 @@
import { Body, Controller, Get, Injectable, Param, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { MidtransService } from '../data/services/midtrans.service';
import { EventBus } from '@nestjs/cqrs';
import { MidtransCallbackEvent } from '../domain/entities/midtrans-callback.event';
import { MidtransDto } from './dto/midtrans.dto';
@ApiTags(`midtrans`)
@Controller('v1/midtrans')
@Public()
@Injectable()
export class MidtransController {
constructor(
private dataService: MidtransService,
private eventBus: EventBus,
) {}
@Get(':id/status')
async getStatus(@Param('id') id: string) {
return await this.dataService.getStatus(id);
}
@Post('callback')
async callback(@Body() callback: MidtransDto) {
const data = await this.dataService.getStatus(callback?.order_id);
this.eventBus.publishAll([
new MidtransCallbackEvent({
id: data.order_id,
data: data,
}),
]);
console.log(`midtrans callback for order ${data.order_id}`);
return 'success listen callback';
}
}

View File

@ -0,0 +1,20 @@
import { ConfigModule } from '@nestjs/config';
import { CqrsModule } from '@nestjs/cqrs';
import { MidtransController } from './infrastructure/midtrans.controller';
import { MidtransService } from './data/services/midtrans.service';
import { Module } from '@nestjs/common';
@Module({
imports: [
ConfigModule.forRoot(),
// TypeOrmModule.forFeature(
// [
// ],
// CONNECTION_NAME.DEFAULT,
// ),
CqrsModule,
],
controllers: [MidtransController],
providers: [MidtransService],
})
export class MidtransModule {}

View File

@ -49,7 +49,7 @@ export class ItemCategoryDataOrchestrator extends BaseDataTransactionOrchestrato
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY); this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -66,7 +66,7 @@ export class ItemCategoryDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY); this.activeManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
await this.activeManager.execute(); await this.activeManager.execute();
@ -83,7 +83,7 @@ export class ItemCategoryDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY); this.confirmManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -100,7 +100,7 @@ export class ItemCategoryDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY); this.inactiveManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -22,7 +22,9 @@ export class CreateItemCategoryManager extends BaseCreateManager<ItemCategoryEnt
return; return;
} }
async generateConfig(): Promise<void> {} async generateConfig(): Promise<void> {
// TODO: Implement logic here
}
get validateRelations(): validateRelations[] { get validateRelations(): validateRelations[] {
return []; return [];

View File

@ -34,7 +34,7 @@ export class ItemCategoryDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class ItemCategoryDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class ItemCategoryDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class ItemCategoryDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -36,7 +36,7 @@ export class ItemRateDataOrchestrator extends BaseDataOrchestrator<ItemRateEntit
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE); this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_RATE);
await this.deleteManager.execute(); await this.deleteManager.execute();

View File

@ -19,7 +19,7 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
async afterProcess(): Promise<void> { async afterProcess(): Promise<void> {
this.result.data?.map((item) => { this.result.data?.map((item) => {
let prices = []; const prices = [];
for ( for (
let d = new Date(this.filterParam.start_date); let d = new Date(this.filterParam.start_date);
d <= new Date(this.filterParam.end_date); d <= new Date(this.filterParam.end_date);

View File

@ -38,7 +38,7 @@ export class ItemRateDataController {
} }
// @Delete(':id') // @Delete(':id')
// async delete(@Param('id') dataId: string): Promise<String> { // async delete(@Param('id') dataId: string): Promise<string> {
// return await this.orchestrator.delete(dataId); // return await this.orchestrator.delete(dataId);
// } // }
} }

View File

@ -60,7 +60,7 @@ export class ItemDataOrchestrator extends BaseDataTransactionOrchestrator<ItemEn
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId, tenantId?: string): Promise<String> { async delete(dataId, tenantId?: string): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM); this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -77,7 +77,7 @@ export class ItemDataOrchestrator extends BaseDataTransactionOrchestrator<ItemEn
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId, tenantId?: string): Promise<String> { async active(dataId, tenantId?: string): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.ITEM); this.activeManager.setService(this.serviceData, TABLE_NAME.ITEM);
await this.activeManager.execute(); await this.activeManager.execute();
@ -94,7 +94,7 @@ export class ItemDataOrchestrator extends BaseDataTransactionOrchestrator<ItemEn
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId, tenantId?: string): Promise<String> { async confirm(dataId, tenantId?: string): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.ITEM); this.confirmManager.setService(this.serviceData, TABLE_NAME.ITEM);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -111,7 +111,7 @@ export class ItemDataOrchestrator extends BaseDataTransactionOrchestrator<ItemEn
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId, tenantId?: string): Promise<String> { async inactive(dataId, tenantId?: string): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.ITEM); this.inactiveManager.setService(this.serviceData, TABLE_NAME.ITEM);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -34,7 +34,7 @@ export class ItemDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class ItemDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class ItemDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class ItemDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -35,16 +35,21 @@ export class ReportBookmarkController {
return await this.service.getAll(query); return await this.service.getAll(query);
} }
@Get('id') // @Get(':id')
async get(@Param('id') id: string) { // async get(@Param('id') id: string) {
return await this.service.getOne(id); // return await this.service.getOne(id);
} // }
@Get('label-history') @Get('label-history')
async getAllLabelHistory(@Query() query: GetLabelReportBookmarkDto) { async getAllLabelHistory(@Query() query: GetLabelReportBookmarkDto) {
return await this.service.getAllLabelHistory(query); return await this.service.getAllLabelHistory(query);
} }
@Get('applied')
async currentApplied(@Query() query: GetLabelReportBookmarkDto) {
return await this.service.getCurrentAppliedBookmark(query);
}
@Put('applied/:id') @Put('applied/:id')
async applied(@Param('id') id: string) { async applied(@Param('id') id: string) {
return await this.service.applied(id); return await this.service.applied(id);

View File

@ -25,7 +25,11 @@ export class ReportBookmarkService extends BaseReportService {
async create(body: CreateReportBookmarkDto) { async create(body: CreateReportBookmarkDto) {
const newPayload = this.injectDefaultColumnCreate(body); const newPayload = this.injectDefaultColumnCreate(body);
return await this.repo.save(newPayload); const result = await this.repo.save(newPayload);
if (body.applied) {
await this.appliedFalseBookmark(result.id);
}
return result;
} }
async getAll(query: GetReportBookmarkDto) { async getAll(query: GetReportBookmarkDto) {
@ -92,6 +96,35 @@ export class ReportBookmarkService extends BaseReportService {
return newData.map((el) => el.ReportBookmarkModel_label); return newData.map((el) => el.ReportBookmarkModel_label);
} }
async getCurrentAppliedBookmark(query: GetLabelReportBookmarkDto) {
const modelName = ReportBookmarkModel.name;
const creator_id = this.getUser().id;
const unique_names = query.unique_names;
const group_names = query.group_names;
const types = query.types;
const qb = this.repo
.createQueryBuilder(modelName)
.where((query) => {
if (unique_names) {
query.andWhere(`unique_name IN (:...unique_names)`, { unique_names });
}
if (group_names) {
query.andWhere(`group_name IN (:...group_names)`, { group_names });
}
if (types) {
query.andWhere(`type IN (:...types)`, { types });
}
query.andWhere(`creator_id = :creator_id`, { creator_id });
query.andWhere(`applied = :applied`, { applied: true });
})
.orderBy(`${modelName}.created_at`, 'DESC');
return await qb.getMany();
}
async applied(id: string) { async applied(id: string) {
await this.repo await this.repo
.createQueryBuilder() .createQueryBuilder()

View File

@ -98,14 +98,15 @@ export class ReportExportService extends BaseReportService {
(_, i) => i * limit, (_, i) => i * limit,
); );
const fileName = `${fName ?? config.label} (${Number(new Date())})`; const defaultFileName = fName ?? config.label;
const fileName = `${defaultFileName} (${Number(new Date())})`;
const exportHistory = { const exportHistory = {
id: undefined, id: undefined,
group_name: config.group_name, group_name: config.group_name,
unique_name: config.unique_name, unique_name: config.unique_name,
label: config.label, label: config.label,
file_name: fName, file_name: defaultFileName,
file_url: null, file_url: null,
total_data: totalRow, total_data: totalRow,
processing_data: 0, processing_data: 0,
@ -143,7 +144,6 @@ export class ReportExportService extends BaseReportService {
// Create a new worksheet // Create a new worksheet
const reportSheet = workbook.addWorksheet('Report'); const reportSheet = workbook.addWorksheet('Report');
const columnStateIds = columnState.map((i) => i.colId);
let configColumns = config.column_configs; let configColumns = config.column_configs;
const rowGroups = query_model?.rowGroupCols ?? []; const rowGroups = query_model?.rowGroupCols ?? [];
@ -154,6 +154,11 @@ export class ReportExportService extends BaseReportService {
}); });
} }
const columnStateIds = [
...rowGroups.map((i) => i.id),
...columnState.map((i) => i.colId),
];
const newConfigColumn = columnStateIds const newConfigColumn = columnStateIds
.map((i) => { .map((i) => {
const findData = configColumns.find((col) => col.column === i); const findData = configColumns.find((col) => col.column === i);

View File

@ -4,11 +4,12 @@ import { ReportService } from './report.service';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { ExportReportHistoryModel } from '../shared/models/export-report-history.model'; import { ExportReportHistoryModel } from '../shared/models/export-report-history.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { ReportBookmarkModel } from '../shared/models/report-bookmark.model';
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature( TypeOrmModule.forFeature(
[ExportReportHistoryModel], [ExportReportHistoryModel, ReportBookmarkModel],
CONNECTION_NAME.DEFAULT, CONNECTION_NAME.DEFAULT,
), ),
], ],

View File

@ -3,13 +3,14 @@ import { BaseReportService } from '../shared/services/base-report.service';
import { GetReportConfigDto } from '../shared/dto/report-config.get.dto'; import { GetReportConfigDto } from '../shared/dto/report-config.get.dto';
import { GetReportDataDto } from '../shared/dto/report-data.get.dto'; import { GetReportDataDto } from '../shared/dto/report-data.get.dto';
import { ReportConfigs } from '../shared/configs'; import { ReportConfigs } from '../shared/configs';
import { InjectDataSource } from '@nestjs/typeorm'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { DataSource } from 'typeorm'; import { DataSource, Repository } from 'typeorm';
import { ReportConfigEntity } from '../shared/entities/report-config.entity'; import { ReportConfigEntity } from '../shared/entities/report-config.entity';
import { ReportQueryBuilder } from '../shared/helpers'; import { ReportQueryBuilder } from '../shared/helpers';
import { DATA_FORMAT } from '../shared/constant'; import { DATA_FORMAT, REPORT_BOOKMARK_TYPE } from '../shared/constant';
import { roundingCurrency } from '../shared/helpers'; import { roundingCurrency } from '../shared/helpers';
import { ReportBookmarkModel } from '../shared/models/report-bookmark.model';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class ReportService extends BaseReportService { export class ReportService extends BaseReportService {
@ -18,6 +19,9 @@ export class ReportService extends BaseReportService {
constructor( constructor(
@InjectDataSource(CONNECTION_NAME.DEFAULT) @InjectDataSource(CONNECTION_NAME.DEFAULT)
private dataSource: DataSource, private dataSource: DataSource,
@InjectRepository(ReportBookmarkModel, CONNECTION_NAME.DEFAULT)
private bookmarkRepo: Repository<ReportBookmarkModel>,
) { ) {
super(); super();
} }
@ -35,8 +39,47 @@ export class ReportService extends BaseReportService {
unique_names.includes(item.unique_name), unique_names.includes(item.unique_name),
); );
} }
const groups = Array.from(new Set(configs?.map((item) => item.group_name)));
const names = Array.from(new Set(configs?.map((item) => item.unique_name)));
return configs; const modelName = ReportBookmarkModel.name;
const creator_id = this.getUser().id;
const bookmarkConfigs = await this.bookmarkRepo
.createQueryBuilder(modelName)
.where((query) => {
if (names.length > 0) {
query.andWhere(`group_name IN (:...groups)`, { groups });
}
if (groups.length > 0) {
query.andWhere(`unique_name IN (:...names)`, { names });
}
query.andWhere(`creator_id = :creator_id`, { creator_id });
query.andWhere(`applied = :applied`, { applied: true });
})
.getMany();
return configs.map((item) => {
const active_filter = bookmarkConfigs.find(
(conf) =>
conf.group_name === item.group_name &&
conf.unique_name === item.unique_name &&
conf.type === REPORT_BOOKMARK_TYPE.FILTER_TABLE,
);
const active_table_config = bookmarkConfigs.find(
(conf) =>
conf.group_name === item.group_name &&
conf.unique_name === item.unique_name &&
conf.type === REPORT_BOOKMARK_TYPE.TABLE_CONFIG,
);
return {
...item,
active_filter: active_filter ?? {},
active_table_config: active_table_config ?? {},
};
});
} }
getReportConfigByUniqueName(group_name, unique_name): ReportConfigEntity { getReportConfigByUniqueName(group_name, unique_name): ReportConfigEntity {

View File

@ -1,5 +0,0 @@
import { ReportConfigEntity } from '../../entities/report-config.entity';
import SampleReport from './configs/sample.report';
export const GeneralReportConfig: ReportConfigEntity[] = [SampleReport];

View File

@ -1,8 +1,8 @@
import { ReportConfigEntity } from '../entities/report-config.entity'; import { ReportConfigEntity } from '../entities/report-config.entity';
import { GeneralReportConfig } from './general-report'; import { TransactionReportConfig } from './transaction-report';
import { TenantReportConfig } from './tenant-report'; import { TenantReportConfig } from './tenant-report';
export const ReportConfigs: ReportConfigEntity[] = [ export const ReportConfigs: ReportConfigEntity[] = [
...GeneralReportConfig, ...TransactionReportConfig,
...TenantReportConfig, ...TenantReportConfig,
]; ];

View File

@ -4,7 +4,7 @@ import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{ export default <ReportConfigEntity>{
group_name: REPORT_GROUP.tenant_report, group_name: REPORT_GROUP.tenant_report,
unique_name: `${REPORT_GROUP.tenant_report}__sample`, unique_name: `${REPORT_GROUP.tenant_report}__sample`,
label: 'Sample Tenant Report ', label: 'Sample Tenant Report',
table_schema: 'season_types main', table_schema: 'season_types main',
main_table_alias: 'main', main_table_alias: 'main',
defaultOrderBy: [], defaultOrderBy: [],

View File

@ -2,9 +2,9 @@ import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity'; import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{ export default <ReportConfigEntity>{
group_name: REPORT_GROUP.general_report, group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.general_report}__sample`, unique_name: `${REPORT_GROUP.transaction_report}__booking`,
label: 'Sample General Report ', label: 'Pemesanan',
table_schema: 'season_types main', table_schema: 'season_types main',
main_table_alias: 'main', main_table_alias: 'main',
defaultOrderBy: [], defaultOrderBy: [],

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__cash_withdrawals`,
label: 'Penarikan Kas',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__cashier_log`,
label: 'Kasir Log',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,67 @@
import {
DATA_FORMAT,
DATA_TYPE,
FILTER_FIELD_TYPE,
FILTER_TYPE,
REPORT_GROUP,
} from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__income`,
label: 'Pendapatan',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [
{
filed_label: 'Name',
filter_column: 'main__name',
field_type: FILTER_FIELD_TYPE.select,
filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
select_data_source_url: '/v1/season-types',
select_custom_options: [],
select_label_key: 'name',
select_value_key: 'name',
},
{
filed_label: 'Status',
filter_column: 'main__status',
field_type: FILTER_FIELD_TYPE.input_text,
filter_type: FILTER_TYPE.TEXT_EQUAL,
// select_data_source_url: '/v1/season-types',
// select_custom_options: [],
// select_label_key: 'code',
// select_value_key: 'code',
},
],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__refunds`,
label: 'Pengembalian',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__revenue_per_item`,
label: 'Pendapatan per Item',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__sales_qty_per_item`,
label: 'Qty Penjualan per Item',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__time_per_ride`,
label: 'Waktu per Wahana',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,40 @@
import { DATA_FORMAT, DATA_TYPE, REPORT_GROUP } from '../../../constant';
import { ReportConfigEntity } from '../../../entities/report-config.entity';
export default <ReportConfigEntity>{
group_name: REPORT_GROUP.transaction_report,
unique_name: `${REPORT_GROUP.transaction_report}__visitors_per_ride`,
label: 'Pengunjung per Wahana',
table_schema: 'season_types main',
main_table_alias: 'main',
defaultOrderBy: [],
lowLevelOrderBy: [],
filter_period_config: {
hidden: true,
},
column_configs: [
{
column: 'main__created_at',
query: 'main.created_at',
label: 'Created Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__updated_at',
query: 'main.updated_at',
label: 'Updated Date',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.DATE_EPOCH,
},
{
column: 'main__name',
query: 'main.name',
label: 'Name',
type: DATA_TYPE.DIMENSION,
format: DATA_FORMAT.TEXT,
},
],
filter_configs: [],
};

View File

@ -0,0 +1,23 @@
import { ReportConfigEntity } from '../../entities/report-config.entity';
import IncomeReport from './configs/income';
import RevenuePerItemReport from './configs/revenue-per-item';
import SalesQtyPerItemReport from './configs/sales-qty-per-item';
import VisitorsPerRideReport from './configs/visitors-per-ride';
import TimePerRideReport from './configs/time-per-ride';
import BookingReport from './configs/booking';
import RefundsReport from './configs/refunds';
import CashierLogReport from './configs/cashier-log';
import CashWithdrawalsReport from './configs/cash-withdrawals';
export const TransactionReportConfig: ReportConfigEntity[] = [
IncomeReport,
RevenuePerItemReport,
SalesQtyPerItemReport,
VisitorsPerRideReport,
TimePerRideReport,
BookingReport,
RefundsReport,
CashierLogReport,
CashWithdrawalsReport,
];

View File

@ -1,6 +1,6 @@
export enum REPORT_GROUP { export enum REPORT_GROUP {
// PATTERN => MODULE__MENU__SUB_MENU // PATTERN => MODULE__MENU__SUB_MENU
// EXAMPLE: // EXAMPLE:
general_report = 'general_report', transaction_report = 'transaction_report',
tenant_report = 'tenant_report', tenant_report = 'tenant_report',
} }

View File

@ -7,7 +7,7 @@ export class GetReportDataDto {
@ApiProperty({ @ApiProperty({
name: 'group_name', name: 'group_name',
required: true, required: true,
default: REPORT_GROUP.general_report, default: REPORT_GROUP.transaction_report,
}) })
@IsString() @IsString()
group_name: string; group_name: string;
@ -15,7 +15,7 @@ export class GetReportDataDto {
@ApiProperty({ @ApiProperty({
name: 'unique_name', name: 'unique_name',
required: true, required: true,
default: `${REPORT_GROUP.general_report}__sample`, default: `${REPORT_GROUP.transaction_report}__sample`,
}) })
@IsString() @IsString()
unique_name: string; unique_name: string;

View File

@ -8,8 +8,9 @@ export class CreateReportExportDto extends GetReportDataDto {
@IsString() @IsString()
time_zone: string; time_zone: string;
@ApiProperty({ name: 'file_name', required: true }) @ApiProperty({ name: 'file_name', required: false })
@IsString() @IsString()
@IsOptional()
file_name?: string; file_name?: string;
@ApiProperty({ @ApiProperty({

View File

@ -360,8 +360,10 @@ export class ReportQueryBuilder {
}); });
} }
const tableWhereConditions = [...whereCondition, ...whereParts]; const tableWhereConditions = [...whereCondition, ...whereParts].filter(
const defaultWhereConditions = defaultWhereOptions; Boolean,
);
const defaultWhereConditions = defaultWhereOptions.filter(Boolean);
if (tableWhereConditions.length > 0) { if (tableWhereConditions.length > 0) {
return `WHERE (${ return `WHERE (${

View File

@ -21,7 +21,7 @@ export async function ValidateSeasonPeriodHelper(dataService, data) {
=> akan tetapi dapat ditindih oleh season period 2024-08-15, 2024-08-28 days [Sabtu, Senin] (karena ini naik prio menjadi priority 2) => akan tetapi dapat ditindih oleh season period 2024-08-15, 2024-08-28 days [Sabtu, Senin] (karena ini naik prio menjadi priority 2)
*/ */
const query = dataService.getRepository().createQueryBuilder('data'); const query = dataService.getRepository().createQueryBuilder('data');
let priority: number = 3; let priority = 3;
// libur / specific date // libur / specific date
if ( if (
data.holidays?.length > 0 || data.holidays?.length > 0 ||

View File

@ -60,7 +60,7 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
return this.updatePriceManager.getResult(); return this.updatePriceManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD); this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -77,7 +77,7 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD); this.activeManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
await this.activeManager.execute(); await this.activeManager.execute();
@ -94,7 +94,7 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD); this.confirmManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -111,7 +111,7 @@ export class SeasonPeriodDataOrchestrator extends BaseDataTransactionOrchestrato
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD); this.inactiveManager.setService(this.serviceData, TABLE_NAME.SEASON_PERIOD);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -44,7 +44,7 @@ export class SeasonPeriodDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -54,7 +54,7 @@ export class SeasonPeriodDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -64,7 +64,7 @@ export class SeasonPeriodDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -91,7 +91,7 @@ export class SeasonPeriodDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -1,3 +1,3 @@
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export interface FilterSeasonTypeEntity extends BaseFilterEntity {} export type FilterSeasonTypeEntity = BaseFilterEntity;

View File

@ -48,7 +48,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE); this.deleteManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -65,7 +65,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE); this.activeManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
await this.activeManager.execute(); await this.activeManager.execute();
@ -82,7 +82,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE); this.confirmManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -99,7 +99,7 @@ export class SeasonTypeDataOrchestrator extends BaseDataTransactionOrchestrator<
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE); this.inactiveManager.setService(this.serviceData, TABLE_NAME.SEASON_TYPE);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -34,7 +34,7 @@ export class SeasonTypeDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class SeasonTypeDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class SeasonTypeDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class SeasonTypeDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -48,7 +48,7 @@ export class PaymentMethodDataOrchestrator extends BaseDataTransactionOrchestrat
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD); this.deleteManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -65,7 +65,7 @@ export class PaymentMethodDataOrchestrator extends BaseDataTransactionOrchestrat
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD); this.activeManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD);
await this.activeManager.execute(); await this.activeManager.execute();
@ -82,7 +82,7 @@ export class PaymentMethodDataOrchestrator extends BaseDataTransactionOrchestrat
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD); this.confirmManager.setService(this.serviceData, TABLE_NAME.PAYMENT_METHOD);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -99,7 +99,7 @@ export class PaymentMethodDataOrchestrator extends BaseDataTransactionOrchestrat
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService( this.inactiveManager.setService(
this.serviceData, this.serviceData,

View File

@ -34,7 +34,7 @@ export class PaymentMethodDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class PaymentMethodDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class PaymentMethodDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class PaymentMethodDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -11,7 +11,7 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class BatchConfirmReconciliationManager extends BaseBatchUpdateStatusManager<TransactionEntity> { export class BatchConfirmReconciliationManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
validateData(data: TransactionEntity): Promise<void> { async validateData(data: TransactionEntity): Promise<void> {
const net_profit = data.reconciliation_mdr const net_profit = data.reconciliation_mdr
? Number(this.data.payment_total) - Number(this.data.reconciliation_mdr) ? Number(this.data.payment_total) - Number(this.data.reconciliation_mdr)
: null; : null;

View File

@ -45,6 +45,7 @@ export class IndexReconciliationManager extends BaseIndexManager<TransactionEnti
`${this.tableName}.reconciliation_confirm_by`, `${this.tableName}.reconciliation_confirm_by`,
`${this.tableName}.customer_name`, `${this.tableName}.customer_name`,
`${this.tableName}.creator_counter_no`,
`${this.tableName}.payment_type`, `${this.tableName}.payment_type`,
`${this.tableName}.payment_type_method_id`, `${this.tableName}.payment_type_method_id`,

View File

@ -39,7 +39,7 @@ export class ReconciliationDataOrchestrator {
return this.recapManager.getResult(); return this.recapManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.CONFIRMED); this.confirmManager.setData(dataId, STATUS.CONFIRMED);
this.confirmManager.setService(this.serviceData, TABLE_NAME.TRANSACTION); this.confirmManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -56,7 +56,7 @@ export class ReconciliationDataOrchestrator {
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async cancel(dataId): Promise<String> { async cancel(dataId): Promise<string> {
this.cancelManager.setData(dataId, STATUS.REJECTED); this.cancelManager.setData(dataId, STATUS.REJECTED);
this.cancelManager.setService(this.serviceData, TABLE_NAME.TRANSACTION); this.cancelManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
await this.cancelManager.execute(); await this.cancelManager.execute();

View File

@ -34,12 +34,12 @@ export class ReconciliationDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@Patch(':id/cancel') @Patch(':id/cancel')
async cancel(@Param('id') dataId: string): Promise<String> { async cancel(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.cancel(dataId); return await this.orchestrator.cancel(dataId);
} }

View File

@ -19,6 +19,7 @@ import { BatchCancelReconciliationManager } from './domain/usecases/managers/bat
import { BatchConfirmReconciliationManager } from './domain/usecases/managers/batch-confirm-reconciliation.manager'; import { BatchConfirmReconciliationManager } from './domain/usecases/managers/batch-confirm-reconciliation.manager';
import { RecapReconciliationManager } from './domain/usecases/managers/recap-reconciliation.manager'; import { RecapReconciliationManager } from './domain/usecases/managers/recap-reconciliation.manager';
import { RecapPosTransactionHandler } from './domain/usecases/handlers/recap-pos-transaction.handler'; import { RecapPosTransactionHandler } from './domain/usecases/handlers/recap-pos-transaction.handler';
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
@Module({ @Module({
imports: [ imports: [

View File

@ -50,7 +50,7 @@ export class TaxDataOrchestrator extends BaseDataTransactionOrchestrator<TaxEnti
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService( this.deleteManager.setService(
this.serviceData, this.serviceData,
@ -72,7 +72,7 @@ export class TaxDataOrchestrator extends BaseDataTransactionOrchestrator<TaxEnti
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.TAX); this.activeManager.setService(this.serviceData, TABLE_NAME.TAX);
await this.activeManager.execute(); await this.activeManager.execute();
@ -86,7 +86,7 @@ export class TaxDataOrchestrator extends BaseDataTransactionOrchestrator<TaxEnti
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.TAX); this.confirmManager.setService(this.serviceData, TABLE_NAME.TAX);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -100,7 +100,7 @@ export class TaxDataOrchestrator extends BaseDataTransactionOrchestrator<TaxEnti
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService( this.inactiveManager.setService(
this.serviceData, this.serviceData,

View File

@ -34,7 +34,7 @@ export class TaxDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class TaxDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class TaxDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class TaxDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -0,0 +1,96 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { TransactionChangeStatusEvent } from '../../entities/event/transaction-change-status.event';
import { SalesPriceFormulaDataService } from 'src/modules/transaction/sales-price-formula/data/services/sales-price-formula-data.service';
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
import { FormulaType } from 'src/modules/transaction/sales-price-formula/constants';
import * as math from 'mathjs';
import { Equation, parse } from 'algebra.js';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { TransactionDataService } from '../../../data/services/transaction-data.service';
import { TransactionModel } from '../../../data/models/transaction.model';
@EventsHandler(TransactionChangeStatusEvent)
export class SettledTransactionHandler
implements IEventHandler<TransactionChangeStatusEvent>
{
constructor(
private formulaService: SalesPriceFormulaDataService,
private taxService: TaxDataService,
private dataService: TransactionDataService,
) {}
async handle(event: TransactionChangeStatusEvent) {
const old_data = event.data.old;
const data = event.data.data;
if (
old_data.status == data.status ||
![STATUS.ACTIVE, STATUS.SETTLED].includes(data.status)
)
return;
const profit_formula = await this.formulaService.getOneByOptions({
where: {
type: FormulaType.PROFIT_SHARE,
},
});
const sales_price = await this.formulaService.getOneByOptions({
where: {
type: FormulaType.SALES_PRICE,
},
});
const taxes = await this.taxService.getManyByOptions({
where: {
status: STATUS.ACTIVE,
},
});
const queryRunner = this.dataService
.getRepository()
.manager.connection.createQueryRunner();
// const profit_share_value = this.calculateFormula(profit_formula.formula_string, taxes, data.payment_total_net_profit ?? 0);
// const sale_price_value = this.calculateFormula(sales_price.formula_string, taxes, data.payment_total_net_profit ?? 0);
Object.assign(data, {
profit_share_formula: profit_formula.formula_string,
sales_price_formula: sales_price.formula_string,
});
await this.dataService.create(queryRunner, TransactionModel, data);
}
calculateFormula(formula, taxes, total) {
const regex = /([a-zA-Z0-9_]+)/g;
const variable = {};
const matches: string[] = formula.match(regex);
const uniqueMatches = new Set(matches);
const keys = Array.from(uniqueMatches).filter((key) => key != 'dpp');
for (const key of keys) {
const keyData = taxes.find((tax) => tax.name == key);
variable[key] = keyData.value / 100;
}
try {
const x1 = math.simplify(formula, variable).toString();
console.log('Formula ', x1);
const dppFormula = parse(x1);
const totalFormula = parse(total.toString());
const equation = new Equation(totalFormula, dppFormula);
console.log(equation.toString());
const result = equation.solveFor('dpp').toString();
console.log(result);
const value = math.evaluate(result);
console.log(value);
return value;
} catch (e) {
console.log(e);
}
}
}

View File

@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
EventTopics,
validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionChangeStatusEvent } from '../../entities/event/transaction-change-status.event';
@Injectable()
export class ActiveTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
getResult(): string {
return `Success active data ${this.result.invoice_code}`;
}
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async afterProcess(): Promise<void> {
return;
}
get validateRelations(): validateRelations[] {
return [];
}
get entityTarget(): any {
return TransactionModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: TransactionChangeStatusEvent,
data: this.data,
},
];
}
}

View File

@ -0,0 +1,45 @@
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
EventTopics,
validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionChangeStatusEvent } from '../../entities/event/transaction-change-status.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { Injectable } from '@nestjs/common';
@Injectable()
export class BatchActiveTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
validateData(data: TransactionEntity): Promise<void> {
return;
}
beforeProcess(): Promise<void> {
return;
}
afterProcess(): Promise<void> {
return;
}
get validateRelations(): validateRelations[] {
return [];
}
get entityTarget(): any {
return TransactionModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: TransactionChangeStatusEvent,
},
];
}
getResult(): BatchResult {
return this.result;
}
}

View File

@ -16,7 +16,7 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
@Injectable() @Injectable()
export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> { export class BatchConfirmTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
validateData(data: TransactionEntity): Promise<void> { async validateData(data: TransactionEntity): Promise<void> {
if (data.status != STATUS.DRAFT) { if (data.status != STATUS.DRAFT) {
throw new UnprocessableEntityException({ throw new UnprocessableEntityException({
statusCode: HttpStatus.UNPROCESSABLE_ENTITY, statusCode: HttpStatus.UNPROCESSABLE_ENTITY,

View File

@ -0,0 +1,45 @@
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
EventTopics,
validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionChangeStatusEvent } from '../../entities/event/transaction-change-status.event';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { Injectable } from '@nestjs/common';
@Injectable()
export class BatchInactiveTransactionManager extends BaseBatchUpdateStatusManager<TransactionEntity> {
validateData(data: TransactionEntity): Promise<void> {
return;
}
beforeProcess(): Promise<void> {
return;
}
afterProcess(): Promise<void> {
return;
}
get validateRelations(): validateRelations[] {
return [];
}
get entityTarget(): any {
return TransactionModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: TransactionChangeStatusEvent,
},
];
}
getResult(): BatchResult {
return this.result;
}
}

View File

@ -2,7 +2,7 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
import { TransactionType } from 'src/modules/transaction/transaction/constants'; import { TransactionType } from 'src/modules/transaction/transaction/constants';
export function mappingTransaction(data) { export function mappingTransaction(data) {
let payment_type_bank; let payment_type_bank: any = null;
const season_period = { const season_period = {
id: data.season_period_id, id: data.season_period_id,
holiday_name: data.season_period_name, holiday_name: data.season_period_name,
@ -12,7 +12,7 @@ export function mappingTransaction(data) {
}, },
}; };
if (data.payment_type_method_id) { if (data.payment_type_method_id || data.payment_type_method_name) {
payment_type_bank = { payment_type_bank = {
id: data.payment_type_method_id, id: data.payment_type_method_id,
issuer_name: data.payment_type_method_name, issuer_name: data.payment_type_method_name,
@ -93,12 +93,17 @@ export function mappingRevertTransaction(data, type) {
Object.assign(data, { Object.assign(data, {
type: type, type: type,
payment_total_net_profit: data.payment_total,
customer_category_id: data.customer_category?.id ?? null, customer_category_id: data.customer_category?.id ?? null,
customer_category_name: data.customer_category?.name ?? null, customer_category_name: data.customer_category?.name ?? null,
season_period_id: data.season_period?.id ?? null, season_period_id: data.season_period?.id ?? null,
season_period_name: data.season_period?.holiday_name ?? null, season_period_name: data.season_period?.holiday_name ?? null,
season_period_type_id: data.season_period?.season_type?.id ?? null, season_period_type_id: data.season_period?.season_type?.id ?? null,
season_period_type_name: data.season_period?.season_type?.name ?? null, season_period_type_name: data.season_period?.season_type?.name ?? null,
payment_type_method_id: data.payment_type_method?.id,
payment_type_method_number: data.payment_type_method?.account_number,
payment_type_method_name: data.payment_type_method?.issuer_name,
payment_type_method_qr: data.payment_type_method?.qr_image,
}); });
data.items?.map((item) => { data.items?.map((item) => {

View File

@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
import { TransactionEntity } from '../../entities/transaction.entity';
import {
EventTopics,
validateRelations,
} from 'src/core/strings/constants/interface.constants';
import { TransactionModel } from '../../../data/models/transaction.model';
import { TransactionChangeStatusEvent } from '../../entities/event/transaction-change-status.event';
@Injectable()
export class InactiveTransactionManager extends BaseUpdateStatusManager<TransactionEntity> {
getResult(): string {
return `Success inactive data ${this.result.invoice_code}`;
}
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async afterProcess(): Promise<void> {
return;
}
get validateRelations(): validateRelations[] {
return [];
}
get entityTarget(): any {
return TransactionModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: TransactionChangeStatusEvent,
data: this.data,
},
];
}
}

View File

@ -45,7 +45,7 @@ export class TransactionDataOrchestrator {
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.TRANSACTION); this.deleteManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -62,7 +62,7 @@ export class TransactionDataOrchestrator {
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async cancel(dataId): Promise<String> { async cancel(dataId): Promise<string> {
this.cancelManager.setData(dataId, STATUS.CANCEL); this.cancelManager.setData(dataId, STATUS.CANCEL);
this.cancelManager.setService(this.serviceData, TABLE_NAME.TRANSACTION); this.cancelManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
await this.cancelManager.execute(); await this.cancelManager.execute();
@ -79,7 +79,7 @@ export class TransactionDataOrchestrator {
return this.batchCancelManager.getResult(); return this.batchCancelManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.TRANSACTION); this.confirmManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -96,7 +96,7 @@ export class TransactionDataOrchestrator {
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async confirmData(dataId): Promise<String> { async confirmData(dataId): Promise<string> {
this.confirmDataManager.setData(dataId, STATUS.ACTIVE); this.confirmDataManager.setData(dataId, STATUS.ACTIVE);
this.confirmDataManager.setService( this.confirmDataManager.setService(
this.serviceData, this.serviceData,

View File

@ -34,7 +34,7 @@ export class TransactionDataController {
} }
@Patch(':id/confirm-data') @Patch(':id/confirm-data')
async confirmData(@Param('id') dataId: string): Promise<String> { async confirmData(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirmData(dataId); return await this.orchestrator.confirmData(dataId);
} }
@ -44,7 +44,7 @@ export class TransactionDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class TransactionDataController {
} }
@Patch(':id/cancel') @Patch(':id/cancel')
async cancel(@Param('id') dataId: string): Promise<String> { async cancel(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.cancel(dataId); return await this.orchestrator.cancel(dataId);
} }
@ -72,7 +72,7 @@ export class TransactionDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -29,6 +29,7 @@ import { TaxDataService } from '../tax/data/services/tax-data.service';
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service'; import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model'; import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model';
import { TaxModel } from '../tax/data/models/tax.model'; import { TaxModel } from '../tax/data/models/tax.model';
import { SettledTransactionHandler } from './domain/usecases/handlers/settled-transaction.handler';
@Module({ @Module({
imports: [ imports: [
@ -48,6 +49,7 @@ import { TaxModel } from '../tax/data/models/tax.model';
controllers: [TransactionDataController, TransactionReadController], controllers: [TransactionDataController, TransactionReadController],
providers: [ providers: [
PosTransactionHandler, PosTransactionHandler,
SettledTransactionHandler,
IndexTransactionManager, IndexTransactionManager,
DetailTransactionManager, DetailTransactionManager,

View File

@ -1,3 +1,3 @@
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export interface FilterVipCategoryEntity extends BaseFilterEntity {} export type FilterVipCategoryEntity = BaseFilterEntity;

View File

@ -19,7 +19,9 @@ export class CreateVipCategoryManager extends BaseCreateManager<VipCategoryEntit
return; return;
} }
async generateConfig(): Promise<void> {} async generateConfig(): Promise<void> {
// TODO: Implement logic here
}
get validateRelations(): validateRelations[] { get validateRelations(): validateRelations[] {
return []; return [];

View File

@ -49,7 +49,7 @@ export class VipCategoryDataOrchestrator extends BaseDataTransactionOrchestrator
return this.updateManager.getResult(); return this.updateManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); this.deleteManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -66,7 +66,7 @@ export class VipCategoryDataOrchestrator extends BaseDataTransactionOrchestrator
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); this.activeManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY);
await this.activeManager.execute(); await this.activeManager.execute();
@ -83,7 +83,7 @@ export class VipCategoryDataOrchestrator extends BaseDataTransactionOrchestrator
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); this.confirmManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -100,7 +100,7 @@ export class VipCategoryDataOrchestrator extends BaseDataTransactionOrchestrator
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY); this.inactiveManager.setService(this.serviceData, TABLE_NAME.VIP_CATEGORY);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -34,7 +34,7 @@ export class VipCategoryDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -44,7 +44,7 @@ export class VipCategoryDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -54,7 +54,7 @@ export class VipCategoryDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -72,7 +72,7 @@ export class VipCategoryDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

View File

@ -1,3 +1,3 @@
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity'; import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export interface FilterVipCodeEntity extends BaseFilterEntity {} export type FilterVipCodeEntity = BaseFilterEntity;

View File

@ -0,0 +1,40 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { ChangeDocEvent } from 'src/modules/configuration/couch/domain/events/change-doc.event';
import { VipCodeDataService } from '../../../data/services/vip-code-data.service';
import { VipCodeModel } from '../../../data/models/vip-code.model';
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
@EventsHandler(ChangeDocEvent)
export class CreateVipCodeHandler implements IEventHandler<ChangeDocEvent> {
constructor(
private dataService: VipCodeDataService,
private couchService: CouchService,
) {}
async handle(event: ChangeDocEvent) {
const database = event.data.database;
const data = event.data.data;
if (database != 'vip_code') return;
const queryRunner = this.dataService
.getRepository()
.manager.connection.createQueryRunner();
// jika delete
if (data._deleted ?? false) {
} else {
const dataMapped = {
...data,
id: data._id ?? data.id,
vip_category_id: data.vip_category?._id ?? data.vip_category?.id,
};
try {
await this.dataService.create(queryRunner, VipCodeModel, dataMapped);
} catch (error) {
await this.couchService.createDoc(data, 'error_vip_code');
}
}
}
}

View File

@ -35,7 +35,7 @@ export class CreateVipCodeManager extends BaseCreateManager<VipCodeEntity> {
return [ return [
{ {
topic: VipCodeCreatedEvent, topic: VipCodeCreatedEvent,
data: this.data, relations: ['vip_category'],
}, },
]; ];
} }

View File

@ -21,7 +21,7 @@ export class VipCodeDataOrchestrator extends BaseDataOrchestrator<VipCodeEntity>
update(dataId: string, data: VipCodeEntity): Promise<VipCodeEntity> { update(dataId: string, data: VipCodeEntity): Promise<VipCodeEntity> {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
delete(dataId: string): Promise<String> { delete(dataId: string): Promise<string> {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
batchDelete(dataIds: string[]): Promise<BatchResult> { batchDelete(dataIds: string[]): Promise<BatchResult> {

View File

@ -19,7 +19,7 @@ export class VipCodeDataController {
} }
@Post('generate-code') @Post('generate-code')
async generateCOde(): Promise<String> { async generateCOde(): Promise<string> {
return await this.orchestrator.generateCode(); return await this.orchestrator.generateCode();
} }
@ -29,7 +29,7 @@ export class VipCodeDataController {
// } // }
// @Delete(':id') // @Delete(':id')
// async delete(@Param('id') dataId: string): Promise<String> { // async delete(@Param('id') dataId: string): Promise<string> {
// return await this.orchestrator.delete(dataId); // return await this.orchestrator.delete(dataId);
// } // }
} }

View File

@ -13,6 +13,8 @@ import { CqrsModule } from '@nestjs/cqrs';
import { IndexVipCodeManager } from './domain/usecases/managers/index-vip-code.manager'; import { IndexVipCodeManager } from './domain/usecases/managers/index-vip-code.manager';
import { VipCodeModel } from './data/models/vip-code.model'; import { VipCodeModel } from './data/models/vip-code.model';
import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-code.manager'; import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-code.manager';
import { CreateVipCodeHandler } from './domain/usecases/handlers/create-vip-code.handler';
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
@Module({ @Module({
imports: [ imports: [
@ -22,10 +24,13 @@ import { GenerateVipCodeManager } from './domain/usecases/managers/geneate-vip-c
], ],
controllers: [VipCodeDataController, VipCodeReadController], controllers: [VipCodeDataController, VipCodeReadController],
providers: [ providers: [
CreateVipCodeHandler,
IndexVipCodeManager, IndexVipCodeManager,
CreateVipCodeManager, CreateVipCodeManager,
GenerateVipCodeManager, GenerateVipCodeManager,
CouchService,
VipCodeDataService, VipCodeDataService,
VipCodeReadService, VipCodeReadService,

View File

@ -30,7 +30,9 @@ export class CreateTenantManager extends BaseCreateManager<UserEntity> {
return; return;
} }
async generateConfig(): Promise<void> {} async generateConfig(): Promise<void> {
// TODO: Implement logic here
}
get uniqueColumns(): columnUniques[] { get uniqueColumns(): columnUniques[] {
return [ return [

View File

@ -58,7 +58,7 @@ export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<User
return this.updatePasswordManager.getResult(); return this.updatePasswordManager.getResult();
} }
async delete(dataId): Promise<String> { async delete(dataId): Promise<string> {
this.deleteManager.setData(dataId); this.deleteManager.setData(dataId);
this.deleteManager.setService(this.serviceData, TABLE_NAME.TENANT); this.deleteManager.setService(this.serviceData, TABLE_NAME.TENANT);
await this.deleteManager.execute(); await this.deleteManager.execute();
@ -72,7 +72,7 @@ export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<User
return this.batchDeleteManager.getResult(); return this.batchDeleteManager.getResult();
} }
async active(dataId): Promise<String> { async active(dataId): Promise<string> {
this.activeManager.setData(dataId, STATUS.ACTIVE); this.activeManager.setData(dataId, STATUS.ACTIVE);
this.activeManager.setService(this.serviceData, TABLE_NAME.TENANT); this.activeManager.setService(this.serviceData, TABLE_NAME.TENANT);
await this.activeManager.execute(); await this.activeManager.execute();
@ -86,7 +86,7 @@ export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<User
return this.batchActiveManager.getResult(); return this.batchActiveManager.getResult();
} }
async confirm(dataId): Promise<String> { async confirm(dataId): Promise<string> {
this.confirmManager.setData(dataId, STATUS.ACTIVE); this.confirmManager.setData(dataId, STATUS.ACTIVE);
this.confirmManager.setService(this.serviceData, TABLE_NAME.TENANT); this.confirmManager.setService(this.serviceData, TABLE_NAME.TENANT);
await this.confirmManager.execute(); await this.confirmManager.execute();
@ -100,7 +100,7 @@ export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<User
return this.batchConfirmManager.getResult(); return this.batchConfirmManager.getResult();
} }
async inactive(dataId): Promise<String> { async inactive(dataId): Promise<string> {
this.inactiveManager.setData(dataId, STATUS.INACTIVE); this.inactiveManager.setData(dataId, STATUS.INACTIVE);
this.inactiveManager.setService(this.serviceData, TABLE_NAME.TENANT); this.inactiveManager.setService(this.serviceData, TABLE_NAME.TENANT);
await this.inactiveManager.execute(); await this.inactiveManager.execute();

View File

@ -36,7 +36,7 @@ export class TenantDataController {
} }
@Patch(':id/active') @Patch(':id/active')
async active(@Param('id') dataId: string): Promise<String> { async active(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.active(dataId); return await this.orchestrator.active(dataId);
} }
@ -46,7 +46,7 @@ export class TenantDataController {
} }
@Patch(':id/confirm') @Patch(':id/confirm')
async confirm(@Param('id') dataId: string): Promise<String> { async confirm(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.confirm(dataId); return await this.orchestrator.confirm(dataId);
} }
@ -56,7 +56,7 @@ export class TenantDataController {
} }
@Patch(':id/inactive') @Patch(':id/inactive')
async inactive(@Param('id') dataId: string): Promise<String> { async inactive(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.inactive(dataId); return await this.orchestrator.inactive(dataId);
} }
@ -82,7 +82,7 @@ export class TenantDataController {
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') dataId: string): Promise<String> { async delete(@Param('id') dataId: string): Promise<string> {
return await this.orchestrator.delete(dataId); return await this.orchestrator.delete(dataId);
} }
} }

Some files were not shown because too many files have changed in this diff Show More