feat(SPG-395) REST API Read Rekonsiliasi
parent
a84a48c292
commit
db005426bd
|
@ -0,0 +1,55 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
|
||||
@Injectable()
|
||||
export class DetailReconciliationManager extends BaseDetailManager<TransactionEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: [],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.reconciliation_mdr`,
|
||||
|
||||
`${this.tableName}.payment_type`,
|
||||
`${this.tableName}.payment_type_method_id`,
|
||||
`${this.tableName}.payment_type_method_name`,
|
||||
`${this.tableName}.payment_type_method_number`,
|
||||
`${this.tableName}.payment_code_reference`,
|
||||
`${this.tableName}.payment_date`,
|
||||
|
||||
`${this.tableName}.payment_total`,
|
||||
`${this.tableName}.payment_total_net_profit`,
|
||||
];
|
||||
}
|
||||
|
||||
get setFindProperties(): any {
|
||||
return {
|
||||
id: this.dataId,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import {
|
||||
Param,
|
||||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
import { BetweenQueryHelper } from 'src/core/helpers/query/between-query.helper';
|
||||
|
||||
@Injectable()
|
||||
export class IndexReconciliationManager extends BaseIndexManager<TransactionEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: [],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.type`,
|
||||
`${this.tableName}.reconciliation_status`,
|
||||
`${this.tableName}.reconciliation_mdr`,
|
||||
`${this.tableName}.reconciliation_confirm_date`,
|
||||
`${this.tableName}.reconciliation_confirm_by`,
|
||||
|
||||
`${this.tableName}.customer_name`,
|
||||
|
||||
`${this.tableName}.payment_type`,
|
||||
`${this.tableName}.payment_type_method_id`,
|
||||
`${this.tableName}.payment_type_method_name`,
|
||||
`${this.tableName}.payment_type_method_number`,
|
||||
`${this.tableName}.payment_code_reference`,
|
||||
`${this.tableName}.payment_date`,
|
||||
|
||||
`${this.tableName}.payment_total`,
|
||||
`${this.tableName}.payment_total_net_profit`,
|
||||
];
|
||||
}
|
||||
|
||||
get specificFilter(): Param[] {
|
||||
return [
|
||||
{
|
||||
cols: `${this.tableName}.customer_name`,
|
||||
data: this.filterParam.customer_names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.reconciliation_confirm_by`,
|
||||
data: this.filterParam.confirm_by_names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.payment_type_method_name`,
|
||||
data: this.filterParam.payment_banks,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.payment_type_method_number`,
|
||||
data: this.filterParam.payment_bank_numbers,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<TransactionEntity>,
|
||||
): SelectQueryBuilder<TransactionEntity> {
|
||||
if (this.filterParam.payment_date_from) {
|
||||
new BetweenQueryHelper(
|
||||
queryBuilder,
|
||||
this.tableName,
|
||||
'payment_date',
|
||||
this.filterParam.payment_date_from,
|
||||
this.filterParam.payment_date_to,
|
||||
'payment_created',
|
||||
).getQuery();
|
||||
}
|
||||
|
||||
if (this.filterParam.transaction_type) {
|
||||
queryBuilder.andWhere(`${this.tableName}.type In (:...types)`, {
|
||||
types: [this.filterParam.transaction_type],
|
||||
});
|
||||
}
|
||||
|
||||
if (this.filterParam.couner_no) {
|
||||
queryBuilder.andWhere(
|
||||
`${this.tableName}.creator_counter_no In (:...counters)`,
|
||||
{
|
||||
counters: [this.filterParam.couner_no],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (this.filterParam.payment_type) {
|
||||
queryBuilder.andWhere(
|
||||
`${this.tableName}.creator_counter_no In (:...counters)`,
|
||||
{
|
||||
counters: [this.filterParam.couner_no],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (this.filterParam.payment_via) {
|
||||
queryBuilder.andWhere(`${this.tableName}.payment_type In (:...type)`, {
|
||||
type: [this.filterParam.payment_via],
|
||||
});
|
||||
}
|
||||
|
||||
if (this.filterParam.payment_bank) {
|
||||
queryBuilder.andWhere(
|
||||
`${this.tableName}.payment_type_method_name In (:...banks)`,
|
||||
{
|
||||
banks: [this.filterParam.payment_bank],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (this.filterParam.confirmation_date_from) {
|
||||
new BetweenQueryHelper(
|
||||
queryBuilder,
|
||||
this.tableName,
|
||||
'payment_date',
|
||||
this.filterParam.confirmation_date_from,
|
||||
this.filterParam.confirmation_date_to,
|
||||
'payment_created',
|
||||
).getQuery();
|
||||
}
|
||||
|
||||
queryBuilder.andWhere(
|
||||
`${this.tableName}.reconciliation_status Is Not Null`,
|
||||
);
|
||||
return queryBuilder;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { IndexReconciliationManager } from './managers/index-reconciliation.manager';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
||||
import { DetailReconciliationManager } from './managers/detail-reconciliation.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
import { TransactionReadService } from 'src/modules/transaction/transaction/data/services/transaction-read.service';
|
||||
|
||||
@Injectable()
|
||||
export class ReconciliationReadOrchestrator extends BaseReadOrchestrator<TransactionEntity> {
|
||||
constructor(
|
||||
private indexManager: IndexReconciliationManager,
|
||||
private detailManager: DetailReconciliationManager,
|
||||
private serviceData: TransactionReadService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async index(params): Promise<PaginationResponse<TransactionEntity>> {
|
||||
this.indexManager.setFilterParam(params);
|
||||
this.indexManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
||||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<TransactionEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
||||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||
import { FilterTransactionEntity } from 'src/modules/transaction/transaction/domain/entities/filter-transaction.entity';
|
||||
|
||||
export class FilterReconciliationDto
|
||||
extends BaseFilterDto
|
||||
implements FilterTransactionEntity
|
||||
{
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
customer_names: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
confirm_by_names: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
payment_banks: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
payment_bank_numbers: string[];
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
payment_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
payment_date_to: Date;
|
||||
|
||||
@ApiProperty({ type: Number, required: false })
|
||||
couner_no: number;
|
||||
|
||||
@ApiProperty({ type: String, required: false })
|
||||
payment_type: string;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
confirmation_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
confirmation_date_to: Date;
|
||||
|
||||
@ApiProperty({ type: String, required: false })
|
||||
transaction_type: string;
|
||||
|
||||
@ApiProperty({ type: String, required: false })
|
||||
payment_via: string;
|
||||
|
||||
@ApiProperty({ type: String, required: false })
|
||||
payment_bank: string;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { FilterReconciliationDto } from './dto/filter-reconciliation.dto';
|
||||
import { Pagination } from 'src/core/response';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { ReconciliationReadOrchestrator } from '../domain/usecases/reconciliation-read.orchestrator';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { TransactionEntity } from '../../transaction/domain/entities/transaction.entity';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.RECONCILIATION.split('-').join(' ')} - read`)
|
||||
@Controller(`v1/${MODULE_NAME.RECONCILIATION}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class ReconciliationReadController {
|
||||
constructor(private orchestrator: ReconciliationReadOrchestrator) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
async index(
|
||||
@Query() params: FilterReconciliationDto,
|
||||
): Promise<PaginationResponse<TransactionEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async detail(@Param('id') id: string): Promise<TransactionEntity> {
|
||||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue