feat(SPG-612) Activity Log PoS
parent
2fc80c7cfc
commit
aa550f9d38
|
@ -69,6 +69,7 @@ import { NewsModel } from './modules/web-information/news/data/models/news.model
|
||||||
import { BannerModule } from './modules/web-information/banner/banner.module';
|
import { BannerModule } from './modules/web-information/banner/banner.module';
|
||||||
import { BannerModel } from './modules/web-information/banner/data/models/banner.model';
|
import { BannerModel } from './modules/web-information/banner/data/models/banner.model';
|
||||||
import { MailModule } from './modules/configuration/mail/mail.module';
|
import { MailModule } from './modules/configuration/mail/mail.module';
|
||||||
|
import { PosLogModel } from './modules/configuration/log/data/models/pos-log.model';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -96,6 +97,7 @@ import { MailModule } from './modules/configuration/mail/mail.module';
|
||||||
LogModel,
|
LogModel,
|
||||||
NewsModel,
|
NewsModel,
|
||||||
PaymentMethodModel,
|
PaymentMethodModel,
|
||||||
|
PosLogModel,
|
||||||
RefundModel,
|
RefundModel,
|
||||||
RefundItemModel,
|
RefundItemModel,
|
||||||
SalesPriceFormulaModel,
|
SalesPriceFormulaModel,
|
||||||
|
|
|
@ -7,6 +7,7 @@ export enum TABLE_NAME {
|
||||||
ITEM_RATE = 'item_rates',
|
ITEM_RATE = 'item_rates',
|
||||||
GATE = 'gates',
|
GATE = 'gates',
|
||||||
LOG = 'logs',
|
LOG = 'logs',
|
||||||
|
LOG_POS = 'logs_pos',
|
||||||
NEWS = 'news',
|
NEWS = 'news',
|
||||||
PAYMENT_METHOD = 'payment_methods',
|
PAYMENT_METHOD = 'payment_methods',
|
||||||
PRICE_FORMULA = 'price_formulas',
|
PRICE_FORMULA = 'price_formulas',
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class PosLog1721736523991 implements MigrationInterface {
|
||||||
|
name = 'PosLog1721736523991';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "logs_pos" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" character varying NOT NULL DEFAULT 'cash withdrawal', "pos_number" bigint, "total_balance" numeric, "created_at" bigint, "creator_name" character varying, "creator_id" character varying, CONSTRAINT "PK_60df825558a6b6881d7ad770d26" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP TABLE "logs_pos"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1,6 @@
|
||||||
export const DatabaseListen = ['transaction', 'vip_code'];
|
export const DatabaseListen = [
|
||||||
|
'transaction',
|
||||||
|
'vip_code',
|
||||||
|
'pos_activity',
|
||||||
|
'pos_cash_activity',
|
||||||
|
];
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { Column, Entity } from 'typeorm';
|
||||||
|
import { PosLogEntity, PosLogType } from '../../domain/entities/pos-log.entity';
|
||||||
|
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.LOG_POS)
|
||||||
|
export class PosLogModel
|
||||||
|
extends BaseCoreModel<PosLogEntity>
|
||||||
|
implements PosLogEntity
|
||||||
|
{
|
||||||
|
@Column('varchar', { name: 'type', default: PosLogType.cash_witdrawal })
|
||||||
|
type: PosLogType;
|
||||||
|
|
||||||
|
@Column('bigint', { name: 'pos_number', nullable: true })
|
||||||
|
pos_number: number;
|
||||||
|
|
||||||
|
@Column('decimal', { name: 'total_balance', nullable: true })
|
||||||
|
total_balance: number;
|
||||||
|
|
||||||
|
@Column('bigint', { name: 'created_at', nullable: true })
|
||||||
|
created_at: number;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'creator_name', nullable: true })
|
||||||
|
creator_name: string;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'creator_id', nullable: true })
|
||||||
|
creator_id: string;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { PosLogEntity } from '../../domain/entities/pos-log.entity';
|
||||||
|
import { PosLogModel } from '../models/pos-log.model';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PosLogService extends BaseDataService<PosLogEntity> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(PosLogModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<PosLogModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
||||||
|
|
||||||
|
export interface PosLogEntity extends BaseCoreEntity {
|
||||||
|
type: PosLogType;
|
||||||
|
pos_number: number;
|
||||||
|
total_balance: number;
|
||||||
|
created_at: number;
|
||||||
|
creator_name: string;
|
||||||
|
creator_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PosLogType {
|
||||||
|
cash_witdrawal = 'cash withdrawal',
|
||||||
|
opening_cash = 'opening_cash',
|
||||||
|
login = 'login',
|
||||||
|
logout = 'logout',
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
||||||
|
import { ChangeDocEvent } from 'src/modules/configuration/couch/domain/events/change-doc.event';
|
||||||
|
import { PosLogService } from '../../data/services/pos-log.service';
|
||||||
|
import { PosLogModel } from '../../data/models/pos-log.model';
|
||||||
|
import { PosLogType } from '../entities/pos-log.entity';
|
||||||
|
|
||||||
|
@EventsHandler(ChangeDocEvent)
|
||||||
|
export class RecordPosLogHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
|
constructor(private dataService: PosLogService) {}
|
||||||
|
|
||||||
|
async handle(event: ChangeDocEvent) {
|
||||||
|
try {
|
||||||
|
const database = event.data.database;
|
||||||
|
const data = event.data.data;
|
||||||
|
|
||||||
|
if (!['pos_cash_activity', 'pos_activity'].includes(database)) return;
|
||||||
|
|
||||||
|
const queryRunner = this.dataService
|
||||||
|
.getRepository()
|
||||||
|
.manager.connection.createQueryRunner();
|
||||||
|
|
||||||
|
const activity = new PosLogModel();
|
||||||
|
|
||||||
|
Object.assign(activity, {
|
||||||
|
id: data._id,
|
||||||
|
type: PosLogType[data.type],
|
||||||
|
total_balance: data.withdrawal_cash ?? data.opening_cash_balance,
|
||||||
|
pos_number: data.pos_number,
|
||||||
|
creator_id: data.pos_admin?.id,
|
||||||
|
creator_name: data.pos_admin?.name,
|
||||||
|
created_at: data.created_at,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.dataService.create(
|
||||||
|
queryRunner,
|
||||||
|
PosLogModel,
|
||||||
|
activity,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error handling pos activity couch');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,12 +9,15 @@ import { RecordErrorLogHandler } from './domain/handlers/error-log.handler';
|
||||||
import { RecordLogHandler } from './domain/handlers/log.handler';
|
import { RecordLogHandler } from './domain/handlers/log.handler';
|
||||||
import { ErrorLogService } from './data/services/error-log.service';
|
import { ErrorLogService } from './data/services/error-log.service';
|
||||||
import { LogService } from './data/services/log.service';
|
import { LogService } from './data/services/log.service';
|
||||||
|
import { PosLogModel } from './data/models/pos-log.model';
|
||||||
|
import { PosLogService } from './data/services/pos-log.service';
|
||||||
|
import { RecordPosLogHandler } from './domain/handlers/pos-log.handler';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[LogModel, ErrorLogModel],
|
[LogModel, ErrorLogModel, PosLogModel],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
@ -22,9 +25,11 @@ import { LogService } from './data/services/log.service';
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [
|
providers: [
|
||||||
RecordLogHandler,
|
RecordLogHandler,
|
||||||
|
RecordPosLogHandler,
|
||||||
RecordErrorLogHandler,
|
RecordErrorLogHandler,
|
||||||
|
|
||||||
LogService,
|
LogService,
|
||||||
|
PosLogService,
|
||||||
ErrorLogService,
|
ErrorLogService,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue