Compare commits

..

No commits in common. "development" and "fix/bug-firman2" have entirely different histories.

311 changed files with 603 additions and 26957 deletions

View File

@ -1,109 +1,38 @@
kind: pipeline kind: pipeline
type: docker type: docker
name: server name: build
steps: steps:
# - name: build - name: build-dev
# image: appleboy/drone-ssh
# settings:
# host:
# - 172.10.10.10
# username: eigen
# key:
# from_secret: DEVOPS_SSH_PRIVATE_OPEN
# port: 22
# script:
# - cd /home/eigen/PROJECT/POS/POS.DEV/BE
# - sh build.sh
# when:
# ref:
# - refs/tags/devel_*
# - refs/tags/*-alpha.*
- name: build-testing
image: plugins/docker image: plugins/docker
settings: settings:
registry: registry.eigen.co.id registry: registry.eigen.co.id
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME} repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
tags: ${DRONE_TAG} build_args:
- env_target=env.development
tags: latest
custom_dns: 172.10.10.16 custom_dns: 172.10.10.16
when:
ref:
- refs/tags/*-alpha.*
- name: build-production
image: plugins/docker
settings:
registry: registry.eigen.co.id
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
tags: ${DRONE_TAG}
custom_dns: 172.10.10.16
when:
ref:
- refs/tags/*-production.*
- name: send-message
image: plugins/webhook
settings:
urls: https://mattermost.eigen.co.id/api/v4/posts
content_type: application/json
headers:
- Authorization=Bearer 5zubexudb38uuradfa36qy98ca
template: |
{
"channel_id": "s1ekqde1c3du5p35g6budnuotc",
"message": "Build {{repo.name}} sudah selesai"
}
trigger: trigger:
ref:
- refs/tags/devel_*
event: event:
exclude: exclude:
- promote - promote
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
name: kustomize name: deployment
clone:
disable: true
steps: steps:
- name: kustomize-testing - name: deployment
image: registry.k8s.io/kustomize/kustomize:v5.0.0 image: alpine
environment: failure: ignore
DEVOPS_SSH_PRIVATE:
from_secret: DEVOPS_SSH_PRIVATE
DEVOPS_SSH_PUBLIC:
from_secret: DEVOPS_SSH_PUBLIC
INFRASTRUCTURE_REPO: "k8s-kustomize-external"
DIRECTORY_NAME: "weplay-pos-testing"
commands: commands:
- mkdir -p ~/.ssh && - apk add --no-cache curl
- echo $DEVOPS_SSH_PRIVATE | base64 -d > ~/.ssh/id_rsa && - curl -X POST https://manager.sky.eigen.co.id/api/webhooks/806de7e2-1d3e-4889-b472-a59af0a5eb33
- echo $DEVOPS_SSH_PUBLIC | base64 -d > ~/.ssh/id_rsa.pub &&
- ssh-keyscan -H -p 2222 git.eigen.co.id >> ~/.ssh/known_hosts &&
- chmod 700 ~/.ssh/ &&
- chmod 600 ~/.ssh/id_rsa &&
- git clone ssh://git@git.eigen.co.id:2222/eigen/$INFRASTRUCTURE_REPO.git &&
- cd $INFRASTRUCTURE_REPO/$DIRECTORY_NAME
- kustomize edit set image registry.eigen.co.id/eigen/$DRONE_REPO_NAME=registry.eigen.co.id/eigen/$DRONE_REPO_NAME:$DRONE_TAG &&
- git add . &&
- |-
git commit -m "feat: update $DRONE_REPO_NAME testing to $DRONE_TAG" &&
- git push origin master
- name: send-message
image: harbor.eigen.co.id/docker.com/plugins/webhook
settings:
urls: https://mattermost.eigen.co.id/api/v4/posts
content_type: application/json
headers:
- Authorization=Bearer 5zubexudb38uuradfa36qy98ca
template: |
{
"channel_id": "s1ekqde1c3du5p35g6budnuotc",
"message": "ALERT: {{ repo.name }} gagal update dengan tag ${DRONE_TAG}"
}
when:
status:
- failure
trigger: trigger:
ref: ref:
include: - refs/tags/devel_*
- refs/tags/*-alpha.* event:
exclude:
- promote
depends_on: depends_on:
- server - build

View File

@ -1,38 +0,0 @@
kind: pipeline
type: docker
name: build
steps:
- name: build-dev
image: plugins/docker
settings:
registry: registry.eigen.co.id
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
build_args:
- env_target=env.development
tags: latest
custom_dns: 172.10.10.16
trigger:
ref:
- refs/tags/devel_*
event:
exclude:
- promote
---
kind: pipeline
type: docker
name: deployment
steps:
- name: deployment
image: alpine
failure: ignore
commands:
- apk add --no-cache curl
- curl -X POST https://manager.sky.eigen.co.id/api/webhooks/806de7e2-1d3e-4889-b472-a59af0a5eb33
trigger:
ref:
- refs/tags/devel_*
event:
exclude:
- promote
depends_on:
- build

View File

@ -5,11 +5,11 @@ COPY . .
RUN yarn install RUN yarn install
RUN yarn build RUN yarn build
FROM node:18.17-alpine FROM node:18.17-alpine
# ARG env_target ARG env_target
WORKDIR /app WORKDIR /app
# RUN echo ${env_target} RUN echo ${env_target}
# COPY env/$env_target /app/.env COPY env/$env_target /app/.env
# COPY --from=builder /app/env/$env_target .env COPY --from=builder /app/env/$env_target .env
COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
COPY --from=builder /app/assets ./assets COPY --from=builder /app/assets ./assets

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 KiB

9
env/env.development vendored
View File

@ -39,11 +39,4 @@ EXPORT_LIMIT_PARTITION=200
ASSETS="https://asset.sky.eigen.co.id/" ASSETS="https://asset.sky.eigen.co.id/"
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o" GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com" GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
SUPERSET_ADMIN_USERNAME=admin
SUPERSET_ADMIN_PASSWORD=admin
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV

9
env/env.production vendored
View File

@ -36,11 +36,4 @@ EXPORT_LIMIT_PARTITION=200
ASSETS="https://asset.sky.eigen.co.id/" ASSETS="https://asset.sky.eigen.co.id/"
GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o" GOOGLE_CALENDAR_KEY="AIzaSyCSg4P3uC9Z7kD1P4f3rf1BbBaz4Q-M55o"
GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com" GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec10bd5@group.calendar.google.com"
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
SUPERSET_ADMIN_USERNAME=admin
SUPERSET_ADMIN_PASSWORD=admin
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV

View File

@ -28,7 +28,6 @@
}, },
"dependencies": { "dependencies": {
"@faker-js/faker": "^8.4.1", "@faker-js/faker": "^8.4.1",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.0.0", "@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2", "@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.0.0",
@ -40,7 +39,6 @@
"@nestjs/typeorm": "^10.0.2", "@nestjs/typeorm": "^10.0.2",
"@types/multer": "^1.4.11", "@types/multer": "^1.4.11",
"algebra.js": "^0.2.6", "algebra.js": "^0.2.6",
"axios": "^1.7.5",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.1", "class-validator": "^0.14.1",
@ -49,7 +47,6 @@
"exceljs": "^4.4.0", "exceljs": "^4.4.0",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"googleapis": "^140.0.0", "googleapis": "^140.0.0",
"gtts": "^0.2.1",
"handlebars": "^4.7.8", "handlebars": "^4.7.8",
"mathjs": "^13.0.2", "mathjs": "^13.0.2",
"midtrans-client": "^1.3.1", "midtrans-client": "^1.3.1",

View File

@ -44,12 +44,7 @@ import { ItemRateModel } from './modules/item-related/item-rate/data/models/item
import { GoogleCalendarModule } from './modules/configuration/google-calendar/google-calendar.module'; import { GoogleCalendarModule } from './modules/configuration/google-calendar/google-calendar.module';
import { TransactionModule } from './modules/transaction/transaction/transaction.module'; import { TransactionModule } from './modules/transaction/transaction/transaction.module';
import { TransactionModel } from './modules/transaction/transaction/data/models/transaction.model'; import { TransactionModel } from './modules/transaction/transaction/data/models/transaction.model';
import { import { TransactionItemModel } from './modules/transaction/transaction/data/models/transaction-item.model';
TransactionBreakdownTaxModel,
TransactionItemBreakdownModel,
TransactionItemModel,
TransactionItemTaxModel,
} from './modules/transaction/transaction/data/models/transaction-item.model';
import { TransactionTaxModel } from './modules/transaction/transaction/data/models/transaction-tax.model'; import { TransactionTaxModel } from './modules/transaction/transaction/data/models/transaction-tax.model';
import { ReconciliationModule } from './modules/transaction/reconciliation/reconciliation.module'; import { ReconciliationModule } from './modules/transaction/reconciliation/reconciliation.module';
import { ReportModule } from './modules/reports/report/report.module'; import { ReportModule } from './modules/reports/report/report.module';
@ -76,23 +71,6 @@ import { BannerModel } from './modules/web-information/banner/data/models/banner
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'; import { PosLogModel } from './modules/configuration/log/data/models/pos-log.model';
import { ExportModule } from './modules/configuration/export/export.module'; import { ExportModule } from './modules/configuration/export/export.module';
import { TransactionDemographyModel } from './modules/transaction/transaction/data/models/transaction-demography.model';
import { SupersetModule } from './modules/configuration/superset/superset.module';
import { GateScanModule } from './modules/gates/gate.module';
import { UserLoginModel } from './modules/user-related/user/data/models/user-login.model';
import { LogUserLoginModel } from './modules/configuration/log/data/models/log-user-login.model';
import { AuthService } from './core/guards/domain/services/auth.service';
import { ReportSummaryModule } from './modules/reports/report-summary/report-summary.module';
import { QueueModule } from './modules/queue/queue.module';
import {
QueueOrderModel,
QueueTicketModel,
QueueItemModel,
QueueModel,
} from './modules/queue/data/models/queue.model';
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model';
@Module({ @Module({
imports: [ imports: [
@ -117,9 +95,7 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ItemModel, ItemModel,
ItemCategoryModel, ItemCategoryModel,
ItemRateModel, ItemRateModel,
ItemQueueModel,
LogModel, LogModel,
LogUserLoginModel,
NewsModel, NewsModel,
PaymentMethodModel, PaymentMethodModel,
PosLogModel, PosLogModel,
@ -133,26 +109,13 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
TransactionModel, TransactionModel,
TransactionItemModel, TransactionItemModel,
TransactionTaxModel, TransactionTaxModel,
TransactionDemographyModel,
TransactionItemBreakdownModel,
TransactionItemTaxModel,
TransactionBreakdownTaxModel,
UserModel, UserModel,
UserLoginModel,
VipCategoryModel, VipCategoryModel,
VipCodeModel, VipCodeModel,
// report // report
ReportBookmarkModel, ReportBookmarkModel,
ExportReportHistoryModel, ExportReportHistoryModel,
// Queue
QueueOrderModel,
QueueTicketModel,
QueueItemModel,
QueueModel,
QueueBucketModel,
], ],
synchronize: false, synchronize: false,
}), }),
@ -178,7 +141,6 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ItemCategoryModule, ItemCategoryModule,
ItemModule, ItemModule,
ItemRateModule, ItemRateModule,
ItemQueueModule,
// transaction // transaction
PaymentMethodModule, PaymentMethodModule,
@ -206,18 +168,9 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ReportModule, ReportModule,
ReportBookmarkModule, ReportBookmarkModule,
ReportExportModule, ReportExportModule,
ReportSummaryModule,
// superset
SupersetModule,
GateScanModule,
QueueModule,
], ],
controllers: [], controllers: [],
providers: [ providers: [
AuthService,
PrivilegeService, PrivilegeService,
/** /**
* By default all request from client will protect by JWT * By default all request from client will protect by JWT

View File

@ -7,10 +7,10 @@ import {
UnauthorizedException, UnauthorizedException,
} from '@nestjs/common'; } from '@nestjs/common';
import { Reflector } from '@nestjs/core'; import { Reflector } from '@nestjs/core';
import { Observable } from 'rxjs';
import { SessionService, UsersSession } from 'src/core/sessions'; import { SessionService, UsersSession } from 'src/core/sessions';
import { UNPROTECTED_URL } from '../constants'; import { UNPROTECTED_URL } from '../constants';
import { PrivilegeService } from './services/privilege.service'; import { PrivilegeService } from './services/privilege.service';
import { AuthService } from './services/auth.service';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class JWTGuard implements CanActivate { export class JWTGuard implements CanActivate {
@ -18,13 +18,14 @@ export class JWTGuard implements CanActivate {
protected readonly session: SessionService, protected readonly session: SessionService,
protected readonly reflector: Reflector, protected readonly reflector: Reflector,
protected readonly privilege: PrivilegeService, protected readonly privilege: PrivilegeService,
protected readonly authService: AuthService,
) {} ) {}
protected isPublic = false; protected isPublic = false;
protected userSession: UsersSession; protected userSession: UsersSession;
async canActivate(context: ExecutionContext) { canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
/** /**
* Check if access url is protected or not * Check if access url is protected or not
* By default `isUnprotected` equals `false` * By default `isUnprotected` equals `false`
@ -60,29 +61,9 @@ export class JWTGuard implements CanActivate {
*/ */
try { try {
this.userSession = this.session.verifyToken(token); this.userSession = this.session.verifyToken(token);
await this.authService.verifyRegisteredLoginToken(token);
Logger.log(`Access from ${this.userSession.name}`, 'AuthGuard'); Logger.log(`Access from ${this.userSession.name}`, 'AuthGuard');
return true; return true;
} catch (error) { } catch (error) {
const expiredError = error.message;
if (expiredError === 'jwt expired') {
const [, body] = token.split('.');
const bodyToken = JSON.parse(atob(body));
const user = {
role: bodyToken.role,
user_id: bodyToken.id,
username: bodyToken.username,
user_privilege_id: bodyToken.user_privilege_id,
item_id: bodyToken.item_id,
item_name: bodyToken.item_name,
source: bodyToken.source,
};
this.authService.logoutUser(user, token);
}
throw new UnauthorizedException({ throw new UnauthorizedException({
code: 10001, code: 10001,
message: message:

View File

@ -9,7 +9,7 @@ import { MAIN_MENU } from '../constants';
@Injectable() @Injectable()
export class RolesGuard extends JWTGuard { export class RolesGuard extends JWTGuard {
async canActivate(context: ExecutionContext): Promise<boolean> { async canActivate(context: ExecutionContext): Promise<boolean> {
await super.canActivate(context); super.canActivate(context);
// jika endpoint tersebut bukan public, maka lakukan check lanjutan // jika endpoint tersebut bukan public, maka lakukan check lanjutan
if (!this.isPublic) { if (!this.isPublic) {

View File

@ -1,78 +0,0 @@
import {
HttpStatus,
Injectable,
Scope,
UnauthorizedException,
} from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import {
CONNECTION_NAME,
OPERATION,
} from 'src/core/strings/constants/base.constants';
import { DataSource } from 'typeorm';
import { UserRole } from 'src/modules/user-related/user/constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { AppSource, LogUserType } from 'src/core/helpers/constant';
import { EventBus } from '@nestjs/cqrs';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
interface UserEntity {
user_id: string;
username: string;
role: UserRole;
user_privilege_id: string;
item_id: string;
item_name: string;
source: AppSource;
}
@Injectable({ scope: Scope.REQUEST })
export class AuthService {
constructor(
@InjectDataSource(CONNECTION_NAME.DEFAULT)
protected readonly dataSource: DataSource,
private eventBus: EventBus,
) {}
get repository() {
return this.dataSource.getRepository(UserLoginModel);
}
async logoutUser(user: UserEntity, token: string) {
await this.repository.delete({ login_token: token });
const userLogout = {
type: LogUserType.logout,
created_at: new Date().getTime(),
name: user.username,
user_privilege_id: user.user_privilege_id,
...user,
};
this.eventBus.publish(
new LogUserLoginEvent({
id: user.user_id,
old: null,
data: userLogout,
user: userLogout as any,
description: 'Logout',
module: UserModel.name,
op: OPERATION.UPDATE,
}),
);
}
async verifyRegisteredLoginToken(token: string) {
const data = await this.repository.findOneBy({ login_token: token });
if (!data) {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `Invalid token`,
error: 'Unauthorized',
});
}
}
}

View File

@ -1,11 +0,0 @@
export enum LogUserType {
login = 'login',
logout = 'logout',
}
export enum AppSource {
POS_ADMIN = 'POS_ADMIN',
POS_COUNTER = 'POS_COUNTER',
QUEUE_ADMIN = 'QUEUE_ADMIN',
QUEUE_CUSTOMER = 'QUEUE_CUSTOMER',
}

View File

@ -8,9 +8,7 @@ import { diskStorage } from 'multer';
const MB = 1024 * 1024; const MB = 1024 * 1024;
const fileFilter = (req, file, callback) => { const fileFilter = (req, file, callback) => {
if ( if (file.mimetype.match(/\/(jpg|jpeg|png)$/)) {
file.mimetype.match(/\/(jpg|jpeg|png|flv|mp4|m3u8|ts|3gp|mov|avi|wmv)$/)
) {
callback(null, true); callback(null, true);
} else { } else {
callback( callback(

View File

@ -32,7 +32,7 @@ export abstract class BaseManager {
setUser() { setUser() {
try { try {
this.user = this.userProvider?.user ?? BLANK_USER; this.user = this.userProvider?.user;
} catch (error) { } catch (error) {
this.user = BLANK_USER; this.user = BLANK_USER;
} }

View File

@ -71,7 +71,7 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
} }
async publishEvents() { async publishEvents() {
this.eventBus?.publish( this.eventBus.publish(
new RecordLog({ new RecordLog({
id: this.result['id'], id: this.result['id'],
old: null, old: null,

View File

@ -50,7 +50,7 @@ export abstract class BaseIndexManager<Entity> extends BaseReadManager {
// jika searching status terdapat dalam enum, maka dia mencari specific data // jika searching status terdapat dalam enum, maka dia mencari specific data
// ? karena jika tidak, ketika dia search "active" maka "inactive" juga ikut // ? karena jika tidak, ketika dia search "active" maka "inactive" juga ikut
return `'${STATUS[statusData.toUpperCase()]}'`; return `'${STATUS[statusData.toUpperCase()]}'` ?? `'%${statusData}%'`;
}); });
const exist = specificFilter.find((item) => item.isStatus); const exist = specificFilter.find((item) => item.isStatus);

View File

@ -1,10 +1,6 @@
import { ValidateRelationHelper } from 'src/core/helpers/validation/validate-relation.helper'; import { ValidateRelationHelper } from 'src/core/helpers/validation/validate-relation.helper';
import { BaseManager } from '../base.manager'; import { BaseManager } from '../base.manager';
import { import { OPERATION, STATUS } from 'src/core/strings/constants/base.constants';
OPERATION,
QUEUE_STATUS,
STATUS,
} from 'src/core/strings/constants/base.constants';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { RecordLog } from 'src/modules/configuration/log/domain/entities/log.event'; import { RecordLog } from 'src/modules/configuration/log/domain/entities/log.event';
@ -12,12 +8,12 @@ export abstract class BaseUpdateStatusManager<Entity> extends BaseManager {
protected dataId: string; protected dataId: string;
protected result: Entity; protected result: Entity;
protected oldData: Entity; protected oldData: Entity;
protected dataStatus: STATUS | QUEUE_STATUS; protected dataStatus: STATUS;
protected relations = []; protected relations = [];
protected duplicateColumn: string[]; protected duplicateColumn: string[];
abstract get entityTarget(): any; abstract get entityTarget(): any;
setData(id: string, status: STATUS | QUEUE_STATUS): void { setData(id: string, status: STATUS): void {
/** /**
* // TODO: Handle case confirm multiple tabs; * // TODO: Handle case confirm multiple tabs;
* Pola id yang dikirim dirubah menjadi data_id___updated_at * Pola id yang dikirim dirubah menjadi data_id___updated_at

View File

@ -23,7 +23,6 @@ export class BaseFilterDto implements BaseFilterEntity {
@IsNumber() @IsNumber()
limit = 10; limit = 10;
@ApiProperty({ type: String, required: false })
q: string; q: string;
@ApiProperty({ type: ['string'], required: false }) @ApiProperty({ type: ['string'], required: false })

View File

@ -1,2 +1 @@
export const PAGINATION_RESPONSE = 'PAGINATION_RESPONSE'; export const PAGINATION_RESPONSE = 'PAGINATION_RESPONSE';
export const GATE_RESPONSE = 'GATE_RESPONSE';

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common'; import { SetMetadata } from '@nestjs/common';
import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../../constants'; import { PAGINATION_RESPONSE } from '../../constants';
/** /**
* This decorator will tell the response, * This decorator will tell the response,
@ -7,5 +7,3 @@ import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../../constants';
*/ */
export const Pagination = (isPagination = true) => export const Pagination = (isPagination = true) =>
SetMetadata(PAGINATION_RESPONSE, isPagination); SetMetadata(PAGINATION_RESPONSE, isPagination);
export const Gate = () => SetMetadata(GATE_RESPONSE, true);

View File

@ -8,20 +8,13 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { Request } from 'express'; import { Request } from 'express';
import { Reflector } from '@nestjs/core'; import { Reflector } from '@nestjs/core';
import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../constants'; import { PAGINATION_RESPONSE } from '../constants';
import { createPaginationResponse } from './utils/pagination-meta.helper'; import { createPaginationResponse } from './utils/pagination-meta.helper';
@Injectable() @Injectable()
export class TransformInterceptor implements NestInterceptor { export class TransformInterceptor implements NestInterceptor {
constructor(protected readonly reflector: Reflector) {} constructor(protected readonly reflector: Reflector) {}
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const isGate = this.reflector.getAllAndOverride<boolean>(GATE_RESPONSE, [
context.getHandler(),
context.getClass(),
]);
if (isGate) return next.handle();
const isPagination = this.reflector.getAllAndOverride<boolean>( const isPagination = this.reflector.getAllAndOverride<boolean>(
PAGINATION_RESPONSE, PAGINATION_RESPONSE,
[context.getHandler(), context.getClass()], [context.getHandler(), context.getClass()],

View File

@ -1,11 +1,8 @@
import { AppSource } from 'src/core/helpers/constant';
import { UserRole } from 'src/modules/user-related/user/constants'; import { UserRole } from 'src/modules/user-related/user/constants';
export interface UsersSession { export interface UsersSession {
id: number; id: number;
name: string; name: string;
role: UserRole; role: UserRole;
source?: AppSource;
item_id?: string;
user_privilege_id: string; user_privilege_id: string;
} }

View File

@ -23,9 +23,4 @@ export class UserProvider {
const [, token] = this.request.headers['authorization'].split(' '); const [, token] = this.request.headers['authorization'].split(' ');
return this.session.verifyToken(token); return this.session.verifyToken(token);
} }
get token(): string {
const [, token] = this.request.headers['authorization'].split(' ');
return token;
}
} }

View File

@ -15,11 +15,6 @@ export enum STATUS {
WAITING = 'waiting', WAITING = 'waiting',
} }
export enum QUEUE_STATUS {
DONE = 'done',
CALLED = 'called',
}
export enum ORDER_TYPE { export enum ORDER_TYPE {
ASC = 'ASC', ASC = 'ASC',
DESC = 'DESC', DESC = 'DESC',

View File

@ -4,7 +4,6 @@ export enum MODULE_NAME {
GATE = 'gates', GATE = 'gates',
ITEM = 'items', ITEM = 'items',
ITEM_CATEGORY = 'item-categories', ITEM_CATEGORY = 'item-categories',
ITEM_QUEUE = 'item-queues',
ITEM_RATE = 'item-rates', ITEM_RATE = 'item-rates',
NEWS = 'news', NEWS = 'news',
PAYMENT_METHOD = 'payment-methods', PAYMENT_METHOD = 'payment-methods',
@ -25,7 +24,4 @@ export enum MODULE_NAME {
REPORT = 'report', REPORT = 'report',
REPORT_BOOKMARK = 'report-bookmark', REPORT_BOOKMARK = 'report-bookmark',
REPORT_EXPORT = 'report-export', REPORT_EXPORT = 'report-export',
REPORT_SUMMARY = 'report-summary',
QUEUE = 'queue',
} }

View File

@ -4,7 +4,6 @@ export enum TABLE_NAME {
FAQ = 'faqs', FAQ = 'faqs',
ITEM = 'items', ITEM = 'items',
ITEM_CATEGORY = 'item_categories', ITEM_CATEGORY = 'item_categories',
ITEM_QUEUE = 'item_queues',
ITEM_RATE = 'item_rates', ITEM_RATE = 'item_rates',
GATE = 'gates', GATE = 'gates',
LOG = 'logs', LOG = 'logs',
@ -21,14 +20,8 @@ export enum TABLE_NAME {
TENANT = 'tenants', TENANT = 'tenants',
TRANSACTION = 'transactions', TRANSACTION = 'transactions',
TRANSACTION_ITEM = 'transaction_items', TRANSACTION_ITEM = 'transaction_items',
TRANSACTION_ITEM_BREAKDOWN = 'transaction_item_breakdowns',
TRANSACTION_TAX = 'transaction_taxes', TRANSACTION_TAX = 'transaction_taxes',
TRANSACTION_ITEM_TAX = 'transaction_item_taxes',
TRANSACTION_ITEM_BREAKDOWN_TAX = 't_breakdown_item_taxes',
TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
USER = 'users', USER = 'users',
USER_LOGIN = 'users_login',
LOG_USER_LOGIN = 'log_users_login',
USER_PRIVILEGE = 'user_privileges', USER_PRIVILEGE = 'user_privileges',
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations', USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
VIP_CATEGORY = 'vip_categories', VIP_CATEGORY = 'vip_categories',
@ -36,10 +29,4 @@ export enum TABLE_NAME {
REPORT_BOOKMARK = 'report_bookmark', REPORT_BOOKMARK = 'report_bookmark',
EXPORT_REPORT_HISTORY = 'export_report_history', EXPORT_REPORT_HISTORY = 'export_report_history',
QUEUE = 'queues',
QUEUE_ORDER = 'queue_orders',
QUEUE_TICKET = 'queue_tickets',
QUEUE_ITEM = 'queue_items',
QUEUE_BUCKET = 'queue_bucket',
} }

View File

@ -1,13 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddItemProfit1723706764654 implements MigrationInterface {
name = 'AddItemProfit1723706764654';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "items" ADD "share_profit" numeric`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "share_profit"`);
}
}

View File

@ -1,85 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddItemProfit1723706764654 implements MigrationInterface {
name = 'AddOtherType1723706764655';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" ADD "breakdown_bundling" boolean NOT NULL DEFAULT false`,
);
await queryRunner.query(
`ALTER TYPE "public"."item_categories_item_type_enum" RENAME TO "item_categories_item_type_enum_old"`,
);
await queryRunner.query(
`CREATE TYPE "public"."item_categories_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum" USING "item_type"::"text"::"public"."item_categories_item_type_enum"`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
);
await queryRunner.query(
`DROP TYPE "public"."item_categories_item_type_enum_old"`,
);
await queryRunner.query(
`ALTER TYPE "public"."items_item_type_enum" RENAME TO "items_item_type_enum_old"`,
);
await queryRunner.query(
`CREATE TYPE "public"."items_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum" USING "item_type"::"text"::"public"."items_item_type_enum"`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
);
await queryRunner.query(`DROP TYPE "public"."items_item_type_enum_old"`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."items_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" TYPE "public"."items_item_type_enum_old" USING "item_type"::"text"::"public"."items_item_type_enum_old"`,
);
await queryRunner.query(
`ALTER TABLE "items" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
);
await queryRunner.query(`DROP TYPE "public"."items_item_type_enum"`);
await queryRunner.query(
`ALTER TYPE "public"."items_item_type_enum_old" RENAME TO "items_item_type_enum"`,
);
await queryRunner.query(
`CREATE TYPE "public"."item_categories_item_type_enum_old" AS ENUM('bundling', 'free gift', 'tiket masuk', 'wahana')`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" TYPE "public"."item_categories_item_type_enum_old" USING "item_type"::"text"::"public"."item_categories_item_type_enum_old"`,
);
await queryRunner.query(
`ALTER TABLE "item_categories" ALTER COLUMN "item_type" SET DEFAULT 'tiket masuk'`,
);
await queryRunner.query(
`DROP TYPE "public"."item_categories_item_type_enum"`,
);
await queryRunner.query(
`ALTER TYPE "public"."item_categories_item_type_enum_old" RENAME TO "item_categories_item_type_enum"`,
);
await queryRunner.query(
`ALTER TABLE "items" DROP COLUMN "breakdown_bundling"`,
);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddDemographyTransaction1723713873756
implements MigrationInterface
{
name = 'AddDemographyTransaction1723713873756';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "transaction_demographies" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "man" integer NOT NULL DEFAULT '0', "woman" integer NOT NULL DEFAULT '0', "teen" integer NOT NULL DEFAULT '0', "child" integer NOT NULL DEFAULT '0', "local" integer NOT NULL DEFAULT '0', "foreign" integer NOT NULL DEFAULT '0', "transaction_id" uuid, CONSTRAINT "PK_84083b782ebc2c6cb2a2dab8e2d" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
);
await queryRunner.query(`DROP TABLE "transaction_demographies"`);
}
}

View File

@ -1,49 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class FixDemographyNationality1723716561482
implements MigrationInterface
{
name = 'FixDemographyNationality1723716561482';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP COLUMN "local"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP COLUMN "foreign"`,
);
await queryRunner.query(
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign', 'mix')`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD "nationality" "public"."transaction_demographies_nationality_enum" NOT NULL DEFAULT 'local'`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP CONSTRAINT "FK_a2b705884bca06c148e3b35ab04"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD CONSTRAINT "FK_a2b705884bca06c148e3b35ab04" FOREIGN KEY ("transaction_id") REFERENCES "transactions"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" DROP COLUMN "nationality"`,
);
await queryRunner.query(
`DROP TYPE "public"."transaction_demographies_nationality_enum"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD "foreign" integer NOT NULL DEFAULT '0'`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ADD "local" integer NOT NULL DEFAULT '0'`,
);
}
}

View File

@ -1,17 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddEstimationToItem1723801180604 implements MigrationInterface {
name = 'AddEstimationToItem1723801180604';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" ADD "play_estimation" numeric`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" DROP COLUMN "play_estimation"`,
);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddBreakdownItemTransaction1724127202672
implements MigrationInterface
{
name = 'AddBreakdownItemTransaction1724127202672';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "transaction_item_breakdowns" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "item_id" character varying NOT NULL, "item_name" character varying NOT NULL, "hpp" bigint, "base_price" bigint, "item_rates" bigint, "transaction_item_id" uuid, CONSTRAINT "PK_e04a30c648d3ba8778e9fb67fdd" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD CONSTRAINT "FK_b8c63b1f3ecace500587da713ae" FOREIGN KEY ("transaction_item_id") REFERENCES "transaction_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP CONSTRAINT "FK_b8c63b1f3ecace500587da713ae"`,
);
await queryRunner.query(`DROP TABLE "transaction_item_breakdowns"`);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddBreakdownToTransactionItem1724233193743
implements MigrationInterface
{
name = 'AddBreakdownToTransactionItem1724233193743';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "breakdown_bundling" boolean NOT NULL DEFAULT false`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "breakdown_bundling"`,
);
}
}

View File

@ -1,47 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddValueToDemography1724240624025 implements MigrationInterface {
name = 'AddValueToDemography1724240624025';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TYPE "public"."transaction_demographies_nationality_enum" RENAME TO "transaction_demographies_nationality_enum_old"`,
);
await queryRunner.query(
`CREATE TYPE "public"."transaction_demographies_nationality_enum" AS ENUM('local', 'foreign', 'mix', 'foreigner')`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" TYPE "public"."transaction_demographies_nationality_enum" USING "nationality"::"text"::"public"."transaction_demographies_nationality_enum"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" SET DEFAULT 'local'`,
);
await queryRunner.query(
`DROP TYPE "public"."transaction_demographies_nationality_enum_old"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."transaction_demographies_nationality_enum_old" AS ENUM('local', 'foreign', 'mix')`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" TYPE "public"."transaction_demographies_nationality_enum_old" USING "nationality"::"text"::"public"."transaction_demographies_nationality_enum_old"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_demographies" ALTER COLUMN "nationality" SET DEFAULT 'local'`,
);
await queryRunner.query(
`DROP TYPE "public"."transaction_demographies_nationality_enum"`,
);
await queryRunner.query(
`ALTER TYPE "public"."transaction_demographies_nationality_enum_old" RENAME TO "transaction_demographies_nationality_enum"`,
);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddValueVariableFormula1724926316235
implements MigrationInterface
{
name = 'AddValueVariableFormula1724926316235';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "price_formulas" ADD "value_for" character varying NOT NULL DEFAULT 'dpp'`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "price_formulas" DROP COLUMN "value_for"`,
);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddPaymentDateBankColumnAtTransaction1725962197762
implements MigrationInterface
{
name = 'AddPaymentDateBankColumnAtTransaction1725962197762';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transactions" ADD "payment_date_bank" date`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transactions" DROP COLUMN "payment_date_bank"`,
);
}
}

View File

@ -1,21 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddPosNameColumn1726033041774 implements MigrationInterface {
name = 'AddPosNameColumn1726033041774';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transactions" ADD "creator_counter_name" character varying`,
);
await queryRunner.query(
`ALTER TABLE "logs_pos" ADD "pos_name" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "logs_pos" DROP COLUMN "pos_name"`);
await queryRunner.query(
`ALTER TABLE "transactions" DROP COLUMN "creator_counter_name"`,
);
}
}

View File

@ -1,43 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddFlagRoleQueue1726041175749 implements MigrationInterface {
name = 'AddFlagRoleQueue1726041175749';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TYPE "public"."users_role_enum" RENAME TO "users_role_enum_old"`,
);
await queryRunner.query(
`CREATE TYPE "public"."users_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" TYPE "public"."users_role_enum" USING "role"::"text"::"public"."users_role_enum"`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'staff'`,
);
await queryRunner.query(`DROP TYPE "public"."users_role_enum_old"`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."users_role_enum_old" AS ENUM('superadmin', 'staff', 'tenant')`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" TYPE "public"."users_role_enum_old" USING "role"::"text"::"public"."users_role_enum_old"`,
);
await queryRunner.query(
`ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'staff'`,
);
await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
await queryRunner.query(
`ALTER TYPE "public"."users_role_enum_old" RENAME TO "users_role_enum"`,
);
}
}

View File

@ -1,73 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTaxItemTransaction1726045820711 implements MigrationInterface {
name = 'AddTaxItemTransaction1726045820711';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "transaction_item_taxes" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "tax_id" character varying, "tax_name" character varying, "taxt_value" numeric, "tax_total_value" numeric, "transaction_id" uuid, CONSTRAINT "PK_fc5f6da61b24eb5bfdd503b0a0d" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "t_breakdown_item_taxes" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "tax_id" character varying, "tax_name" character varying, "taxt_value" numeric, "tax_total_value" numeric, "transaction_id" uuid, CONSTRAINT "PK_a1ef08d2c68169a50102aa70eca" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "total_profit_share" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "total_profit_share" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_taxes" ADD CONSTRAINT "FK_f5c4966a381d903899cafb4b5ba" FOREIGN KEY ("transaction_id") REFERENCES "transaction_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "t_breakdown_item_taxes" ADD CONSTRAINT "FK_74bedce7e94f6707ddf26ef0c0f" FOREIGN KEY ("transaction_id") REFERENCES "transaction_item_breakdowns"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "payment_total_dpp" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "payment_total_dpp" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "payment_total_tax" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "payment_total_tax" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "total_share_tenant" numeric`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "t_breakdown_item_taxes" DROP CONSTRAINT "FK_74bedce7e94f6707ddf26ef0c0f"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_taxes" DROP CONSTRAINT "FK_f5c4966a381d903899cafb4b5ba"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "total_profit_share"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "total_profit_share"`,
);
await queryRunner.query(`DROP TABLE "t_breakdown_item_taxes"`);
await queryRunner.query(`DROP TABLE "transaction_item_taxes"`);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "payment_total_dpp"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "payment_total_dpp"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "payment_total_tax"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "payment_total_tax"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "total_share_tenant"`,
);
}
}

View File

@ -1,21 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTableUserLogin1726115025759 implements MigrationInterface {
name = 'AddTableUserLogin1726115025759';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "login_date" bigint NOT NULL, "login_token" character varying, "user_id" uuid, CONSTRAINT "REL_2a80a213b51423ce5b8211f058" UNIQUE ("user_id"), CONSTRAINT "PK_e564194a9a22f8c623354284f75" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(`DROP TABLE "users_login"`);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class UpdateTableUserLogin1726122619596 implements MigrationInterface {
name = 'UpdateTableUserLogin1726122619596';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTableLogUserLogin1726123955427 implements MigrationInterface {
name = 'AddTableLogUserLogin1726123955427';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."log_users_login_type_enum" AS ENUM('login', 'logout')`,
);
await queryRunner.query(
`CREATE TYPE "public"."log_users_login_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
);
await queryRunner.query(
`CREATE TABLE "log_users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."log_users_login_type_enum", "role" "public"."log_users_login_role_enum", "user_id" uuid, "username" character varying, "created_at" bigint, CONSTRAINT "PK_75141588aa6ee560504f7d3adce" PRIMARY KEY ("id"))`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "log_users_login"`);
await queryRunner.query(`DROP TYPE "public"."log_users_login_role_enum"`);
await queryRunner.query(`DROP TYPE "public"."log_users_login_type_enum"`);
}
}

View File

@ -1,17 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddColumnItemId1726139426994 implements MigrationInterface {
name = 'AddColumnItemId1726139426994';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users_login" ADD "item_id" uuid`);
await queryRunner.query(`ALTER TABLE "log_users_login" ADD "item_id" uuid`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "log_users_login" DROP COLUMN "item_id"`,
);
await queryRunner.query(`ALTER TABLE "users_login" DROP COLUMN "item_id"`);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddColumnItemName1726141393404 implements MigrationInterface {
name = 'AddColumnItemName1726141393404';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" ADD "item_name" character varying`,
);
await queryRunner.query(
`ALTER TABLE "log_users_login" ADD "item_name" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "log_users_login" DROP COLUMN "item_name"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" DROP COLUMN "item_name"`,
);
}
}

View File

@ -1,17 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddFormulaToTax1726365023179 implements MigrationInterface {
name = 'AddFormulaToTax1726365023179';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "taxes" ADD "formula_render" json`);
await queryRunner.query(
`ALTER TABLE "taxes" ADD "formula_string" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "taxes" DROP COLUMN "formula_string"`);
await queryRunner.query(`ALTER TABLE "taxes" DROP COLUMN "formula_render"`);
}
}

View File

@ -1,35 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ChangeUserLoginRelation1726642119207
implements MigrationInterface
{
name = 'ChangeUserLoginRelation1726642119207';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "refresh_token"`);
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "REL_2a80a213b51423ce5b8211f058"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "REL_2a80a213b51423ce5b8211f058" UNIQUE ("user_id")`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "users" ADD "refresh_token" character varying`,
);
}
}

View File

@ -1,29 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddColumnSourceAtUserLogin1726642499135
implements MigrationInterface
{
name = 'AddColumnSourceAtUserLogin1726642499135';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."users_login_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD "role" "public"."users_login_role_enum"`,
);
await queryRunner.query(
`CREATE TYPE "public"."users_login_source_enum" AS ENUM('POS_ADMIN', 'POS_COUNTER', 'QUEUE_ADMIN', 'QUEUE_CUSTOMER')`,
);
await queryRunner.query(
`ALTER TABLE "users_login" ADD "source" "public"."users_login_source_enum"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "users_login" DROP COLUMN "source"`);
await queryRunner.query(`DROP TYPE "public"."users_login_source_enum"`);
await queryRunner.query(`ALTER TABLE "users_login" DROP COLUMN "role"`);
await queryRunner.query(`DROP TYPE "public"."users_login_role_enum"`);
}
}

View File

@ -1,21 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddSourceOnLogLogin1726647442006 implements MigrationInterface {
name = 'AddSourceOnLogLogin1726647442006';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."log_users_login_source_enum" AS ENUM('POS_ADMIN', 'POS_COUNTER', 'QUEUE_ADMIN', 'QUEUE_CUSTOMER')`,
);
await queryRunner.query(
`ALTER TABLE "log_users_login" ADD "source" "public"."log_users_login_source_enum"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "log_users_login" DROP COLUMN "source"`,
);
await queryRunner.query(`DROP TYPE "public"."log_users_login_source_enum"`);
}
}

View File

@ -1,43 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddDiscountForItemTransaction1726824289989
implements MigrationInterface
{
name = 'AddDiscountForItemTransaction1726824289989';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "subtotal" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "discount_value" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "subtotal" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "discount_value" numeric`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" ADD "total_price" numeric`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "total_price"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "discount_value"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" DROP COLUMN "subtotal"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "discount_value"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "subtotal"`,
);
}
}

View File

@ -1,23 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ChangeColumnName1726830293878 implements MigrationInterface {
name = 'ChangeColumnName1726830293878';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_items" RENAME COLUMN "subtotal" TO "total_net_price"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" RENAME COLUMN "subtotal" TO "total_net_price"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_item_breakdowns" RENAME COLUMN "total_net_price" TO "subtotal"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" RENAME COLUMN "total_net_price" TO "subtotal"`,
);
}
}

View File

@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddDiscountValueToVoucher1728377112337
implements MigrationInterface
{
name = 'AddDiscountValueToVoucher1728377112337';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "vip_codes" ADD "discount_value" numeric`,
);
await queryRunner.query(
`ALTER TABLE "vip_codes" ALTER COLUMN "discount" DROP NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "vip_codes" ALTER COLUMN "discount" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "vip_codes" DROP COLUMN "discount_value"`,
);
}
}

View File

@ -1,21 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ItemVideoAndVipPass1729072422409 implements MigrationInterface {
name = 'ItemVideoAndVipPass1729072422409';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" ADD "video_url" character varying`,
);
await queryRunner.query(
`ALTER TABLE "vip_categories" ADD "has_vip_pass" boolean NOT NULL DEFAULT false`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "vip_categories" DROP COLUMN "has_vip_pass"`,
);
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "video_url"`);
}
}

View File

@ -1,43 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class QueueTable1729151429165 implements MigrationInterface {
name = 'QueueTable1729151429165';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "queue_orders" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "code" character varying NOT NULL, "customer" character varying, "phone" character varying, "date" bigint NOT NULL, CONSTRAINT "PK_b139e4cc9ca3e709c152f820d2e" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "queue_tickets" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "code" character varying NOT NULL, "customer" character varying, "phone" character varying, "date" bigint NOT NULL, "order_id" uuid, CONSTRAINT "PK_1b903aa90bcc04136caa6540c55" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "queue_items" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "qty" integer NOT NULL, "ticket_id" uuid, "item_id" uuid, CONSTRAINT "PK_2245e11ac3517494bacfe932773" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "queue_tickets" ADD CONSTRAINT "FK_0e9823b8b7ca9523b3be73878e5" FOREIGN KEY ("order_id") REFERENCES "queue_orders"("id") ON DELETE SET NULL ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "queue_items" ADD CONSTRAINT "FK_25352739034765f6917757df74b" FOREIGN KEY ("ticket_id") REFERENCES "queue_tickets"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "queue_items" ADD CONSTRAINT "FK_ab15c053aeb4f739ebf533b61cd" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queue_items" DROP CONSTRAINT "FK_ab15c053aeb4f739ebf533b61cd"`,
);
await queryRunner.query(
`ALTER TABLE "queue_items" DROP CONSTRAINT "FK_25352739034765f6917757df74b"`,
);
await queryRunner.query(
`ALTER TABLE "queue_tickets" DROP CONSTRAINT "FK_0e9823b8b7ca9523b3be73878e5"`,
);
await queryRunner.query(`DROP TABLE "queue_items"`);
await queryRunner.query(`DROP TABLE "queue_tickets"`);
await queryRunner.query(`DROP TABLE "queue_orders"`);
}
}

View File

@ -1,18 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class VideoUrlToJson1729248576381 implements MigrationInterface {
name = 'VideoUrlToJson1729248576381';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "video_url"`);
await queryRunner.query(`ALTER TABLE "items" ADD "video_url" json`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "video_url"`);
await queryRunner.query(
`ALTER TABLE "items" ADD "video_url" character varying`,
);
await queryRunner.query(`DROP TABLE "item_queues"`);
}
}

View File

@ -1,33 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ItemQueues1729570177597 implements MigrationInterface {
name = 'ItemQueues1729570177597';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."item_queues_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'partial refund', 'pending', 'proses refund', 'refunded', 'rejected', 'settled', 'waiting')`,
);
await queryRunner.query(
`CREATE TYPE "public"."item_queues_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift', 'other')`,
);
await queryRunner.query(
`CREATE TABLE "item_queues" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "status" "public"."item_queues_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, "item_type" "public"."item_queues_item_type_enum" NOT NULL DEFAULT 'tiket masuk', CONSTRAINT "PK_e19adb0b99d995e8f10c189985f" PRIMARY KEY ("id"))`,
);
await queryRunner.query(`ALTER TABLE "items" ADD "item_queue_id" uuid`);
await queryRunner.query(
`ALTER TABLE "items" ADD CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c" FOREIGN KEY ("item_queue_id") REFERENCES "item_queues"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" DROP CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c"`,
);
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "item_queue_id"`);
await queryRunner.query(`DROP TABLE "item_queues"`);
await queryRunner.query(`DROP TYPE "public"."item_queues_item_type_enum"`);
await queryRunner.query(`DROP TYPE "public"."item_queues_status_enum"`);
}
}

View File

@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ItemQueueOnDelete1729582398827 implements MigrationInterface {
name = 'ItemQueueOnDelete1729582398827';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" DROP CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c"`,
);
await queryRunner.query(
`ALTER TABLE "items" ADD CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c" FOREIGN KEY ("item_queue_id") REFERENCES "item_queues"("id") ON DELETE SET NULL ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" DROP CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c"`,
);
await queryRunner.query(
`ALTER TABLE "items" ADD CONSTRAINT "FK_2cbbeb03e176addcf60d65f7c9c" FOREIGN KEY ("item_queue_id") REFERENCES "item_queues"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTransactionIdToQueueOrder1729653046392
implements MigrationInterface
{
name = 'AddTransactionIdToQueueOrder1729653046392';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queue_orders" ADD "transaction_id" character varying NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queue_orders" DROP COLUMN "transaction_id"`,
);
}
}

View File

@ -1,22 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddQueueTable1729756969674 implements MigrationInterface {
name = 'AddQueueTable1729756969674';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "queues" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "code" character varying NOT NULL, "status" character varying NOT NULL, "time" bigint NOT NULL, "call_time" bigint NOT NULL, "vip" boolean NOT NULL, "item_id" uuid NOT NULL, "qty" integer NOT NULL, CONSTRAINT "PK_d966f9eb39a9396658387071bb3" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD CONSTRAINT "FK_435954e9a0d9967f17e043d54b4" FOREIGN KEY ("item_id") REFERENCES "queue_items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" DROP CONSTRAINT "FK_435954e9a0d9967f17e043d54b4"`,
);
await queryRunner.query(`DROP TABLE "queues"`);
}
}

View File

@ -1,39 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddQueueBaseModel1729838994129 implements MigrationInterface {
name = 'AddQueueBaseModel1729838994129';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" ADD "creator_id" character varying(36)`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD "creator_name" character varying(125)`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD "editor_id" character varying(36)`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD "editor_name" character varying(125)`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD "created_at" bigint NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "queues" ADD "updated_at" bigint NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" ALTER COLUMN "call_time" DROP NOT NULL`,
);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "updated_at"`);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "created_at"`);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "editor_name"`);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "editor_id"`);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "creator_name"`);
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "creator_id"`);
}
}

View File

@ -1,15 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddQueueBucket1730859187883 implements MigrationInterface {
name = 'AddQueueBucket1730859187883';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "queue_bucket" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "queue_item_id" character varying NOT NULL, "date" bigint NOT NULL, "regular" integer NOT NULL, "vip" integer NOT NULL, CONSTRAINT "PK_cdd58b0d9e93e4be922da9d8bd6" PRIMARY KEY ("id"))`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "queue_bucket"`);
}
}

View File

@ -1,50 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddTransactionAndItemRelation1731383726542
implements MigrationInterface
{
name = 'AddTransactionAndItemRelation1731383726542';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "item_id" uuid`,
);
await queryRunner.query(
`ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
);
await queryRunner.query(
`ALTER TABLE "transactions" ADD "customer_category_id" uuid`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "transactions" ADD CONSTRAINT "FK_08dc8138714894a66e94820766d" FOREIGN KEY ("customer_category_id") REFERENCES "vip_categories"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "transactions" DROP CONSTRAINT "FK_08dc8138714894a66e94820766d"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc"`,
);
await queryRunner.query(
`ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
);
await queryRunner.query(
`ALTER TABLE "transactions" ADD "customer_category_id" character varying`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
);
await queryRunner.query(
`ALTER TABLE "transaction_items" ADD "item_id" character varying`,
);
}
}

View File

@ -1,15 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddItemQueueToQueue1731498661938 implements MigrationInterface {
name = 'AddItemQueueToQueue1731498661938';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" ADD "item_queue_id" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "item_queue_id"`);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddInformationToItemQueue1731570311609
implements MigrationInterface
{
name = 'AddInformationToItemQueue1731570311609';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" ADD "information" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" DROP COLUMN "information"`,
);
}
}

View File

@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class ItemQueueAddTimeAndPeakLevel1733199330134
implements MigrationInterface
{
name = 'ItemQueueAddTimeAndPeakLevel1733199330134';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" ADD "max_peak_level" integer NOT NULL DEFAULT '100'`,
);
await queryRunner.query(
`ALTER TABLE "item_queues" ADD "call_preparation" integer NOT NULL DEFAULT '5'`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" DROP COLUMN "call_preparation"`,
);
await queryRunner.query(
`ALTER TABLE "item_queues" DROP COLUMN "max_peak_level"`,
);
}
}

