feat(SPG-393) REST API Read Refund
parent
2ed4ce0199
commit
daf325b1a0
|
@ -0,0 +1,17 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { RefundEntity } from '../../domain/entities/refund.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { RefundModel } from '../models/refund.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
|
||||
@Injectable()
|
||||
export class RefundReadService extends BaseReadService<RefundEntity> {
|
||||
constructor(
|
||||
@InjectRepository(RefundModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<RefundModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
|
||||
export interface FilterRefundEntity extends BaseFilterEntity {
|
||||
codes: string[];
|
||||
invoice_codes: string[];
|
||||
bank_names: string[];
|
||||
bank_account_names: string[];
|
||||
bank_account_numbers: string[];
|
||||
contact_names: string[];
|
||||
creator_names: string[];
|
||||
|
||||
refund_date_from: Date;
|
||||
refund_date_to: Date;
|
||||
request_date_from: Date;
|
||||
request_date_to: Date;
|
||||
settlement_date_from: Date;
|
||||
settlement_date_to: Date;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||
import { RefundEntity } from '../../entities/refund.entity';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { mappingTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||
|
||||
@Injectable()
|
||||
export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
mappingTransaction(this.result['transaction']);
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['transaction', 'transaction.items', 'items.refund'],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.code`,
|
||||
`${this.tableName}.status`,
|
||||
`${this.tableName}.type`,
|
||||
|
||||
`${this.tableName}.request_date`,
|
||||
`${this.tableName}.refund_date`,
|
||||
`${this.tableName}.created_at`,
|
||||
`${this.tableName}.updated_at`,
|
||||
`${this.tableName}.creator_name`,
|
||||
`${this.tableName}.editor_name`,
|
||||
|
||||
`${this.tableName}.refund_total`,
|
||||
`${this.tableName}.bank_name`,
|
||||
`${this.tableName}.bank_account_name`,
|
||||
`${this.tableName}.bank_account_number`,
|
||||
|
||||
'transaction',
|
||||
'items',
|
||||
'refund',
|
||||
];
|
||||
}
|
||||
|
||||
get setFindProperties(): any {
|
||||
return {
|
||||
id: this.dataId,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||
import { RefundEntity } from '../../entities/refund.entity';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import {
|
||||
Param,
|
||||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { BetweenQueryHelper } from 'src/core/helpers/query/between-query.helper';
|
||||
|
||||
@Injectable()
|
||||
export class IndexRefundManager extends BaseIndexManager<RefundEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
this.result?.data?.map((item) => {
|
||||
delete item['transaction']?.id;
|
||||
Object.assign(item, {
|
||||
...item['transaction'],
|
||||
});
|
||||
|
||||
delete item['transaction'];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['transaction'],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [
|
||||
`${this.tableName}.id`,
|
||||
`${this.tableName}.code`,
|
||||
`${this.tableName}.status`,
|
||||
`${this.tableName}.type`,
|
||||
|
||||
`${this.tableName}.request_date`,
|
||||
`${this.tableName}.refund_date`,
|
||||
`${this.tableName}.created_at`,
|
||||
`${this.tableName}.updated_at`,
|
||||
`${this.tableName}.creator_name`,
|
||||
`${this.tableName}.editor_name`,
|
||||
|
||||
`${this.tableName}.refund_total`,
|
||||
`${this.tableName}.bank_name`,
|
||||
`${this.tableName}.bank_account_name`,
|
||||
`${this.tableName}.bank_account_number`,
|
||||
|
||||
`transaction.id`,
|
||||
`transaction.invoice_code`,
|
||||
`transaction.settlement_date`,
|
||||
`transaction.payment_total`,
|
||||
`transaction.customer_name`,
|
||||
`transaction.customer_phone`,
|
||||
`transaction.customer_email`,
|
||||
`transaction.customer_description`,
|
||||
];
|
||||
}
|
||||
|
||||
get specificFilter(): Param[] {
|
||||
return [
|
||||
{
|
||||
cols: `${this.tableName}.code`,
|
||||
data: this.filterParam.codes,
|
||||
},
|
||||
{
|
||||
cols: `transaction.invoice_code`,
|
||||
data: this.filterParam.invoice_codes,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.bank_name`,
|
||||
data: this.filterParam.bank_names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.bank_account_name`,
|
||||
data: this.filterParam.bank_account_names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.bank_account_number`,
|
||||
data: this.filterParam.bank_account_numbers,
|
||||
},
|
||||
{
|
||||
cols: `transaction.customer_name`,
|
||||
data: this.filterParam.contact_names,
|
||||
},
|
||||
{
|
||||
cols: `${this.tableName}.creator_name`,
|
||||
data: this.filterParam.creator_names,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<RefundEntity>,
|
||||
): SelectQueryBuilder<RefundEntity> {
|
||||
if (!!this.filterParam.refund_date_from)
|
||||
new BetweenQueryHelper(
|
||||
queryBuilder,
|
||||
this.tableName,
|
||||
'refund_date',
|
||||
this.filterParam.refund_date_from,
|
||||
this.filterParam.refund_date_to ?? this.filterParam.refund_date_from,
|
||||
'refund_date',
|
||||
).getQuery();
|
||||
|
||||
if (!!this.filterParam.request_date_from)
|
||||
new BetweenQueryHelper(
|
||||
queryBuilder,
|
||||
this.tableName,
|
||||
'request_date',
|
||||
this.filterParam.request_date_from,
|
||||
this.filterParam.request_date_to ?? this.filterParam.request_date_from,
|
||||
'request_date',
|
||||
).getQuery();
|
||||
|
||||
if (!!this.filterParam.settlement_date_from)
|
||||
new BetweenQueryHelper(
|
||||
queryBuilder,
|
||||
'transaction',
|
||||
'settlement_date',
|
||||
this.filterParam.settlement_date_from,
|
||||
this.filterParam.settlement_date_to ??
|
||||
this.filterParam.settlement_date_from,
|
||||
'settlement_date',
|
||||
).getQuery();
|
||||
|
||||
return queryBuilder;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { IndexRefundManager } from './managers/index-refund.manager';
|
||||
import { RefundReadService } from '../../data/services/refund-read.service';
|
||||
import { RefundEntity } from '../entities/refund.entity';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
||||
import { DetailRefundManager } from './managers/detail-refund.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
|
||||
@Injectable()
|
||||
export class RefundReadOrchestrator extends BaseReadOrchestrator<RefundEntity> {
|
||||
constructor(
|
||||
private indexManager: IndexRefundManager,
|
||||
private detailManager: DetailRefundManager,
|
||||
private serviceData: RefundReadService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async index(params): Promise<PaginationResponse<RefundEntity>> {
|
||||
this.indexManager.setFilterParam(params);
|
||||
this.indexManager.setService(this.serviceData, TABLE_NAME.REFUND);
|
||||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<RefundEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData, TABLE_NAME.REFUND);
|
||||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||
import { FilterRefundEntity } from '../../domain/entities/filter-refund.entity';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class FilterRefundDto
|
||||
extends BaseFilterDto
|
||||
implements FilterRefundEntity
|
||||
{
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
codes: string[];
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
invoice_codes: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
bank_names: string[];
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
bank_account_names: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
bank_account_numbers: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
contact_names: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
creator_names: string[];
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
refund_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
refund_date_to: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
request_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
request_date_to: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
settlement_date_from: Date;
|
||||
|
||||
@ApiProperty({ type: Date, required: false })
|
||||
settlement_date_to: Date;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { FilterRefundDto } from './dto/filter-refund.dto';
|
||||
import { Pagination } from 'src/core/response';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { RefundEntity } from '../domain/entities/refund.entity';
|
||||
import { RefundReadOrchestrator } from '../domain/usecases/refund-read.orchestrator';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { Public } from 'src/core/guards';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.REFUND.split('-').join(' ')} - read`)
|
||||
@Controller(`v1/${MODULE_NAME.REFUND}`)
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class RefundReadController {
|
||||
constructor(private orchestrator: RefundReadOrchestrator) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
async index(
|
||||
@Query() params: FilterRefundDto,
|
||||
): Promise<PaginationResponse<RefundEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async detail(@Param('id') id: string): Promise<RefundEntity> {
|
||||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['items'],
|
||||
selectRelations: ['items', 'items.refund item_refund', 'refund'],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
|
@ -72,6 +72,8 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
|||
`${this.tableName}.payment_total`,
|
||||
|
||||
'items',
|
||||
'item_refund',
|
||||
'refund',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ export function mappingTransaction(data) {
|
|||
id: data.payment_type_method_id,
|
||||
issuer_name: data.payment_type_method_name,
|
||||
account_number: data.payment_type_method_number,
|
||||
qr_image: data.payment_type_method_qr,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,10 @@ export function mappingTransaction(data) {
|
|||
name: itemData.item_category_name,
|
||||
},
|
||||
},
|
||||
refund: itemData.refund,
|
||||
qty: itemData.qty,
|
||||
qty_remaining: itemData.qty_remaining,
|
||||
total_price_refund: itemData.refund?.refund_total ?? 0,
|
||||
total_price: itemData.total_price,
|
||||
};
|
||||
});
|
||||
|
@ -63,6 +67,7 @@ export function mappingTransaction(data) {
|
|||
delete data.payment_type_method_id;
|
||||
delete data.payment_type_method_name;
|
||||
delete data.payment_type_method_number;
|
||||
delete data.payment_type_method_qr;
|
||||
}
|
||||
|
||||
export function mappingRevertTransaction(data, type) {
|
||||
|
@ -124,6 +129,7 @@ export function mappingRevertTransaction(data, type) {
|
|||
item_type: item.item.item_type,
|
||||
item_price: item.item.base_price,
|
||||
item_hpp: item.item.hpp,
|
||||
qty_remaining: item.qty,
|
||||
|
||||
item_category_id: item.item.item_category?.id,
|
||||
item_category_name: item.item.item_category?.name,
|
||||
|
|
|
@ -18,6 +18,14 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
this.result?.data?.map((item) => {
|
||||
Object.assign(item, {
|
||||
refund_code: item['refund']?.code ?? null,
|
||||
refund_date: item['refund']?.refund_date ?? null,
|
||||
});
|
||||
|
||||
delete item['refund'];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,7 +35,7 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: ['items'],
|
||||
selectRelations: ['items', 'refund'],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
|
@ -63,6 +71,10 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
|
|||
`${this.tableName}.payment_type_method_id`,
|
||||
`${this.tableName}.payment_type_method_name`,
|
||||
`${this.tableName}.payment_type_method_number`,
|
||||
|
||||
`refund.id`,
|
||||
`refund.code`,
|
||||
`refund.refund_date`,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue