fix/data #32

Merged
aswin merged 3 commits from fix/data into development 2024-07-18 11:15:26 +00:00
10 changed files with 28 additions and 26 deletions

View File

@ -13,9 +13,11 @@ export abstract class BaseReadService<Entity> {
queryBuilder: SelectQueryBuilder<Entity>,
params: BaseFilterEntity,
): Promise<PaginationResponse<Entity>> {
const limit = params.limit ?? 10;
const page = params.page ?? 1;
const [data, total] = await queryBuilder
.take(+params.limit)
.skip(+params.limit * +params.page - +params.limit)
.take(+limit)
.skip(+limit * +page - +limit)
.getManyAndCount();
return {

View File

@ -6,10 +6,7 @@ import { Global, Module } from '@nestjs/common';
@Global()
@Module({
imports: [
ConfigModule.forRoot(),
CqrsModule,
],
imports: [ConfigModule.forRoot(), CqrsModule],
controllers: [MidtransController],
providers: [MidtransService],
exports: [MidtransService],

View File

@ -124,8 +124,6 @@ export class IndexItemRateManager extends BaseIndexManager<ItemEntity> {
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
tenantIds: this.filterParam.tenant_ids,
});
} else if (!this.filterParam.all_item) {
queryBuilder.andWhere(`${this.tableName}.tenant_id Is Null`);
}
return queryBuilder;

View File

@ -72,17 +72,17 @@ export class IndexItemRatesManager extends BaseIndexManager<ItemRateEntity> {
}
if (this.filterParam.season_period_ids) {
queryBuilder.andWhere(`season_period.id In (:...itemIds)`, {
itemIds: this.filterParam.season_period_ids,
queryBuilder.andWhere(`season_period.id In (:...seasonIdss)`, {
seasonIdss: this.filterParam.season_period_ids,
});
}
if (this.filterParam.start_date) {
queryBuilder.andWhere(`season_period.start_date < :inputStartDate`, {
queryBuilder.andWhere(`season_period.start_date <= :inputStartDate`, {
inputStartDate: this.filterParam.end_date,
});
queryBuilder.andWhere(`season_period.end_date > :inputEndDate`, {
queryBuilder.andWhere(`season_period.end_date >= :inputEndDate`, {
inputEndDate: this.filterParam.start_date,
});
}

View File

@ -85,8 +85,6 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
tenantIds: this.filterParam.tenant_ids,
});
} else if (!this.filterParam.all_item) {
queryBuilder.andWhere(`${this.tableName}.tenant_id Is Null`);
}
return queryBuilder;

View File

@ -69,13 +69,12 @@ export class CurrentSeasonPeriodManager extends BaseIndexManager<SeasonPeriodEnt
setQueryFilter(
queryBuilder: SelectQueryBuilder<SeasonPeriodEntity>,
): SelectQueryBuilder<SeasonPeriodEntity> {
queryBuilder.andWhere(
`${this.tableName}.start_date BETWEEN :from AND :to`,
{
from: this.filterParam.date ?? new Date().toLocaleDateString(),
to: this.filterParam.date ?? new Date().toLocaleDateString(),
},
);
queryBuilder.andWhere(`${this.tableName}.start_date <= :date`, {
date: this.filterParam.date ?? new Date().toLocaleDateString(),
});
queryBuilder.andWhere(`${this.tableName}.end_date >= :date`, {
date: this.filterParam.date ?? new Date().toLocaleDateString(),
});
queryBuilder.andWhere(`${this.tableName}.status In (:...statuses)`, {
statuses: [STATUS.ACTIVE],

View File

@ -38,10 +38,10 @@ export async function ValidateSeasonPeriodHelper(dataService, data) {
let datas = await query
.andWhere('data.priority = :priority', { priority: priority })
.andWhere(`data.start_date < :inputStartDate`, {
.andWhere(`data.start_date <= :inputStartDate`, {
inputStartDate: data.end_date,
})
.andWhere(`data.end_date > :inputEndDate`, {
.andWhere(`data.end_date >= :inputEndDate`, {
inputEndDate: data.start_date,
})
.getMany();

View File

@ -87,11 +87,11 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
data: this.filterParam.invoice_codes,
},
{
cols: `${this.tableName}.type`,
cols: `${this.tableName}.type::text`,
data: this.filterParam.types,
},
{
cols: `${this.tableName}.customer_type`,
cols: `${this.tableName}.customer_type::text`,
data: this.filterParam.customer_types,
},
{
@ -99,7 +99,7 @@ export class IndexTransactionManager extends BaseIndexManager<TransactionEntity>
data: this.filterParam.customer_names,
},
{
cols: `${this.tableName}.payment_type`,
cols: `${this.tableName}.payment_type::text`,
data: this.filterParam.payment_types,
},
{

View File

@ -6,10 +6,13 @@ import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
@Injectable()
export class IndexFaqManager extends BaseIndexManager<FaqEntity> {
async prepareData(): Promise<void> {
this.filterParam.order_by = `${this.tableName}.sort_order`;
this.filterParam.order_type = ORDER_TYPE.ASC;
return;
}
@ -38,6 +41,7 @@ export class IndexFaqManager extends BaseIndexManager<FaqEntity> {
return [
`${this.tableName}.id`,
`${this.tableName}.status`,
`${this.tableName}.sort_order`,
`${this.tableName}.created_at`,
`${this.tableName}.creator_name`,
`${this.tableName}.updated_at`,

View File

@ -6,10 +6,13 @@ import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
@Injectable()
export class IndexTermConditionManager extends BaseIndexManager<TermConditionEntity> {
async prepareData(): Promise<void> {
this.filterParam.order_by = `${this.tableName}.sort_order`;
this.filterParam.order_type = ORDER_TYPE.ASC;
return;
}
@ -38,6 +41,7 @@ export class IndexTermConditionManager extends BaseIndexManager<TermConditionEnt
return [
`${this.tableName}.id`,
`${this.tableName}.status`,
`${this.tableName}.sort_order`,
`${this.tableName}.created_at`,
`${this.tableName}.creator_name`,
`${this.tableName}.updated_at`,