View File

@ -1,25 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddNotificationConfigToItemQueue1734717058658
implements MigrationInterface
{
name = 'AddNotificationConfigToItemQueue1734717058658';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" ADD "use_notification" boolean NOT NULL DEFAULT true`,
);
await queryRunner.query(
`ALTER TABLE "item_queues" ADD "requiring_notification" boolean NOT NULL DEFAULT false`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_queues" DROP COLUMN "requiring_notification"`,
);
await queryRunner.query(
`ALTER TABLE "item_queues" DROP COLUMN "use_notification"`,
);
}
}

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddLastNotificationToQueue1734718462106
implements MigrationInterface
{
name = 'AddLastNotificationToQueue1734718462106';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" ADD "last_notification" bigint NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "queues" DROP COLUMN "last_notification"`,
);
}
}

View File

@ -9,32 +9,14 @@ import { CqrsModule } from '@nestjs/cqrs';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service'; import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
import { AuthAdminQueueController } from './infrastructure/auth-admin-queue.controller';
import { AuthAdminQueueOrchestrator } from './domain/auth-admin-queue.orchestrator';
import { LoginAdminQueueManager } from './domain/managers/admin-queue/login-admin-queue.manager';
import { LogoutAdminQueueManager } from './domain/managers/admin-queue/logout-admin-queue.manager';
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature( TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT),
[UserModel, UserLoginModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule, CqrsModule,
], ],
controllers: [AuthController, AuthAdminQueueController], controllers: [AuthController],
providers: [ providers: [LoginManager, LogoutManager, UserDataService, AuthOrchestrator],
LoginManager,
LogoutManager,
UserDataService,
AuthOrchestrator,
// ADMIN QUEUE
AuthAdminQueueOrchestrator,
LoginAdminQueueManager,
LogoutAdminQueueManager,
],
}) })
export class AuthModule {} export class AuthModule {}

View File

@ -1,32 +0,0 @@
import { Injectable } from '@nestjs/common';
import { LoginAdminQueueManager } from './managers/admin-queue/login-admin-queue.manager';
import { LogoutAdminQueueManager } from './managers/admin-queue/logout-admin-queue.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
@Injectable()
export class AuthAdminQueueOrchestrator {
constructor(
private loginManager: LoginAdminQueueManager,
private logoutManager: LogoutAdminQueueManager,
private serviceData: UserDataService,
) {}
async login(data): Promise<any> {
this.loginManager.setData(data);
this.loginManager.setService(this.serviceData, TABLE_NAME.USER);
await this.loginManager.execute();
return this.loginManager.getResult();
}
async logout(userId?: string): Promise<any> {
if (userId) this.logoutManager.setData({ user_id: userId });
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
await this.logoutManager.execute();
return this.logoutManager.getResult();
}
async forceLogout(token): Promise<any> {
return this.serviceData.forceLogout(token);
}
}

View File

@ -24,8 +24,4 @@ export class AuthOrchestrator {
await this.logoutManager.execute(); await this.logoutManager.execute();
return this.logoutManager.getResult(); return this.logoutManager.getResult();
} }
async forceLogout(token): Promise<any> {
return this.serviceData.forceLogout(token);
}
} }

View File

@ -1,168 +0,0 @@
import {
HttpStatus,
Inject,
Injectable,
Logger,
UnauthorizedException,
} from '@nestjs/common';
import { validatePassword } from 'src/core/helpers/password/bcrypt.helpers';
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
import { SessionService } from 'src/core/sessions';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { In } from 'typeorm';
import { UserRole } from 'src/modules/user-related/user/constants';
import { AppSource, LogUserType } from 'src/core/helpers/constant';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
import { UserLoginEntity } from 'src/modules/user-related/user/domain/entities/user-login.entity';
@Injectable()
export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
@Inject()
protected session: SessionService;
protected token;
protected userLogin;
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async process(): Promise<void> {
const itemLogin = await this.dataService.getLoginUserByItem(
this.data.item_id,
);
// get user active by username
this.userLogin = await this.dataService.getOneByOptions({
where: {
username: this.data.username,
status: STATUS.ACTIVE,
role: In([UserRole.QUEUE_ADMIN, UserRole.SUPERADMIN]),
},
relations: ['user_login'],
});
if (!this.userLogin) this.throwError();
// validasi password
const valid = await validatePassword(
this.data.password,
this.userLogin?.password,
);
if (!valid) this.throwError();
const userLoginItem = await this.dataService.getOneByOptions({
where: {
id: itemLogin?.user_id,
},
});
const hasLoginAsQueue = this.userLogin?.user_login?.find(
(item) => item.source === AppSource.QUEUE_ADMIN,
);
if (hasLoginAsQueue && hasLoginAsQueue?.item_id !== this.data.item_id) {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
error: 'Unauthorized',
});
}
// else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
// throw new UnauthorizedException({
// statusCode: HttpStatus.UNAUTHORIZED,
// message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
// error: 'Unauthorized',
// });
// }
// * Disini untuk isi token
const tokenData = {
id: this.userLogin.id,
name: this.userLogin.name,
username: this.userLogin.username,
role: this.userLogin.role,
user_privilege_id: this.userLogin.user_privilege_id,
item_id: this.data.item_id,
item_name: this.data.item_name,
source: AppSource.QUEUE_ADMIN,
};
Logger.debug('Sign Token Admin Queue', 'LoginAdminQueueManager');
this.token = this.session.createAccessToken(tokenData);
Logger.debug('Save Login Token', 'LoginManager');
const userLoginData: UserLoginEntity = {
user_id: this.userLogin.id,
login_token: this.token,
login_date: new Date().getTime(),
source: AppSource.QUEUE_ADMIN,
role: this.userLogin.role,
item_id: this.data.item_id,
item_name: this.data.item_name,
};
if (hasLoginAsQueue?.item_id === this.data.item_id) {
Object.assign(userLoginData, { id: hasLoginAsQueue.id });
}
// Update refresh token
await this.dataService.saveUserLogin(userLoginData);
await this.publishEvents();
Logger.debug('Process Login Admin Queue Done', 'LoginAdminQueueManager');
return;
}
async afterProcess(): Promise<void> {
return;
}
getResult() {
return {
id: this.userLogin.id,
name: this.userLogin.name,
username: this.userLogin.username,
role: this.userLogin.role,
token: this.token,
item_id: this.data.item_id,
item_name: this.data.item_name,
};
}
get entityTarget(): any {
return UserModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: LogUserLoginEvent,
data: {
type: LogUserType.login,
role: this.userLogin.role,
user_id: this.userLogin.id,
username: this.userLogin.username,
created_at: new Date().getTime(),
item_id: this.data.item_id,
item_name: this.data.item_name,
source: AppSource.QUEUE_ADMIN,
},
},
];
}
// !throw errornya akan sama, untuk security
throwError() {
throw new UnauthorizedException({
statusCode: HttpStatus.UNAUTHORIZED,
message: `Gagal! username atau password tidak sesuai`,
error: 'Unauthorized',
});
}
}

View File

@ -1,62 +0,0 @@
import { AppSource, LogUserType } from 'src/core/helpers/constant';
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
export class LogoutAdminQueueManager extends BaseCustomManager<UserEntity> {
protected userLogin;
async validateProcess(): Promise<void> {
return;
}
async beforeProcess(): Promise<void> {
return;
}
async process(): Promise<void> {
const id = this.data?.user_id ?? this.user.id;
this.userLogin = await this.dataService.getOneByOptions({
where: { id },
});
await this.dataService.removeUserLogin({
user_id: id,
source: AppSource.QUEUE_ADMIN,
});
await this.publishEvents();
return;
}
async afterProcess(): Promise<void> {
return;
}
getResult() {
return `Success Logout User`;
}
get entityTarget(): any {
return UserModel;
}
get eventTopics(): EventTopics[] {
return [
{
topic: LogUserLoginEvent,
data: {
type: LogUserType.logout,
role: this.userLogin.role,
user_id: this.userLogin.id,
username: this.userLogin.name,
created_at: new Date().getTime(),
source: AppSource.QUEUE_ADMIN,
},
},
];
}
}

View File

