feat(SPG-428) REST API Read Data Gate

pull/28/head
Aswin Ashar Abdullah 2024-07-15 14:28:45 +07:00
parent 0d2e49f93a
commit af1a642907
9 changed files with 268 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import { ItemType } from 'src/modules/item-related/item-category/constants';
import { LimitType } from 'src/modules/item-related/item/constants'; import { LimitType } from 'src/modules/item-related/item/constants';
import { PaymentMethodType } from 'src/modules/transaction/payment-method/constants'; import { PaymentMethodType } from 'src/modules/transaction/payment-method/constants';
import { RefundType } from 'src/modules/transaction/refund/constants'; import { RefundType } from 'src/modules/transaction/refund/constants';
import { GateType } from 'src/modules/web-information/gate/constants';
@ApiTags('configuration - constant') @ApiTags('configuration - constant')
@Controller('v1/constant') @Controller('v1/constant')
@ -50,4 +51,9 @@ export class ConstantController {
async refundType(): Promise<any> { async refundType(): Promise<any> {
return Object.values(RefundType); return Object.values(RefundType);
} }
@Get('gate-type')
async gateType(): Promise<any> {
return Object.values(GateType);
}
} }

View File

@ -1,18 +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 FilterRefundEntity extends BaseFilterEntity { 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;
}

View File

@ -0,0 +1,17 @@
import { Injectable } from '@nestjs/common';
import { GateEntity } from '../../domain/entities/gate.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { GateModel } from '../models/gate.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 GateReadService extends BaseReadService<GateEntity> {
constructor(
@InjectRepository(GateModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<GateModel>,
) {
super(repo);
}
}

View File

@ -0,0 +1,8 @@
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export interface FilterGateEntity extends BaseFilterEntity {
codes: string[];
types: string[];
item_names: string[];
notes: string[];
}

View File

@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import { IndexGateManager } from './managers/index-gate.manager';
import { GateReadService } from '../../data/services/gate-read.service';
import { GateEntity } from '../entities/gate.entity';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
import { DetailGateManager } from './managers/detail-gate.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
@Injectable()
export class GateReadOrchestrator extends BaseReadOrchestrator<GateEntity> {
constructor(
private indexManager: IndexGateManager,
private detailManager: DetailGateManager,
private serviceData: GateReadService,
) {
super();
}
async index(params): Promise<PaginationResponse<GateEntity>> {
this.indexManager.setFilterParam(params);
this.indexManager.setService(this.serviceData, TABLE_NAME.GATE);
await this.indexManager.execute();
return this.indexManager.getResult();
}
async detail(dataId: string): Promise<GateEntity> {
this.detailManager.setData(dataId);
this.detailManager.setService(this.serviceData, TABLE_NAME.GATE);
await this.detailManager.execute();
return this.detailManager.getResult();
}
}

View File

@ -0,0 +1,59 @@
import { Injectable } from '@nestjs/common';
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
import { GateEntity } from '../../entities/gate.entity';
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
@Injectable()
export class DetailGateManager extends BaseDetailManager<GateEntity> {
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: ['item'],
// relation yang hanya ingin dihitung (akan return number)
countRelations: [],
};
}
get selects(): string[] {
return [
`${this.tableName}.id`,
`${this.tableName}.status`,
`${this.tableName}.creator_name`,
`${this.tableName}.created_at`,
`${this.tableName}.updated_at`,
`${this.tableName}.editor_name`,
`${this.tableName}.type`,
`${this.tableName}.code`,
`${this.tableName}.note`,
'item.id',
'item.name',
'item.status',
'item.item_type',
'item.base_price',
'item.hpp',
];
}
get setFindProperties(): any {
return {
id: this.dataId,
};
}
}

View File

@ -0,0 +1,84 @@
import { Injectable } from '@nestjs/common';
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
import { GateEntity } from '../../entities/gate.entity';
import { SelectQueryBuilder } from 'typeorm';
import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
@Injectable()
export class IndexGateManager extends BaseIndexManager<GateEntity> {
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: ['item'],
// relation yang hanya ingin dihitung (akan return number)
countRelations: [],
};
}
get selects(): string[] {
return [
`${this.tableName}.id`,
`${this.tableName}.status`,
`${this.tableName}.creator_name`,
`${this.tableName}.created_at`,
`${this.tableName}.updated_at`,
`${this.tableName}.editor_name`,
`${this.tableName}.type`,
`${this.tableName}.code`,
`${this.tableName}.note`,
'item.id',
'item.name',
'item.status',
'item.item_type',
'item.base_price',
'item.hpp',
];
}
get specificFilter(): Param[] {
return [
{
cols: `${this.tableName}.code`,
data: this.filterParam.codes,
},
{
cols: `${this.tableName}.type`,
data: this.filterParam.types,
},
{
cols: `${this.tableName}.note`,
data: this.filterParam.notes,
},
{
cols: `item.name`,
data: this.filterParam.item_names,
},
];
}
setQueryFilter(
queryBuilder: SelectQueryBuilder<GateEntity>,
): SelectQueryBuilder<GateEntity> {
return queryBuilder;
}
}

View File

@ -0,0 +1,30 @@
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
import { FilterGateEntity } from '../../domain/entities/filter-gate.entity';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
export class FilterGateDto extends BaseFilterDto implements FilterGateEntity {
@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];
})
types: string[];
@ApiProperty({ type: ['string'], required: false })
@Transform((body) => {
return Array.isArray(body.value) ? body.value : [body.value];
})
item_names: string[];
@ApiProperty({ type: ['string'], required: false })
@Transform((body) => {
return Array.isArray(body.value) ? body.value : [body.value];
})
notes: string[];
}

View File

@ -0,0 +1,30 @@
import { Controller, Get, Param, Query } from '@nestjs/common';
import { FilterGateDto } from './dto/filter-gate.dto';
import { Pagination } from 'src/core/response';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { GateEntity } from '../domain/entities/gate.entity';
import { GateReadOrchestrator } from '../domain/usecases/gate-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.GATE.split('-').join(' ')} - read`)
@Controller(`v1/${MODULE_NAME.GATE}`)
@Public(false)
@ApiBearerAuth('JWT')
export class GateReadController {
constructor(private orchestrator: GateReadOrchestrator) {}
@Get()
@Pagination()
async index(
@Query() params: FilterGateDto,
): Promise<PaginationResponse<GateEntity>> {
return await this.orchestrator.index(params);
}
@Get(':id')
async detail(@Param('id') id: string): Promise<GateEntity> {
return await this.orchestrator.detail(id);
}
}