Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development
commit
bd14dc0b4b
|
@ -57,6 +57,10 @@ import {
|
||||||
TimeGroupUpdatedHandler,
|
TimeGroupUpdatedHandler,
|
||||||
} from './domain/managers/time-group.handle';
|
} from './domain/managers/time-group.handle';
|
||||||
|
|
||||||
|
import { DataSchedulingUpdatedHandler } from './domain/managers/data-scheduling.handler';
|
||||||
|
import { DataSchedulingDefaultModel } from '../data-scheduling/data/models/data-scheduling-default.model';
|
||||||
|
import { DataSchedulingModel } from '../data-scheduling/data/models/data-scheduling.model';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -71,6 +75,9 @@ import {
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
TransactionItemModel,
|
TransactionItemModel,
|
||||||
TransactionDemographyModel,
|
TransactionDemographyModel,
|
||||||
|
|
||||||
|
DataSchedulingDefaultModel,
|
||||||
|
DataSchedulingModel,
|
||||||
],
|
],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
|
@ -104,6 +111,8 @@ import {
|
||||||
SeasonTypeDeletedHandler,
|
SeasonTypeDeletedHandler,
|
||||||
SeasonTypeUpdatedHandler,
|
SeasonTypeUpdatedHandler,
|
||||||
|
|
||||||
|
DataSchedulingUpdatedHandler,
|
||||||
|
|
||||||
SeasonPeriodDataService,
|
SeasonPeriodDataService,
|
||||||
TransactionDataService,
|
TransactionDataService,
|
||||||
UserDataService,
|
UserDataService,
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { CouchService } from '../../data/services/couch.service';
|
||||||
|
import { DataSchedulingDeletedEvent } from 'src/modules/configuration/data-scheduling/domain/entities/event/data-scheduling-deleted.event';
|
||||||
|
import { DataSchedulingChangeStatusEvent } from 'src/modules/configuration/data-scheduling/domain/entities/event/data-scheduling-change-status.event';
|
||||||
|
import { DataSchedulingUpdatedEvent } from 'src/modules/configuration/data-scheduling/domain/entities/event/data-scheduling-updated.event';
|
||||||
|
import { DataSchedulingCreatedEvent } from 'src/modules/configuration/data-scheduling/domain/entities/event/data-scheduling-created.event';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { DataSchedulingDefaultModel } from 'src/modules/configuration/data-scheduling/data/models/data-scheduling-default.model';
|
||||||
|
import { DataSchedulingModel } from 'src/modules/configuration/data-scheduling/data/models/data-scheduling.model';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
import * as momentTz from 'moment-timezone';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { DataSchedulingEntity } from 'src/modules/configuration/data-scheduling/domain/entities/data-scheduling.entity';
|
||||||
|
import { decryptionTotal } from 'src/modules/configuration/data-scheduling/infrastructure/helpers';
|
||||||
|
|
||||||
|
@EventsHandler(
|
||||||
|
DataSchedulingCreatedEvent,
|
||||||
|
DataSchedulingUpdatedEvent,
|
||||||
|
DataSchedulingChangeStatusEvent,
|
||||||
|
DataSchedulingDeletedEvent,
|
||||||
|
)
|
||||||
|
export class DataSchedulingUpdatedHandler implements IEventHandler {
|
||||||
|
constructor(
|
||||||
|
private couchService: CouchService,
|
||||||
|
|
||||||
|
@InjectRepository(DataSchedulingDefaultModel)
|
||||||
|
private repository: Repository<DataSchedulingDefaultModel>,
|
||||||
|
|
||||||
|
@InjectRepository(DataSchedulingModel)
|
||||||
|
private repoSchedule: Repository<DataSchedulingModel>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async handle() {
|
||||||
|
const activeData = await this.getActiveData();
|
||||||
|
console.log(
|
||||||
|
activeData,
|
||||||
|
'handle when data scheduling status change and data updated',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getActiveData() {
|
||||||
|
const timeZoneWIB = 'Asia/Jakarta';
|
||||||
|
const nowInWIB = momentTz().tz(timeZoneWIB).format('YYYY-MM-DD');
|
||||||
|
const date = nowInWIB;
|
||||||
|
|
||||||
|
const qb = this.repoSchedule.createQueryBuilder(TABLE_NAME.DATA_SCHEDULING);
|
||||||
|
|
||||||
|
const findData: DataSchedulingEntity = await qb
|
||||||
|
.where('status = :status', { status: 'active' })
|
||||||
|
.andWhere('schedule_date_from <= :date', { date: date })
|
||||||
|
.andWhere('schedule_date_to >= :date', { date: date })
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!findData) {
|
||||||
|
const defaultData = await this.repository
|
||||||
|
.createQueryBuilder(TABLE_NAME.DATA_SCHEDULING_DEFAULT)
|
||||||
|
.getOne();
|
||||||
|
return { value: defaultData?.default_value };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { value: decryptionTotal(findData.indexing_key as string), date };
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,18 +2,13 @@ import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { UserProvider, UsersSession } from 'src/core/sessions';
|
import { UserProvider, UsersSession } from 'src/core/sessions';
|
||||||
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
import { BLANK_USER } from 'src/core/strings/constants/base.constants';
|
||||||
import { EditDataSchedulingDefaultDto } from '../../../infrastructure/dto/data-scheduling.dto';
|
import { EditDataSchedulingDefaultDto } from '../../../infrastructure/dto/data-scheduling.dto';
|
||||||
import {
|
import { DataSchedulingDefaultEntity } from '../../entities/data-scheduling.entity';
|
||||||
DataSchedulingDefaultEntity,
|
|
||||||
DataSchedulingEntity,
|
|
||||||
} from '../../entities/data-scheduling.entity';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling-default.model';
|
import { DataSchedulingDefaultModel } from '../../../data/models/data-scheduling-default.model';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { SelectQueryBuilder } from 'typeorm';
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
import { DataSchedulingModel } from '../../../data/models/data-scheduling.model';
|
||||||
import { decryptionTotal } from '../../../infrastructure/helpers';
|
|
||||||
import * as momentTz from 'moment-timezone';
|
|
||||||
import { EventBus } from '@nestjs/cqrs';
|
import { EventBus } from '@nestjs/cqrs';
|
||||||
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
import { DataSchedulingChangeStatusEvent } from '../../entities/event/data-scheduling-change-status.event';
|
||||||
|
|
||||||
|
@ -70,6 +65,7 @@ export class DataSchedulingManager {
|
||||||
updated_at: dateNow,
|
updated_at: dateNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
await this.publishEventUpdates();
|
||||||
return this.repository.save(payload);
|
return this.repository.save(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,33 +73,14 @@ export class DataSchedulingManager {
|
||||||
return this.queryBuilder().getOne();
|
return this.queryBuilder().getOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getActiveData() {
|
async publishEventUpdates() {
|
||||||
const timeZoneWIB = 'Asia/Jakarta';
|
await this.eventBus.publish(
|
||||||
const nowInWIB = momentTz().tz(timeZoneWIB).format('YYYY-MM-DD');
|
new DataSchedulingChangeStatusEvent({ data: null } as any),
|
||||||
const date = nowInWIB;
|
);
|
||||||
|
|
||||||
const qb = this.repoSchedule.createQueryBuilder(TABLE_NAME.DATA_SCHEDULING);
|
|
||||||
|
|
||||||
const findData: DataSchedulingEntity = await qb
|
|
||||||
.where('status = :status', { status: 'active' })
|
|
||||||
.andWhere('schedule_date_from <= :date', { date: date })
|
|
||||||
.andWhere('schedule_date_to >= :date', { date: date })
|
|
||||||
.getOne();
|
|
||||||
|
|
||||||
if (!findData) {
|
|
||||||
const defaultData = await this.queryBuilder().getOne();
|
|
||||||
return { value: defaultData?.default_value };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { value: decryptionTotal(findData.indexing_key as string), date };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupActiveScheduling() {
|
async setupActiveScheduling() {
|
||||||
const activeSchedule = await this.getActiveData();
|
await this.publishEventUpdates();
|
||||||
await this.eventBus.publish(
|
|
||||||
new DataSchedulingChangeStatusEvent({ data: activeSchedule } as any),
|
|
||||||
);
|
|
||||||
|
|
||||||
return { message: 'Success setup transaction schedule.' };
|
return { message: 'Success setup transaction schedule.' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue