Compare commits

..

No commits in common. "development" and "feat/reconciliation" have entirely different histories.

273 changed files with 449 additions and 25707 deletions

View File

@ -2,37 +2,29 @@ kind: pipeline
type: docker
name: server
steps:
# - name: build
# 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
- name: build
image: appleboy/drone-ssh
settings:
registry: registry.eigen.co.id
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
tags: ${DRONE_TAG}
custom_dns: 172.10.10.16
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-production
image: plugins/docker
settings:
registry: registry.eigen.co.id
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
build_args:
- env_target=env.production
tags: ${DRONE_TAG}
custom_dns: 172.10.10.16
when:
@ -54,56 +46,3 @@ trigger:
event:
exclude:
- promote
---
kind: pipeline
type: docker
name: kustomize
clone:
disable: true
steps:
- name: kustomize-testing
image: registry.k8s.io/kustomize/kustomize:v5.0.0
environment:
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:
- mkdir -p ~/.ssh &&
- echo $DEVOPS_SSH_PRIVATE | base64 -d > ~/.ssh/id_rsa &&
- 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:
ref:
include:
- refs/tags/*-alpha.*
depends_on:
- server

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

3
env/env.development vendored
View File

@ -44,6 +44,3 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
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

3
env/env.production vendored
View File

@ -41,6 +41,3 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
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

@ -49,7 +49,6 @@
"exceljs": "^4.4.0",
"fs-extra": "^11.2.0",
"googleapis": "^140.0.0",
"gtts": "^0.2.1",
"handlebars": "^4.7.8",
"mathjs": "^13.0.2",
"midtrans-client": "^1.3.1",

View File

@ -45,10 +45,8 @@ import { GoogleCalendarModule } from './modules/configuration/google-calendar/go
import { TransactionModule } from './modules/transaction/transaction/transaction.module';
import { TransactionModel } from './modules/transaction/transaction/data/models/transaction.model';
import {
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 { ReconciliationModule } from './modules/transaction/reconciliation/reconciliation.module';
@ -78,21 +76,6 @@ import { PosLogModel } from './modules/configuration/log/data/models/pos-log.mod
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({
imports: [
@ -117,9 +100,7 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ItemModel,
ItemCategoryModel,
ItemRateModel,
ItemQueueModel,
LogModel,
LogUserLoginModel,
NewsModel,
PaymentMethodModel,
PosLogModel,
@ -135,24 +116,13 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
TransactionTaxModel,
TransactionDemographyModel,
TransactionItemBreakdownModel,
TransactionItemTaxModel,
TransactionBreakdownTaxModel,
UserModel,
UserLoginModel,
VipCategoryModel,
VipCodeModel,
// report
ReportBookmarkModel,
ExportReportHistoryModel,
// Queue
QueueOrderModel,
QueueTicketModel,
QueueItemModel,
QueueModel,
QueueBucketModel,
],
synchronize: false,
}),
@ -178,7 +148,6 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ItemCategoryModule,
ItemModule,
ItemRateModule,
ItemQueueModule,
// transaction
PaymentMethodModule,
@ -206,18 +175,12 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
ReportModule,
ReportBookmarkModule,
ReportExportModule,
ReportSummaryModule,
// superset
SupersetModule,
GateScanModule,
QueueModule,
],
controllers: [],
providers: [
AuthService,
PrivilegeService,
/**
* By default all request from client will protect by JWT

View File

@ -7,10 +7,10 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { Observable } from 'rxjs';
import { SessionService, UsersSession } from 'src/core/sessions';
import { UNPROTECTED_URL } from '../constants';
import { PrivilegeService } from './services/privilege.service';
import { AuthService } from './services/auth.service';
@Injectable({ scope: Scope.REQUEST })
export class JWTGuard implements CanActivate {
@ -18,13 +18,14 @@ export class JWTGuard implements CanActivate {
protected readonly session: SessionService,
protected readonly reflector: Reflector,
protected readonly privilege: PrivilegeService,
protected readonly authService: AuthService,
) {}
protected isPublic = false;
protected userSession: UsersSession;
async canActivate(context: ExecutionContext) {
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
/**
* Check if access url is protected or not
* By default `isUnprotected` equals `false`
@ -60,29 +61,9 @@ export class JWTGuard implements CanActivate {
*/
try {
this.userSession = this.session.verifyToken(token);
await this.authService.verifyRegisteredLoginToken(token);
Logger.log(`Access from ${this.userSession.name}`, 'AuthGuard');
return true;
} 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({
code: 10001,
message:

View File

@ -9,7 +9,7 @@ import { MAIN_MENU } from '../constants';
@Injectable()
export class RolesGuard extends JWTGuard {
async canActivate(context: ExecutionContext): Promise<boolean> {
await super.canActivate(context);
super.canActivate(context);
// jika endpoint tersebut bukan public, maka lakukan check lanjutan
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 fileFilter = (req, file, callback) => {
if (
file.mimetype.match(/\/(jpg|jpeg|png|flv|mp4|m3u8|ts|3gp|mov|avi|wmv)$/)
) {
if (file.mimetype.match(/\/(jpg|jpeg|png)$/)) {
callback(null, true);
} else {
callback(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { SetMetadata } from '@nestjs/common';
import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../../constants';
import { PAGINATION_RESPONSE } from '../../constants';
/**
* This decorator will tell the response,
@ -7,5 +7,3 @@ import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../../constants';
*/
export const Pagination = (isPagination = true) =>
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 { Request } from 'express';
import { Reflector } from '@nestjs/core';
import { GATE_RESPONSE, PAGINATION_RESPONSE } from '../constants';
import { PAGINATION_RESPONSE } from '../constants';
import { createPaginationResponse } from './utils/pagination-meta.helper';
@Injectable()
export class TransformInterceptor implements NestInterceptor {
constructor(protected readonly reflector: Reflector) {}
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>(
PAGINATION_RESPONSE,
[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';
export interface UsersSession {
id: number;
name: string;
role: UserRole;
source?: AppSource;
item_id?: string;
user_privilege_id: string;
}

View File

@ -23,9 +23,4 @@ export class UserProvider {
const [, token] = this.request.headers['authorization'].split(' ');
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',
}
export enum QUEUE_STATUS {
DONE = 'done',
CALLED = 'called',
}
export enum ORDER_TYPE {
ASC = 'ASC',
DESC = 'DESC',

View File

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

View File

@ -4,7 +4,6 @@ export enum TABLE_NAME {
FAQ = 'faqs',
ITEM = 'items',
ITEM_CATEGORY = 'item_categories',
ITEM_QUEUE = 'item_queues',
ITEM_RATE = 'item_rates',
GATE = 'gates',
LOG = 'logs',
@ -23,12 +22,8 @@ export enum TABLE_NAME {
TRANSACTION_ITEM = 'transaction_items',
TRANSACTION_ITEM_BREAKDOWN = 'transaction_item_breakdowns',
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_LOGIN = 'users_login',
LOG_USER_LOGIN = 'log_users_login',
USER_PRIVILEGE = 'user_privileges',
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
VIP_CATEGORY = 'vip_categories',
@ -36,10 +31,4 @@ export enum TABLE_NAME {
REPORT_BOOKMARK = 'report_bookmark',
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

@ -5,7 +5,7 @@ export class AddEstimationToItem1723801180604 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "items" ADD "play_estimation" numeric`,
`ALTER TABLE "items" ADD "play_estimation" integer`,
);
}

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 { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
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({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forFeature(
[UserModel, UserLoginModel],
CONNECTION_NAME.DEFAULT,
),
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT),
CqrsModule,
],
controllers: [AuthController, AuthAdminQueueController],
providers: [
LoginManager,
LogoutManager,
UserDataService,
AuthOrchestrator,
// ADMIN QUEUE
AuthAdminQueueOrchestrator,
LoginAdminQueueManager,
LogoutAdminQueueManager,
],
controllers: [AuthController],
providers: [LoginManager, LogoutManager, UserDataService, AuthOrchestrator],
})
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();
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 { UserModel } from 'src/modules/user-related/user/data/models/user.model';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { Not } 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';
import { UserLoginEvent } from '../entities/login.event';
@Injectable()
export class LoginManager extends BaseCustomManager<UserEntity> {
@ -40,7 +36,6 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
where: {
username: this.data.username,
status: STATUS.ACTIVE,
role: Not(UserRole.QUEUE_ADMIN),
},
relations: [
'user_privilege',
@ -63,27 +58,25 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
username: this.userLogin.username,
role: this.userLogin.role,
user_privilege_id: this.userLogin.user_privilege_id,
source: AppSource.POS_ADMIN,
};
Logger.debug('Sign Token', 'LoginManager');
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.POS_ADMIN,
role: this.userLogin.role,
item_id: null,
item_name: null,
};
Logger.debug('refreshToken', 'LoginManager');
const refreshToken = this.session.createAccessToken(tokenData);
Logger.debug('Update Refresh Token', 'LoginManager');
// 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');
return;
}
@ -126,14 +119,11 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
get eventTopics(): EventTopics[] {
return [
{
topic: LogUserLoginEvent,
topic: UserLoginEvent,
data: {
type: LogUserType.login,
role: this.userLogin.role,
user_id: this.userLogin.id,
username: this.userLogin.username,
created_at: new Date().getTime(),
source: AppSource.POS_ADMIN,
id: this.userLogin.id,
type: 'login',
timestamp: new Date().getTime(),
},
},
];

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

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 { ExcludePrivilege, Public } from 'src/core/guards';
import { Public } from 'src/core/guards';
import { AuthOrchestrator } from '../domain/auth.orchestrator';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ForceLogoutDto, LoginDto } from './dto/login.dto';
import { LoginDto } from './dto/login.dto';
@Controller('v1/auth')
export class AuthController {
@ -16,15 +16,8 @@ export class AuthController {
@ApiBearerAuth('JWT')
@Public(false)
@ExcludePrivilege()
@Delete('logout')
async logout() {
async logoout() {
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()
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

@ -51,7 +51,6 @@ import {
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 { 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({
imports: [
@ -62,7 +61,6 @@ import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-l
ItemRateModel,
SeasonPeriodModel,
UserModel,
UserLoginModel,
TransactionModel,
TransactionTaxModel,
TransactionItemModel,
@ -102,6 +100,5 @@ import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-l
ItemDataService,
CouchService,
],
exports: [CouchService],
})
export class CouchModule {}

View File

@ -19,19 +19,17 @@ export class CouchService {
}
async onModuleInit() {
// return;
const nano = this.nanoInstance;
for (const database of DatabaseListen) {
const db = nano.db.use(database);
db.changesReader.start({ includeDocs: true }).on('change', (change) => {
Logger.verbose(
Logger.log(
`Receive Data from ${database}: ${change?.id}`,
'CouchService',
);
this.changeDoc(change, database);
});
// transaction
Logger.log(`start listen database ${database}`, 'CouchService');
}
}
@ -96,41 +94,4 @@ export class CouchService {
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

@ -97,7 +97,9 @@ export class ChangeStatusBookingHandler
},
relations: ['items', 'items.bundling_items'],
});
console.log('change status', { dataID, couchData, booking });
mappingTransaction(booking);
console.log('after mapping');
if (!couchData) {
console.log('save data to couch');

View File

@ -5,17 +5,13 @@ import { Public } from 'src/core/guards';
import * as Nano from 'nano';
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
import { ConfigService } from '@nestjs/config';
import { CouchService } from '../data/services/couch.service';
@ApiTags(`couch`)
@Controller('v1/couch')
@Public()
@Injectable()
export class CouchDataController {
constructor(
private configService: ConfigService,
private couchService: CouchService,
) {}
constructor(private configService: ConfigService) {}
get nanoInstance() {
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
@ -68,11 +64,4 @@ export class CouchDataController {
// return people.get();
} 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 })
pos_number: number;
@Column('varchar', { name: 'pos_name', nullable: true })
pos_name: string;
@Column('decimal', { name: 'total_balance', nullable: true })
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 {
type: PosLogType;
pos_number: number;
pos_name: string;
total_balance: number;
created_at: number;
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],
total_balance: data.withdrawal_cash ?? data.opening_cash_balance,
pos_number: data.pos_number,
pos_name: data.pos_name,
creator_id: data.pos_admin?.id,
creator_name: data.pos_admin?.name ?? data.pos_admin?.username,
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 { PosLogService } from './data/services/pos-log.service';
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({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forFeature(
[LogModel, ErrorLogModel, PosLogModel, LogUserLoginModel],
[LogModel, ErrorLogModel, PosLogModel],
CONNECTION_NAME.DEFAULT,
),
CqrsModule,
@ -30,12 +27,10 @@ import { LogUserLoginHandler } from './domain/handlers/log-user-login.handler';
RecordLogHandler,
RecordPosLogHandler,
RecordErrorLogHandler,
LogUserLoginHandler,
LogService,
PosLogService,
ErrorLogService,
LogUserLoginService,
],
})
export class LogModule {}

View File

@ -32,6 +32,7 @@ export class PaymentTransactionHandler
const current_data = event.data.data;
const data_id = current_data.transaction_id ?? event.data.id;
const from_refund = event.data.module == TABLE_NAME.REFUND;
console.log('payment handlet', { data_id });
const payments = await this.paymentService.getManyByOptions({
where: {
@ -105,15 +106,6 @@ export class PaymentTransactionHandler
`;
})}
</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) {
try {
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 template = handlebars.compile(templateSource);

View File

@ -40,13 +40,11 @@ export class SupersetService {
}),
);
const cookie = response.headers['set-cookie'];
return { loginToken, csrfToken: response.data.result, cookie };
return { loginToken, csrfToken: response.data.result };
}
async getGuestToken(uuid: string) {
const { loginToken, csrfToken, cookie } = await this.getCSRFToken();
const { loginToken, csrfToken } = await this.getCSRFToken();
const data = {
resources: [{ type: 'dashboard', id: uuid }],
@ -54,14 +52,11 @@ export class SupersetService {
user: { username: 'pos_embed', first_name: 'pos', last_name: 'embed' },
};
const [requestCookie] = cookie[0].split(';');
const headers = {
Authorization: `Bearer ${loginToken}`,
Cookie: requestCookie,
'Content-Type': 'application/json',
Authorization: `Bearer ${loginToken}`,
'X-CSRFToken': `${csrfToken}`,
'Access-Control-Allow-Credentials': true,
Referer: `${this.supersetURL}/v1/security/guest_token/`,
};
const response = await firstValueFrom(

View File

@ -1,11 +0,0 @@
export interface GateScanEntity {
gate_id: string;
type: string;
uuid: string;
}
export interface GateLogEntity {
gate_id: string;
code: string;
error: any;
}

View File

@ -1,8 +0,0 @@
export interface GateResponseEntity {
code: number;
message: string;
}
export interface GateMasterEntity {
codes: string[];
}

View File

@ -1,17 +0,0 @@
import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { GateController } from './infrastructure/gate.controller';
@Global()
@Module({
imports: [
ConfigModule.forRoot(),
// TypeOrmModule.forFeature(
// [],
// CONNECTION_NAME.DEFAULT,
// ),
],
controllers: [GateController],
providers: [],
})
export class GateScanModule {}

View File

@ -1,26 +0,0 @@
import { IsNotEmpty, IsString } from 'class-validator';
import { GateLogEntity } from '../../domain/entity/gate-request.entity';
import { ApiProperty } from '@nestjs/swagger';
export class GateLogDto implements GateLogEntity {
@ApiProperty({
type: String,
required: true,
})
@IsNotEmpty()
@IsString()
gate_id: string;
@ApiProperty({
type: String,
required: true,
})
@IsNotEmpty()
@IsString()
code: string;
@ApiProperty({
required: false,
})
error: any;
}

View File

@ -1,102 +0,0 @@
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
import { Response } from 'express';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { GateScanEntity } from '../domain/entity/gate-request.entity';
import {
GateMasterEntity,
GateResponseEntity,
} from '../domain/entity/gate-response.entity';
import { Gate } from 'src/core/response';
import { GateLogDto } from './dto/logs.dto';
const masterGates = [
'319b6d3e-b661-4d19-8695-0dd6fb76465e',
'9afdb79d-7162-43e6-8ac6-f1941adea7ba',
'7e4c0281-8cf2-420e-aba1-c8ff834de450',
'19318ac8-caa0-47e4-8a41-2aac238d3665',
'495bc25f-42c4-4007-8e79-3747fa1054b6',
'b90fc9a9-efd9-4216-a8af-7ed120b141de',
'4399e93c-a839-4802-a49d-f933c72b1433',
'970673a7-6370-444a-931a-9784220dd35d',
'151ab50e-4e54-4252-b3ab-f5c0817b27a0',
'4c0e6924-baf5-47fb-a15b-fd1cd0958cc0',
];
const failedGates = [
'b3c3ae7b-daf5-4340-998b-ee35ed41323d',
'be157609-92b8-4989-920d-a81769bcb05a',
];
const gateResponses = [
{
statusCode: 200,
code: 1,
message: 'Berhasil Check In',
},
{
statusCode: 403,
code: 2,
message: 'Gagal melakukan Check In. Karena tiket telah kadaluarsa',
},
{
statusCode: 403,
code: 3,
message: 'Gagal melakukan Check In. Tiket tidak tersedia',
},
];
@ApiTags(`Gate - read`)
@Controller(`v1/gate`)
@Public(true)
@Gate()
export class GateController {
@Post('scan')
async scan(
@Body() data: GateScanEntity,
@Res({ passthrough: true }) res: Response,
): Promise<GateResponseEntity> {
console.log(data);
if (masterGates.includes(data.uuid)) {
res.status(200);
return gateResponses[0];
}
if (failedGates.includes(data.uuid)) {
res.status(403);
return gateResponses[2];
}
const response = Math.floor(Math.random() * 3);
const responseValue = gateResponses[response];
res.status(responseValue.statusCode);
return responseValue;
}
@Post('logs')
async logs(@Body() data: GateLogDto): Promise<GateResponseEntity> {
console.log(data);
return { code: 1, message: 'success' };
}
@Get(':id/master')
async detail(@Param('id') id: string): Promise<GateMasterEntity> {
if (id == '1') return { codes: masterGates };
return {
codes: this.createRandomStringArray(masterGates),
};
}
createRandomStringArray(inputArray: string[]): string[] {
const randomLength = Math.floor(Math.random() * 4) + 2; // Random length between 2 and 5
const outputArray: string[] = [];
while (outputArray.length < randomLength) {
const randomIndex = Math.floor(Math.random() * inputArray.length);
outputArray.push(inputArray[randomIndex]);
}
return outputArray;
}
}

View File

@ -1,7 +0,0 @@
export enum ItemType {
TIKET_MASUK = 'tiket masuk',
WAHANA = 'wahana',
BUNDLING = 'bundling',
FREE_GIFT = 'free gift',
OTHER = 'other',
}

View File

@ -1,42 +0,0 @@
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
import { Column, Entity, OneToMany } from 'typeorm';
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
import { ItemType } from '../../constants';
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
@Entity(TABLE_NAME.ITEM_QUEUE)
export class ItemQueueModel
extends BaseStatusModel<ItemQueueEntity>
implements ItemQueueEntity
{
@Column('int', { default: 100 })
max_peak_level: number;
@Column('int', { default: 5 })
call_preparation: number;
@Column('varchar', { name: 'name' })
name: string;
@Column('varchar', { name: 'information', nullable: true })
information: string;
@Column('enum', {
name: 'item_type',
enum: ItemType,
default: ItemType.TIKET_MASUK,
})
item_type: ItemType;
@OneToMany(() => ItemModel, (model) => model.item_queue, {
onUpdate: 'CASCADE',
})
items: ItemModel[];
@Column('boolean', { default: true })
use_notification: boolean;
@Column('boolean', { default: false })
requiring_notification: boolean;
}

View File

@ -1,17 +0,0 @@
import { Injectable } from '@nestjs/common';
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { ItemQueueModel } from '../models/item-queue.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
@Injectable()
export class ItemQueueDataService extends BaseDataService<ItemQueueEntity> {
constructor(
@InjectRepository(ItemQueueModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ItemQueueModel>,
) {
super(repo);
}
}

View File

@ -1,21 +0,0 @@
import { Injectable } from '@nestjs/common';
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { ItemQueueModel } from '../models/item-queue.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { Repository } from 'typeorm';
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
@Injectable()
export class ItemQueueReadService extends BaseReadService<ItemQueueEntity> {
constructor(
@InjectRepository(ItemQueueModel, CONNECTION_NAME.DEFAULT)
private repo: Repository<ItemQueueModel>,
) {
super(repo);
}
async list(): Promise<ItemQueueEntity[]> {
return this.repo.find();
}
}

View File

@ -1,5 +0,0 @@
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
export interface FilterItemQueueEntity extends BaseFilterEntity {
item_types: string[];
}

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