@ -12,11 +12,7 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
import { EventTopics } from 'src/core/strings/constants/interface.constants'; import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity'; import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { Not } from 'typeorm'; import { UserLoginEvent } from '../entities/login.event';
import { UserRole } from 'src/modules/user-related/user/constants';
import { AppSource, LogUserType } from 'src/core/helpers/constant';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
import { UserLoginEntity } from 'src/modules/user-related/user/domain/entities/user-login.entity';
@Injectable() @Injectable()
export class LoginManager extends BaseCustomManager<UserEntity> { export class LoginManager extends BaseCustomManager<UserEntity> {
@ -40,7 +36,6 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
where: { where: {
username: this.data.username, username: this.data.username,
status: STATUS.ACTIVE, status: STATUS.ACTIVE,
role: Not(UserRole.QUEUE_ADMIN),
}, },
relations: [ relations: [
'user_privilege', 'user_privilege',
@ -63,27 +58,25 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
username: this.userLogin.username, username: this.userLogin.username,
role: this.userLogin.role, role: this.userLogin.role,
user_privilege_id: this.userLogin.user_privilege_id, user_privilege_id: this.userLogin.user_privilege_id,
source: AppSource.POS_ADMIN,
}; };
Logger.debug('Sign Token', 'LoginManager'); Logger.debug('Sign Token', 'LoginManager');
this.token = this.session.createAccessToken(tokenData); this.token = this.session.createAccessToken(tokenData);
Logger.debug('Save Login Token', 'LoginManager'); Logger.debug('refreshToken', 'LoginManager');
const userLoginData: UserLoginEntity = { const refreshToken = this.session.createAccessToken(tokenData);
user_id: this.userLogin.id,
login_token: this.token,
login_date: new Date().getTime(),
source: AppSource.POS_ADMIN,
role: this.userLogin.role,
item_id: null,
item_name: null,
};
Logger.debug('Update Refresh Token', 'LoginManager');
// Update refresh token // Update refresh token
await this.dataService.saveUserLogin(userLoginData); await this.dataService.update(
this.queryRunner,
this.entityTarget,
{ id: this.userLogin.id },
{
refresh_token: refreshToken,
},
);
await this.publishEvents();
Logger.debug('Process Login Done', 'LoginManager'); Logger.debug('Process Login Done', 'LoginManager');
return; return;
} }
@ -126,14 +119,11 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
get eventTopics(): EventTopics[] { get eventTopics(): EventTopics[] {
return [ return [
{ {
topic: LogUserLoginEvent, topic: UserLoginEvent,
data: { data: {
type: LogUserType.login, id: this.userLogin.id,
role: this.userLogin.role, type: 'login',
user_id: this.userLogin.id, timestamp: new Date().getTime(),
username: this.userLogin.username,
created_at: new Date().getTime(),
source: AppSource.POS_ADMIN,
}, },
}, },
]; ];

View File

@ -2,8 +2,7 @@ import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base
import { EventTopics } from 'src/core/strings/constants/interface.constants'; import { EventTopics } from 'src/core/strings/constants/interface.constants';
import { UserModel } from 'src/modules/user-related/user/data/models/user.model'; import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity'; import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { AppSource, LogUserType } from 'src/core/helpers/constant'; import { UserLogoutEvent } from '../entities/logout.event';
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
export class LogoutManager extends BaseCustomManager<UserEntity> { export class LogoutManager extends BaseCustomManager<UserEntity> {
async validateProcess(): Promise<void> { async validateProcess(): Promise<void> {
@ -15,12 +14,15 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
} }
async process(): Promise<void> { async process(): Promise<void> {
await this.dataService.removeUserLogin({ await this.dataService.update(
user_id: this.user.id, this.queryRunner,
login_token: this.userProvider.token, this.entityTarget,
source: AppSource.POS_ADMIN, { id: this.user.id },
}); {
await this.publishEvents(); refresh_token: null,
},
);
return; return;
} }
@ -39,14 +41,11 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
get eventTopics(): EventTopics[] { get eventTopics(): EventTopics[] {
return [ return [
{ {
topic: LogUserLoginEvent, topic: UserLogoutEvent,
data: { data: {
type: LogUserType.logout, id: this.user.id,
role: this.user.role, type: 'logout',
user_id: this.user.id, timestamp: new Date().getTime(),
username: this.user.name,
created_at: new Date().getTime(),
source: AppSource.POS_ADMIN,
}, },
}, },
]; ];

View File

@ -1,35 +0,0 @@
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
import { ExcludePrivilege, Public } from 'src/core/guards';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ForceLogoutDto, LoginQueueDto } from './dto/login.dto';
import { AuthAdminQueueOrchestrator } from '../domain/auth-admin-queue.orchestrator';
@Controller('v1/auth/queue')
export class AuthAdminQueueController {
constructor(private orchestrator: AuthAdminQueueOrchestrator) {}
@Post()
@Public(true)
async login(@Body() body: LoginQueueDto) {
return await this.orchestrator.login(body);
}
@ApiBearerAuth('JWT')
@Public(false)
@ExcludePrivilege()
@Delete('logout')
async logout() {
return await this.orchestrator.logout();
}
@Put(':user_id/logout')
async logoutQueueAdmin(@Param('user_id') userId: string) {
return await this.orchestrator.logout(userId);
}
@Post('force-logout')
@Public(true)
async forceLogout(@Body() body: ForceLogoutDto) {
return await this.orchestrator.forceLogout(body.token);
}
}

View File

@ -1,8 +1,8 @@
import { Body, Controller, Delete, Post } from '@nestjs/common'; import { Body, Controller, Delete, Post } from '@nestjs/common';
import { ExcludePrivilege, Public } from 'src/core/guards'; import { Public } from 'src/core/guards';
import { AuthOrchestrator } from '../domain/auth.orchestrator'; import { AuthOrchestrator } from '../domain/auth.orchestrator';
import { ApiBearerAuth } from '@nestjs/swagger'; import { ApiBearerAuth } from '@nestjs/swagger';
import { ForceLogoutDto, LoginDto } from './dto/login.dto'; import { LoginDto } from './dto/login.dto';
@Controller('v1/auth') @Controller('v1/auth')
export class AuthController { export class AuthController {
@ -16,15 +16,8 @@ export class AuthController {
@ApiBearerAuth('JWT') @ApiBearerAuth('JWT')
@Public(false) @Public(false)
@ExcludePrivilege()
@Delete('logout') @Delete('logout')
async logout() { async logoout() {
return await this.orchestrator.logout(); return await this.orchestrator.logout();
} }
@Post('force-logout')
@Public(true)
async forceLogout(@Body() body: ForceLogoutDto) {
return await this.orchestrator.forceLogout(body.token);
}
} }

View File

@ -11,27 +11,3 @@ export class LoginDto implements LoginRequest {
@IsString() @IsString()
password: string; password: string;
} }
export class LoginQueueDto implements LoginRequest {
@ApiProperty({ name: 'username', required: true, default: 'superadmin' })
@IsString()
username: string;
@ApiProperty({ name: 'password', required: true, default: 'Eigen123!' })
@IsString()
password: string;
@ApiProperty({ name: 'item_id', required: true, default: 'string' })
@IsString()
item_id: string;
@ApiProperty({ name: 'item_name', required: true, default: 'string' })
@IsString()
item_name: string;
}
export class ForceLogoutDto {
@ApiProperty({ required: true })
@IsString()
token: string;
}

View File

@ -50,8 +50,6 @@ import {
} from './domain/managers/season-type.handler'; } from './domain/managers/season-type.handler';
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service'; import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model'; import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model';
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
@Module({ @Module({
imports: [ imports: [
@ -62,11 +60,9 @@ import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-l
ItemRateModel, ItemRateModel,
SeasonPeriodModel, SeasonPeriodModel,
UserModel, UserModel,
UserLoginModel,
TransactionModel, TransactionModel,
TransactionTaxModel, TransactionTaxModel,
TransactionItemModel, TransactionItemModel,
TransactionDemographyModel,
], ],
CONNECTION_NAME.DEFAULT, CONNECTION_NAME.DEFAULT,
), ),
@ -102,6 +98,5 @@ import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-l
ItemDataService, ItemDataService,
CouchService, CouchService,
], ],
exports: [CouchService],
}) })
export class CouchModule {} export class CouchModule {}

View File

@ -3,7 +3,7 @@ import { DatabaseListen } from '../../constants';
import { EventBus } from '@nestjs/cqrs'; import { EventBus } from '@nestjs/cqrs';
import { ChangeDocEvent } from '../../domain/events/change-doc.event'; import { ChangeDocEvent } from '../../domain/events/change-doc.event';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { apm } from 'src/core/apm';
import * as Nano from 'nano'; import * as Nano from 'nano';
@Injectable() @Injectable()
@ -19,19 +19,17 @@ export class CouchService {
} }
async onModuleInit() { async onModuleInit() {
// return;
const nano = this.nanoInstance; const nano = this.nanoInstance;
for (const database of DatabaseListen) { for (const database of DatabaseListen) {
const db = nano.db.use(database); const db = nano.db.use(database);
db.changesReader.start({ includeDocs: true }).on('change', (change) => { db.changesReader.start({ includeDocs: true }).on('change', (change) => {
Logger.verbose( Logger.log(
`Receive Data from ${database}: ${change?.id}`, `Receive Data from ${database}: ${change?.id}`,
'CouchService', 'CouchService',
); );
this.changeDoc(change, database); this.changeDoc(change, database);
}); });
// transaction
Logger.log(`start listen database ${database}`, 'CouchService'); Logger.log(`start listen database ${database}`, 'CouchService');
} }
} }
@ -51,10 +49,7 @@ export class CouchService {
const nano = this.nanoInstance; const nano = this.nanoInstance;
const db = nano.use(database); const db = nano.use(database);
return await db.insert(data); return await db.insert(data);
} catch (error) { } catch (error) {}
console.log(error);
apm.captureError(error);
}
} }
public async deleteDoc(data, database) { public async deleteDoc(data, database) {
@ -63,10 +58,7 @@ export class CouchService {
const db = nano.use(database); const db = nano.use(database);
const result = await db.get(data.id); const result = await db.get(data.id);
await db.destroy(data.id, result._rev); await db.destroy(data.id, result._rev);
} catch (error) { } catch (error) {}
console.log(error);
apm.captureError(error);
}
} }
public async updateDoc(data, database) { public async updateDoc(data, database) {
@ -78,10 +70,7 @@ export class CouchService {
...data, ...data,
_rev: result._rev, _rev: result._rev,
}); });
} catch (error) { } catch (error) {}
console.log(error);
apm.captureError(error);
}
} }
public async getDoc(id: string, database: string) { public async getDoc(id: string, database: string) {
@ -91,46 +80,7 @@ export class CouchService {
const result = await db.get(id); const result = await db.get(id);
return result; return result;
} catch (error) { } catch (error) {
console.log(error);
apm.captureError(error);
return null; return null;
} }
} }
getUnixTimestampLast7Days() {
const date = new Date();
date.setDate(date.getDate() - 4);
date.setHours(0, 0, 0, 0);
return date.getTime();
}
public async clearTransactions() {
const nano = this.nanoInstance;
const transaction = nano.use('transaction');
const expiredDate = this.getUnixTimestampLast7Days();
const selectorPayment = {
created_at: {
$lt: expiredDate,
},
};
const transactions = await transaction.find({
selector: selectorPayment,
fields: ['_id', '_rev'],
limit: 100000,
});
const { docs } = transactions;
console.log(docs.length);
const deletedDocs = {
docs: docs.map((doc) => ({
_id: doc._id,
_rev: doc._rev,
_deleted: true,
})),
};
await transaction.bulk(deletedDocs);
}
} }

View File

@ -87,20 +87,20 @@ export class ChangeStatusBookingHandler
async handle(event: TransactionChangeStatusEvent) { async handle(event: TransactionChangeStatusEvent) {
const data = event.data.data; const data = event.data.data;
const dataID = data?.id ?? data?.order_id;
const dataID = data?.id;
const couchData = await this.couchService.getDoc(dataID, 'booking'); const couchData = await this.couchService.getDoc(dataID, 'booking');
const booking = await this.bookingService.getOneByOptions({ const booking = await this.bookingService.getOneByOptions({
where: { where: {
id: dataID, id: data.id,
}, },
relations: ['items', 'items.bundling_items'], relations: ['items'],
}); });
mappingTransaction(booking); mappingTransaction(booking);
if (!couchData) { if (!couchData) {
console.log('save data to couch');
await this.couchService.createDoc( await this.couchService.createDoc(
{ {
_id: booking.id, _id: booking.id,
@ -109,7 +109,6 @@ export class ChangeStatusBookingHandler
'booking', 'booking',
); );
} else { } else {
console.log('update data to couch');
await this.couchService.updateDoc( await this.couchService.updateDoc(
{ {
_id: booking.id, _id: booking.id,
@ -132,18 +131,18 @@ export class BookingUpdateHandler
async handle(event: TransactionUpdatedEvent) { async handle(event: TransactionUpdatedEvent) {
const data = event.data.data; const data = event.data.data;
const dataID = data?.id ?? data?.order_id; const dataID = data?.id;
const couchData = await this.couchService.getDoc(dataID, 'booking'); const couchData = await this.couchService.getDoc(dataID, 'booking');
console.log('update', { dataID, couchData });
if (couchData) { if (couchData) {
const booking = await this.bookingService.getOneByOptions({ const booking = await this.bookingService.getOneByOptions({
where: { where: {
id: dataID, id: data.id,
}, },
relations: ['items'], relations: ['items'],
}); });
console.log({ booking });
mappingTransaction(booking); mappingTransaction(booking);
await this.couchService.updateDoc( await this.couchService.updateDoc(
{ {

View File

@ -5,17 +5,13 @@ import { Public } from 'src/core/guards';
import * as Nano from 'nano'; import * as Nano from 'nano';
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto'; import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { CouchService } from '../data/services/couch.service';
@ApiTags(`couch`) @ApiTags(`couch`)
@Controller('v1/couch') @Controller('v1/couch')
@Public() @Public()
@Injectable() @Injectable()
export class CouchDataController { export class CouchDataController {
constructor( constructor(private configService: ConfigService) {}
private configService: ConfigService,
private couchService: CouchService,
) {}
get nanoInstance() { get nanoInstance() {
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG'); const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
@ -68,11 +64,4 @@ export class CouchDataController {
// return people.get(); // return people.get();
} catch (error) {} } catch (error) {}
} }
@Public(true)
@Get('clear-transactions')
async clearTransactions(): Promise<string> {
await this.couchService.clearTransactions();
return 'OK';
}
} }

View File

@ -1,37 +0,0 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from '../../../../user-related/user/domain/entities/user.entity';
import { Column, Entity } from 'typeorm';
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
import { UserRole } from '../../../../user-related/user/constants';
import { AppSource, LogUserType } from 'src/core/helpers/constant';
@Entity(TABLE_NAME.LOG_USER_LOGIN)
export class LogUserLoginModel
extends BaseCoreModel<UserEntity>
implements LogUserLoginEntity
{
@Column({ type: 'enum', enum: LogUserType, nullable: true })
type: LogUserType;
@Column({ type: 'enum', enum: UserRole, nullable: true })
role: UserRole;
@Column({ type: 'uuid', nullable: true })
user_id: string;
@Column({ type: 'uuid', nullable: true })
item_id: string;
@Column({ type: 'varchar', nullable: true })
item_name: string;
@Column({ type: 'varchar', nullable: true })
username: string;
@Column({ type: 'bigint', nullable: true })
created_at: number;
@Column({ type: 'enum', enum: AppSource, nullable: true })
source: AppSource;
}

View File

@ -14,9 +14,6 @@ export class PosLogModel
@Column('bigint', { name: 'pos_number', nullable: true }) @Column('bigint', { name: 'pos_number', nullable: true })
pos_number: number; pos_number: number;
@Column('varchar', { name: 'pos_name', nullable: true })
pos_name: string;
@Column('decimal', { name: 'total_balance', nullable: true }) @Column('decimal', { name: 'total_balance', nullable: true })
total_balance: number; total_balance: number;

View File

@ -1,21 +0,0 @@
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
import { LogUserLoginModel } from '../models/log-user-login.model';
@Injectable()
export class LogUserLoginService extends BaseDataService<LogUserLoginEntity> {
constructor(
@InjectRepository(LogUserLoginModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<LogUserLoginModel>,
) {
super(repo);
}
async saveData(data) {
this.repo.save(data);
}
}

View File

@ -1,13 +0,0 @@
import { LogUserType } from 'src/core/helpers/constant';
import { UserRole } from '../../../../user-related/user/constants';
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
export interface LogUserLoginEntity extends BaseCoreEntity {
type: LogUserType;
role: UserRole;
user_id: string;
item_id: string;
item_name: string;
username: string;
created_at: number;
}

View File

@ -1,5 +0,0 @@
import { IEvent } from 'src/core/strings/constants/interface.constants';
export class LogUserLoginEvent {
constructor(public readonly data: IEvent) {}
}

View File

@ -3,7 +3,6 @@ import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entit
export interface PosLogEntity extends BaseCoreEntity { export interface PosLogEntity extends BaseCoreEntity {
type: PosLogType; type: PosLogType;
pos_number: number; pos_number: number;
pos_name: string;
total_balance: number; total_balance: number;
created_at: number; created_at: number;
creator_name: string; creator_name: string;

View File

@ -1,14 +0,0 @@
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { LogUserLoginEvent } from '../entities/log-user-login.event';
import { LogUserLoginService } from '../../data/services/log-user-login.service';
@EventsHandler(LogUserLoginEvent)
export class LogUserLoginHandler implements IEventHandler<LogUserLoginEvent> {
constructor(private service: LogUserLoginService) {}
async handle(event: LogUserLoginEvent) {
const data = event.data.data;
await this.service.saveData(data);
}
}

View File

@ -26,7 +26,6 @@ export class RecordPosLogHandler implements IEventHandler<ChangeDocEvent> {
type: PosLogType[data.type], type: PosLogType[data.type],
total_balance: data.withdrawal_cash ?? data.opening_cash_balance, total_balance: data.withdrawal_cash ?? data.opening_cash_balance,
pos_number: data.pos_number, pos_number: data.pos_number,
pos_name: data.pos_name,
creator_id: data.pos_admin?.id, creator_id: data.pos_admin?.id,
creator_name: data.pos_admin?.name ?? data.pos_admin?.username, creator_name: data.pos_admin?.name ?? data.pos_admin?.username,
drawn_by_id: data.withdraw_user?.id, drawn_by_id: data.withdraw_user?.id,

View File

@ -12,15 +12,12 @@ import { LogService } from './data/services/log.service';
import { PosLogModel } from './data/models/pos-log.model'; import { PosLogModel } from './data/models/pos-log.model';
import { PosLogService } from './data/services/pos-log.service'; import { PosLogService } from './data/services/pos-log.service';
import { RecordPosLogHandler } from './domain/handlers/pos-log.handler'; import { RecordPosLogHandler } from './domain/handlers/pos-log.handler';
import { LogUserLoginModel } from './data/models/log-user-login.model';
import { LogUserLoginService } from './data/services/log-user-login.service';
import { LogUserLoginHandler } from './domain/handlers/log-user-login.handler';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forFeature( TypeOrmModule.forFeature(
[LogModel, ErrorLogModel, PosLogModel, LogUserLoginModel], [LogModel, ErrorLogModel, PosLogModel],
CONNECTION_NAME.DEFAULT, CONNECTION_NAME.DEFAULT,
), ),
CqrsModule, CqrsModule,
@ -30,12 +27,10 @@ import { LogUserLoginHandler } from './domain/handlers/log-user-login.handler';
RecordLogHandler, RecordLogHandler,
RecordPosLogHandler, RecordPosLogHandler,
RecordErrorLogHandler, RecordErrorLogHandler,
LogUserLoginHandler,
LogService, LogService,
PosLogService, PosLogService,
ErrorLogService, ErrorLogService,
LogUserLoginService,
], ],
}) })
export class LogModule {} export class LogModule {}

View File

@ -105,15 +105,6 @@ export class PaymentTransactionHandler
`; `;
})} })}
</ul>`, </ul>`,
refund_items_data: transaction?.['refund']?.refund_items
?.filter((item) => Number(item.qty_refund) > 0)
.map((item) => {
return {
qty_refund: item.qty_refund,
item_name: item.transaction_item.item_name,
};
}),
}); });
} }

View File

@ -17,7 +17,7 @@ export async function sendEmail(receivers, invoiceType, attachment?) {
for (const receiver of receivers) { for (const receiver of receivers) {
try { try {
const templateName = getTemplate(receiver.payment_type, invoiceType); const templateName = getTemplate(receiver.payment_type, invoiceType);
const templatePath = `./assets/email-template/redesign/${templateName}.html`; const templatePath = `./assets/email-template/${templateName}.html`;
const templateSource = fs.readFileSync(templatePath, 'utf8'); const templateSource = fs.readFileSync(templatePath, 'utf8');
const template = handlebars.compile(templateSource); const template = handlebars.compile(templateSource);

View File

@ -1,17 +0,0 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ExcludePrivilege, Public } from 'src/core/guards';
import { SupersetService } from './superset.service';
@ApiTags(`Superset`)
@Controller(`v1/superset`)
@Public(false)
@ApiBearerAuth('JWT')
export class SupersetController {
constructor(private service: SupersetService) {}
@Get('token/:id')
@ExcludePrivilege()
async getGuestToken(@Param('id') id: string) {
return this.service.getGuestToken(id);
}
}

View File

@ -1,11 +0,0 @@
import { Module } from '@nestjs/common';
import { SupersetController } from './superset.controller';
import { SupersetService } from './superset.service';
import { HttpModule } from '@nestjs/axios';
@Module({
imports: [HttpModule],
controllers: [SupersetController],
providers: [SupersetService],
})
export class SupersetModule {}

Some files were not shown because too many files have changed in this diff Show More