Compare commits
206 Commits
fix/report
...
developmen
Author | SHA1 | Date |
---|---|---|
|
064112e731 | |
|
d6a238a224 | |
|
dc5e938f75 | |
|
eb4da7ccc4 | |
|
46caaba6bd | |
|
7953c7dbbd | |
|
6911f6f0a2 | |
|
762340a72b | |
|
61cbbf81ef | |
|
4ea53f7088 | |
|
0548141e5f | |
|
29e4dc5400 | |
|
f9d8f85179 | |
|
769e8174f4 | |
|
3ace59c450 | |
|
187555a543 | |
|
551bd12f5b | |
|
1692c8234a | |
|
903b7cfd18 | |
|
26a6af2044 | |
|
d7ed77934d | |
|
66720c5b8b | |
|
44e74de315 | |
|
82e7879969 | |
|
d612b6725a | |
|
54b9658075 | |
|
661dbb8cf2 | |
|
6dc6579450 | |
|
e3db958e0d | |
|
d73752252a | |
|
b38c489777 | |
|
8cfc003261 | |
|
55e89426d9 | |
|
5f6214eeb6 | |
|
d71c2096b8 | |
|
f661276c58 | |
|
4a3e77043e | |
|
b4f141e628 | |
|
9db5c4b326 | |
|
f7e3d5399c | |
|
7305dfd068 | |
|
b4bc31463e | |
|
83d53847d7 | |
|
e09190df42 | |
|
61045a39ab | |
|
60b5bcf638 | |
|
4eedca12e7 | |
|
cb452cf5f3 | |
|
ea25e0cae1 | |
|
5e4401a974 | |
|
c05af5c16b | |
|
5988a592ac | |
|
1148a72481 | |
|
3b7d7ea80b | |
|
3b19484f29 | |
|
4dc21c4ebd | |
|
99d0fc8560 | |
|
ac3fde14e3 | |
|
8d54c686fc | |
|
c0a68db9f1 | |
|
3cf4fbdada | |
|
9eacb7dca5 | |
|
eae529bce9 | |
|
a0de16575f | |
|
53ef4656eb | |
|
ec916ab574 | |
|
72827aa83e | |
|
0e9ae569ba | |
|
37334ecb19 | |
|
86c73058fd | |
|
fb7f925c78 | |
|
2b132c53a8 | |
|
e9535749d4 | |
|
94696e765d | |
|
9805b9903a | |
|
af9818d44c | |
|
2bcd7a34fb | |
|
577f8ea9ea | |
|
1878d03c0f | |
|
6807d00cbe | |
|
ad3e3593fd | |
|
8e7e43b09d | |
|
6c53610ec4 | |
|
c129a59d47 | |
|
d413f1fa7b | |
|
bf5914af92 | |
|
28c1ab36da | |
|
3ed25e1366 | |
|
4c403293db | |
|
dac42b754c | |
|
5ef7521e9b | |
|
ba7b81c320 | |
|
7137b98043 | |
|
3ddd837622 | |
|
217362193a | |
|
a3647b536b | |
|
5f46432327 | |
|
319d9eecef | |
|
50e7f66bb7 | |
|
492a4ca2ba | |
|
4ed7ecce5e | |
|
e6787aed89 | |
|
1d54b709b6 | |
|
bd32d4fbdd | |
|
78fb5b7fac | |
|
dea9989914 | |
|
c8d0b32cc6 | |
|
93b1208278 | |
|
86251f43a2 | |
|
9977a7456a | |
|
487f59ae93 | |
|
e9de46fff8 | |
|
5b507a1c3c | |
|
143bf76417 | |
|
ac86289182 | |
|
32d4064f0a | |
|
01b2796c26 | |
|
e9d864c922 | |
|
d6c02ac29f | |
|
4f0b378ec6 | |
|
efa245048a | |
|
2d0ccf67f2 | |
|
77cf19c06e | |
|
77a6afbbbc | |
|
fea0420ae4 | |
|
3eee8d73f4 | |
|
07d2ec3b46 | |
|
8ba5646bb6 | |
|
ce1aa86944 | |
|
4d20955764 | |
|
6a8816aa90 | |
|
8f43907091 | |
|
7afe06e96c | |
|
c0a0b2316d | |
|
95ee8dce8d | |
|
55ddc9b605 | |
|
e2a6878e71 | |
|
f2c409fc35 | |
|
7213e7915b | |
|
0e65fb8a9a | |
|
6efe5618cb | |
|
60167cd807 | |
|
0dfaeb2045 | |
|
18dc15e442 | |
|
198dcb4933 | |
|
901c67137b | |
|
411458fe4c | |
|
d911f80ff9 | |
|
79f3966b49 | |
|
e6066b534c | |
|
c5590ab7b1 | |
|
1a633cc574 | |
|
1348f5a79b | |
|
90ab3668b4 | |
|
49b98cd56c | |
|
d6ae891de4 | |
|
9026f85a66 | |
|
d40261e919 | |
|
e1c6b809e4 | |
|
c47f1e2616 | |
|
df0536157a | |
|
92bf8fc342 | |
|
437793a2a1 | |
|
48a48e6e7a | |
|
22f4e732db | |
|
34ae5964c4 | |
|
f2fef65f20 | |
|
039531de3b | |
|
0b8bb72392 | |
|
256c8f38bd | |
|
109898b076 | |
|
b2be2e0160 | |
|
b4266d5d68 | |
|
f23a9f3510 | |
|
91370940d7 | |
|
c15b4d8079 | |
|
b16edb73e3 | |
|
ea58096287 | |
|
1dfcaf7b15 | |
|
8b58598955 | |
|
5eb50c952f | |
|
aaa0ca6f76 | |
|
3de7bfbbe5 | |
|
60c03fefa0 | |
|
b34d54e7d0 | |
|
3fd97b8879 | |
|
93c822f34e | |
|
e09c76309e | |
|
43deb04d92 | |
|
23043fb7f9 | |
|
1d377b574c | |
|
7d9f619858 | |
|
c06a2a0a2b | |
|
cc71814648 | |
|
004dfc9de5 | |
|
09d6dbaab2 | |
|
c76594d767 | |
|
f4cf5178b8 | |
|
ffbbf6e140 | |
|
614a9346fb | |
|
f7c49d27d5 | |
|
2ee96a617f | |
|
10049abc55 | |
|
01fbedab77 | |
|
19494b3328 | |
|
e1f2cdfa4d |
89
.drone.yml
89
.drone.yml
|
@ -2,29 +2,37 @@ kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: server
|
name: server
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
# - name: build
|
||||||
image: appleboy/drone-ssh
|
# 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
|
||||||
settings:
|
settings:
|
||||||
host:
|
registry: registry.eigen.co.id
|
||||||
- 172.10.10.10
|
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
||||||
username: eigen
|
tags: ${DRONE_TAG}
|
||||||
key:
|
custom_dns: 172.10.10.16
|
||||||
from_secret: DEVOPS_SSH_PRIVATE_OPEN
|
|
||||||
port: 22
|
|
||||||
script:
|
|
||||||
- cd /home/eigen/PROJECT/POS/POS.DEV/BE
|
|
||||||
- sh build.sh
|
|
||||||
when:
|
when:
|
||||||
ref:
|
ref:
|
||||||
- refs/tags/devel_*
|
|
||||||
- refs/tags/*-alpha.*
|
- refs/tags/*-alpha.*
|
||||||
- name: build-production
|
- name: build-production
|
||||||
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}
|
||||||
build_args:
|
|
||||||
- env_target=env.production
|
|
||||||
tags: ${DRONE_TAG}
|
tags: ${DRONE_TAG}
|
||||||
custom_dns: 172.10.10.16
|
custom_dns: 172.10.10.16
|
||||||
when:
|
when:
|
||||||
|
@ -46,3 +54,56 @@ trigger:
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
- promote
|
- 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
|
|
@ -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
|
||||||
|
|
|
@ -44,3 +44,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||||
SUPERSET_ADMIN_USERNAME=admin
|
SUPERSET_ADMIN_USERNAME=admin
|
||||||
SUPERSET_ADMIN_PASSWORD=admin
|
SUPERSET_ADMIN_PASSWORD=admin
|
||||||
|
|
||||||
|
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||||
|
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -41,3 +41,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||||
SUPERSET_ADMIN_USERNAME=admin
|
SUPERSET_ADMIN_USERNAME=admin
|
||||||
SUPERSET_ADMIN_PASSWORD=admin
|
SUPERSET_ADMIN_PASSWORD=admin
|
||||||
|
|
||||||
|
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||||
|
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -49,6 +49,7 @@
|
||||||
"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",
|
||||||
|
|
|
@ -45,8 +45,10 @@ import { GoogleCalendarModule } from './modules/configuration/google-calendar/go
|
||||||
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 {
|
||||||
|
TransactionBreakdownTaxModel,
|
||||||
TransactionItemBreakdownModel,
|
TransactionItemBreakdownModel,
|
||||||
TransactionItemModel,
|
TransactionItemModel,
|
||||||
|
TransactionItemTaxModel,
|
||||||
} from './modules/transaction/transaction/data/models/transaction-item.model';
|
} 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';
|
||||||
|
@ -79,6 +81,18 @@ import { SupersetModule } from './modules/configuration/superset/superset.module
|
||||||
import { GateScanModule } from './modules/gates/gate.module';
|
import { GateScanModule } from './modules/gates/gate.module';
|
||||||
import { UserLoginModel } from './modules/user-related/user/data/models/user-login.model';
|
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 { 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: [
|
||||||
|
@ -103,6 +117,7 @@ import { LogUserLoginModel } from './modules/configuration/log/data/models/log-u
|
||||||
ItemModel,
|
ItemModel,
|
||||||
ItemCategoryModel,
|
ItemCategoryModel,
|
||||||
ItemRateModel,
|
ItemRateModel,
|
||||||
|
ItemQueueModel,
|
||||||
LogModel,
|
LogModel,
|
||||||
LogUserLoginModel,
|
LogUserLoginModel,
|
||||||
NewsModel,
|
NewsModel,
|
||||||
|
@ -120,6 +135,8 @@ import { LogUserLoginModel } from './modules/configuration/log/data/models/log-u
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
TransactionDemographyModel,
|
TransactionDemographyModel,
|
||||||
TransactionItemBreakdownModel,
|
TransactionItemBreakdownModel,
|
||||||
|
TransactionItemTaxModel,
|
||||||
|
TransactionBreakdownTaxModel,
|
||||||
UserModel,
|
UserModel,
|
||||||
UserLoginModel,
|
UserLoginModel,
|
||||||
|
|
||||||
|
@ -129,6 +146,13 @@ import { LogUserLoginModel } from './modules/configuration/log/data/models/log-u
|
||||||
// report
|
// report
|
||||||
ReportBookmarkModel,
|
ReportBookmarkModel,
|
||||||
ExportReportHistoryModel,
|
ExportReportHistoryModel,
|
||||||
|
|
||||||
|
// Queue
|
||||||
|
QueueOrderModel,
|
||||||
|
QueueTicketModel,
|
||||||
|
QueueItemModel,
|
||||||
|
QueueModel,
|
||||||
|
QueueBucketModel,
|
||||||
],
|
],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
}),
|
}),
|
||||||
|
@ -154,6 +178,7 @@ import { LogUserLoginModel } from './modules/configuration/log/data/models/log-u
|
||||||
ItemCategoryModule,
|
ItemCategoryModule,
|
||||||
ItemModule,
|
ItemModule,
|
||||||
ItemRateModule,
|
ItemRateModule,
|
||||||
|
ItemQueueModule,
|
||||||
|
|
||||||
// transaction
|
// transaction
|
||||||
PaymentMethodModule,
|
PaymentMethodModule,
|
||||||
|
@ -181,14 +206,18 @@ import { LogUserLoginModel } from './modules/configuration/log/data/models/log-u
|
||||||
ReportModule,
|
ReportModule,
|
||||||
ReportBookmarkModule,
|
ReportBookmarkModule,
|
||||||
ReportExportModule,
|
ReportExportModule,
|
||||||
|
ReportSummaryModule,
|
||||||
|
|
||||||
// superset
|
// superset
|
||||||
SupersetModule,
|
SupersetModule,
|
||||||
|
|
||||||
GateScanModule,
|
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
|
||||||
|
|
|
@ -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,14 +18,13 @@ 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;
|
||||||
|
|
||||||
canActivate(
|
async canActivate(context: ExecutionContext) {
|
||||||
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`
|
||||||
|
@ -61,9 +60,29 @@ 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:
|
||||||
|
|
|
@ -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> {
|
||||||
super.canActivate(context);
|
await 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) {
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
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',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,3 +2,10 @@ export enum LogUserType {
|
||||||
login = 'login',
|
login = 'login',
|
||||||
logout = 'logout',
|
logout = 'logout',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AppSource {
|
||||||
|
POS_ADMIN = 'POS_ADMIN',
|
||||||
|
POS_COUNTER = 'POS_COUNTER',
|
||||||
|
QUEUE_ADMIN = 'QUEUE_ADMIN',
|
||||||
|
QUEUE_CUSTOMER = 'QUEUE_CUSTOMER',
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ import { diskStorage } from 'multer';
|
||||||
const MB = 1024 * 1024;
|
const MB = 1024 * 1024;
|
||||||
|
|
||||||
const fileFilter = (req, file, callback) => {
|
const fileFilter = (req, file, callback) => {
|
||||||
if (file.mimetype.match(/\/(jpg|jpeg|png)$/)) {
|
if (
|
||||||
|
file.mimetype.match(/\/(jpg|jpeg|png|flv|mp4|m3u8|ts|3gp|mov|avi|wmv)$/)
|
||||||
|
) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
callback(
|
callback(
|
||||||
|
|
|
@ -32,7 +32,7 @@ export abstract class BaseManager {
|
||||||
|
|
||||||
setUser() {
|
setUser() {
|
||||||
try {
|
try {
|
||||||
this.user = this.userProvider?.user;
|
this.user = this.userProvider?.user ?? BLANK_USER;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.user = BLANK_USER;
|
this.user = BLANK_USER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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()]}'` ?? `'%${statusData}%'`;
|
return `'${STATUS[statusData.toUpperCase()]}'`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const exist = specificFilter.find((item) => item.isStatus);
|
const exist = specificFilter.find((item) => item.isStatus);
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
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 { OPERATION, STATUS } from 'src/core/strings/constants/base.constants';
|
import {
|
||||||
|
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';
|
||||||
|
|
||||||
|
@ -8,12 +12,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;
|
protected dataStatus: STATUS | QUEUE_STATUS;
|
||||||
protected relations = [];
|
protected relations = [];
|
||||||
protected duplicateColumn: string[];
|
protected duplicateColumn: string[];
|
||||||
abstract get entityTarget(): any;
|
abstract get entityTarget(): any;
|
||||||
|
|
||||||
setData(id: string, status: STATUS): void {
|
setData(id: string, status: STATUS | QUEUE_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
|
||||||
|
|
|
@ -23,6 +23,7 @@ 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 })
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,9 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,11 @@ 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',
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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',
|
||||||
|
@ -24,4 +25,7 @@ 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',
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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',
|
||||||
|
@ -22,6 +23,8 @@ export enum TABLE_NAME {
|
||||||
TRANSACTION_ITEM = 'transaction_items',
|
TRANSACTION_ITEM = 'transaction_items',
|
||||||
TRANSACTION_ITEM_BREAKDOWN = 'transaction_item_breakdowns',
|
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',
|
TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
|
||||||
USER = 'users',
|
USER = 'users',
|
||||||
USER_LOGIN = 'users_login',
|
USER_LOGIN = 'users_login',
|
||||||
|
@ -33,4 +36,10 @@ 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',
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ export class AddEstimationToItem1723801180604 implements MigrationInterface {
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "items" ADD "play_estimation" integer`,
|
`ALTER TABLE "items" ADD "play_estimation" numeric`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
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`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
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`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
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`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
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"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,10 +19,14 @@ export class AuthAdminQueueOrchestrator {
|
||||||
return this.loginManager.getResult();
|
return this.loginManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout(id?: string): Promise<any> {
|
async logout(userId?: string): Promise<any> {
|
||||||
if (id) this.logoutManager.setData({ id });
|
if (userId) this.logoutManager.setData({ user_id: userId });
|
||||||
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
|
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,4 +24,8 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,9 @@ 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 { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||||
import { LogUserType } from 'src/core/helpers/constant';
|
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
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 LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
|
@ -62,19 +63,24 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.userLogin.user_login) {
|
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({
|
throw new UnauthorizedException({
|
||||||
statusCode: HttpStatus.UNAUTHORIZED,
|
statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
message: `Akun anda sudah login di perangkat lain.`,
|
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||||
error: 'Unauthorized',
|
|
||||||
});
|
|
||||||
} else if (itemLogin) {
|
|
||||||
throw new UnauthorizedException({
|
|
||||||
statusCode: HttpStatus.UNAUTHORIZED,
|
|
||||||
message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
|
||||||
error: 'Unauthorized',
|
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
|
// * Disini untuk isi token
|
||||||
const tokenData = {
|
const tokenData = {
|
||||||
|
@ -85,32 +91,28 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
user_privilege_id: this.userLogin.user_privilege_id,
|
user_privilege_id: this.userLogin.user_privilege_id,
|
||||||
item_id: this.data.item_id,
|
item_id: this.data.item_id,
|
||||||
item_name: this.data.item_name,
|
item_name: this.data.item_name,
|
||||||
|
source: AppSource.QUEUE_ADMIN,
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.debug('Sign Token Admin Queue', 'LoginAdminQueueManager');
|
Logger.debug('Sign Token Admin Queue', 'LoginAdminQueueManager');
|
||||||
this.token = this.session.createAccessToken(tokenData);
|
this.token = this.session.createAccessToken(tokenData);
|
||||||
|
|
||||||
Logger.debug('refreshToken Admin Queue', 'LoginAdminQueueManager');
|
Logger.debug('Save Login Token', 'LoginManager');
|
||||||
const refreshToken = this.session.createAccessToken(tokenData);
|
const userLoginData: UserLoginEntity = {
|
||||||
|
|
||||||
Logger.debug('Update Refresh Token Admin Queue', 'LoginAdminQueueManager');
|
|
||||||
|
|
||||||
// Update refresh token
|
|
||||||
await this.dataService.update(
|
|
||||||
this.queryRunner,
|
|
||||||
this.entityTarget,
|
|
||||||
{ id: this.userLogin.id },
|
|
||||||
{
|
|
||||||
refresh_token: refreshToken,
|
|
||||||
user_login: {
|
|
||||||
user_id: this.userLogin.id,
|
user_id: this.userLogin.id,
|
||||||
login_token: this.token,
|
login_token: this.token,
|
||||||
login_date: new Date().getTime(),
|
login_date: new Date().getTime(),
|
||||||
|
source: AppSource.QUEUE_ADMIN,
|
||||||
|
role: this.userLogin.role,
|
||||||
item_id: this.data.item_id,
|
item_id: this.data.item_id,
|
||||||
item_name: this.data.item_name,
|
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();
|
await this.publishEvents();
|
||||||
|
|
||||||
Logger.debug('Process Login Admin Queue Done', 'LoginAdminQueueManager');
|
Logger.debug('Process Login Admin Queue Done', 'LoginAdminQueueManager');
|
||||||
|
@ -149,6 +151,7 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
item_id: this.data.item_id,
|
item_id: this.data.item_id,
|
||||||
item_name: this.data.item_name,
|
item_name: this.data.item_name,
|
||||||
|
source: AppSource.QUEUE_ADMIN,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { LogUserType } from 'src/core/helpers/constant';
|
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||||
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
|
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
|
||||||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
||||||
|
@ -17,21 +17,17 @@ export class LogoutAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(): Promise<void> {
|
async process(): Promise<void> {
|
||||||
const id = this.data?.id ?? this.user.id;
|
const id = this.data?.user_id ?? this.user.id;
|
||||||
|
|
||||||
this.userLogin = await this.dataService.getOneByOptions({
|
this.userLogin = await this.dataService.getOneByOptions({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.dataService.update(
|
await this.dataService.removeUserLogin({
|
||||||
this.queryRunner,
|
user_id: id,
|
||||||
this.entityTarget,
|
source: AppSource.QUEUE_ADMIN,
|
||||||
{ id: this.userLogin.id },
|
});
|
||||||
{
|
|
||||||
refresh_token: null,
|
|
||||||
user_login: null,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await this.publishEvents();
|
await this.publishEvents();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +54,7 @@ export class LogoutAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
user_id: this.userLogin.id,
|
user_id: this.userLogin.id,
|
||||||
username: this.userLogin.name,
|
username: this.userLogin.name,
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
|
source: AppSource.QUEUE_ADMIN,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -14,8 +14,9 @@ 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 { Not } from 'typeorm';
|
||||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||||
import { LogUserType } from 'src/core/helpers/constant';
|
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
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> {
|
||||||
|
@ -62,24 +63,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('refreshToken', 'LoginManager');
|
Logger.debug('Save Login Token', 'LoginManager');
|
||||||
const refreshToken = this.session.createAccessToken(tokenData);
|
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('Update Refresh Token', 'LoginManager');
|
|
||||||
// Update refresh token
|
// Update refresh token
|
||||||
await this.dataService.update(
|
await this.dataService.saveUserLogin(userLoginData);
|
||||||
this.queryRunner,
|
|
||||||
this.entityTarget,
|
|
||||||
{ id: this.userLogin.id },
|
|
||||||
{
|
|
||||||
refresh_token: refreshToken,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.publishEvents();
|
await this.publishEvents();
|
||||||
Logger.debug('Process Login Done', 'LoginManager');
|
Logger.debug('Process Login Done', 'LoginManager');
|
||||||
|
@ -131,6 +133,7 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
|
||||||
user_id: this.userLogin.id,
|
user_id: this.userLogin.id,
|
||||||
username: this.userLogin.username,
|
username: this.userLogin.username,
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
|
source: AppSource.POS_ADMIN,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,7 +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 { LogUserType } from 'src/core/helpers/constant';
|
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.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> {
|
||||||
|
@ -15,15 +15,11 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(): Promise<void> {
|
async process(): Promise<void> {
|
||||||
await this.dataService.update(
|
await this.dataService.removeUserLogin({
|
||||||
this.queryRunner,
|
user_id: this.user.id,
|
||||||
this.entityTarget,
|
login_token: this.userProvider.token,
|
||||||
{ id: this.user.id },
|
source: AppSource.POS_ADMIN,
|
||||||
{
|
});
|
||||||
refresh_token: null,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.publishEvents();
|
await this.publishEvents();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +46,7 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
|
||||||
user_id: this.user.id,
|
user_id: this.user.id,
|
||||||
username: this.user.name,
|
username: this.user.name,
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
|
source: AppSource.POS_ADMIN,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
|
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
|
||||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||||
import { LoginQueueDto } from './dto/login.dto';
|
import { ForceLogoutDto, LoginQueueDto } from './dto/login.dto';
|
||||||
import { AuthAdminQueueOrchestrator } from '../domain/auth-admin-queue.orchestrator';
|
import { AuthAdminQueueOrchestrator } from '../domain/auth-admin-queue.orchestrator';
|
||||||
|
|
||||||
@Controller('v1/auth/queue')
|
@Controller('v1/auth/queue')
|
||||||
|
@ -18,12 +18,18 @@ export class AuthAdminQueueController {
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ExcludePrivilege()
|
@ExcludePrivilege()
|
||||||
@Delete('logout')
|
@Delete('logout')
|
||||||
async logoout() {
|
async logout() {
|
||||||
return await this.orchestrator.logout();
|
return await this.orchestrator.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/logout')
|
@Put(':user_id/logout')
|
||||||
async logoutQueueAdmin(@Param('id') dataId: string) {
|
async logoutQueueAdmin(@Param('user_id') userId: string) {
|
||||||
return await this.orchestrator.logout(dataId);
|
return await this.orchestrator.logout(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('force-logout')
|
||||||
|
@Public(true)
|
||||||
|
async forceLogout(@Body() body: ForceLogoutDto) {
|
||||||
|
return await this.orchestrator.forceLogout(body.token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Body, Controller, Delete, Post } from '@nestjs/common';
|
||||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
import { ExcludePrivilege, 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 { LoginDto } from './dto/login.dto';
|
import { ForceLogoutDto, LoginDto } from './dto/login.dto';
|
||||||
|
|
||||||
@Controller('v1/auth')
|
@Controller('v1/auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
|
@ -18,7 +18,13 @@ export class AuthController {
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ExcludePrivilege()
|
@ExcludePrivilege()
|
||||||
@Delete('logout')
|
@Delete('logout')
|
||||||
async logoout() {
|
async logout() {
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,3 +29,9 @@ export class LoginQueueDto implements LoginRequest {
|
||||||
@IsString()
|
@IsString()
|
||||||
item_name: string;
|
item_name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ForceLogoutDto {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@IsString()
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ 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);
|
||||||
|
@ -95,4 +96,41 @@ export class CouchService {
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,7 @@ export class ChangeStatusBookingHandler
|
||||||
},
|
},
|
||||||
relations: ['items', 'items.bundling_items'],
|
relations: ['items', 'items.bundling_items'],
|
||||||
});
|
});
|
||||||
console.log('change status', { dataID, couchData, booking });
|
|
||||||
mappingTransaction(booking);
|
mappingTransaction(booking);
|
||||||
console.log('after mapping');
|
|
||||||
|
|
||||||
if (!couchData) {
|
if (!couchData) {
|
||||||
console.log('save data to couch');
|
console.log('save data to couch');
|
||||||
|
|
|
@ -5,13 +5,17 @@ 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(private configService: ConfigService) {}
|
constructor(
|
||||||
|
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');
|
||||||
|
@ -64,4 +68,11 @@ 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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Column, Entity } from 'typeorm';
|
||||||
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
||||||
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
|
import { LogUserLoginEntity } from '../../domain/entities/log-user-login.entity';
|
||||||
import { UserRole } from '../../../../user-related/user/constants';
|
import { UserRole } from '../../../../user-related/user/constants';
|
||||||
import { LogUserType } from 'src/core/helpers/constant';
|
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.LOG_USER_LOGIN)
|
@Entity(TABLE_NAME.LOG_USER_LOGIN)
|
||||||
export class LogUserLoginModel
|
export class LogUserLoginModel
|
||||||
|
@ -31,4 +31,7 @@ export class LogUserLoginModel
|
||||||
|
|
||||||
@Column({ type: 'bigint', nullable: true })
|
@Column({ type: 'bigint', nullable: true })
|
||||||
created_at: number;
|
created_at: number;
|
||||||
|
|
||||||
|
@Column({ type: 'enum', enum: AppSource, nullable: true })
|
||||||
|
source: AppSource;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,13 @@ export class SupersetService {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return { loginToken, csrfToken: response.data.result };
|
const cookie = response.headers['set-cookie'];
|
||||||
|
|
||||||
|
return { loginToken, csrfToken: response.data.result, cookie };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGuestToken(uuid: string) {
|
async getGuestToken(uuid: string) {
|
||||||
const { loginToken, csrfToken } = await this.getCSRFToken();
|
const { loginToken, csrfToken, cookie } = await this.getCSRFToken();
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
resources: [{ type: 'dashboard', id: uuid }],
|
resources: [{ type: 'dashboard', id: uuid }],
|
||||||
|
@ -52,11 +54,14 @@ export class SupersetService {
|
||||||
user: { username: 'pos_embed', first_name: 'pos', last_name: 'embed' },
|
user: { username: 'pos_embed', first_name: 'pos', last_name: 'embed' },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [requestCookie] = cookie[0].split(';');
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${loginToken}`,
|
Authorization: `Bearer ${loginToken}`,
|
||||||
|
Cookie: requestCookie,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
'X-CSRFToken': `${csrfToken}`,
|
'X-CSRFToken': `${csrfToken}`,
|
||||||
Referer: `${this.supersetURL}/v1/security/guest_token/`,
|
'Access-Control-Allow-Credentials': true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
|
|
|
@ -3,3 +3,9 @@ export interface GateScanEntity {
|
||||||
type: string;
|
type: string;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GateLogEntity {
|
||||||
|
gate_id: string;
|
||||||
|
code: string;
|
||||||
|
error: any;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import {
|
||||||
GateResponseEntity,
|
GateResponseEntity,
|
||||||
} from '../domain/entity/gate-response.entity';
|
} from '../domain/entity/gate-response.entity';
|
||||||
import { Gate } from 'src/core/response';
|
import { Gate } from 'src/core/response';
|
||||||
|
import { GateLogDto } from './dto/logs.dto';
|
||||||
|
|
||||||
const masterGates = [
|
const masterGates = [
|
||||||
'319b6d3e-b661-4d19-8695-0dd6fb76465e',
|
'319b6d3e-b661-4d19-8695-0dd6fb76465e',
|
||||||
|
@ -72,6 +73,13 @@ export class GateController {
|
||||||
return responseValue;
|
return responseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('logs')
|
||||||
|
async logs(@Body() data: GateLogDto): Promise<GateResponseEntity> {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
return { code: 1, message: 'success' };
|
||||||
|
}
|
||||||
|
|
||||||
@Get(':id/master')
|
@Get(':id/master')
|
||||||
async detail(@Param('id') id: string): Promise<GateMasterEntity> {
|
async detail(@Param('id') id: string): Promise<GateMasterEntity> {
|
||||||
if (id == '1') return { codes: masterGates };
|
if (id == '1') return { codes: masterGates };
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
export enum ItemType {
|
||||||
|
TIKET_MASUK = 'tiket masuk',
|
||||||
|
WAHANA = 'wahana',
|
||||||
|
BUNDLING = 'bundling',
|
||||||
|
FREE_GIFT = 'free gift',
|
||||||
|
OTHER = 'other',
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { BaseFilterEntity } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
export interface FilterItemQueueEntity extends BaseFilterEntity {
|
||||||
|
item_types: string[];
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
|
import { ItemType } from '../../constants';
|
||||||
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
|
||||||
|
export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
|
name: string;
|
||||||
|
item_type: ItemType;
|
||||||
|
information?: string;
|
||||||
|
max_peak_level: number;
|
||||||
|
call_preparation: number;
|
||||||
|
items: ItemEntity[];
|
||||||
|
use_notification?: boolean;
|
||||||
|
requiring_notification?: boolean;
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { CreateItemQueueManager } from './managers/create-item-queue.manager';
|
||||||
|
import { ItemQueueDataService } from '../../data/services/item-queue-data.service';
|
||||||
|
import { ItemQueueEntity } from '../entities/item-queue.entity';
|
||||||
|
import { DeleteItemQueueManager } from './managers/delete-item-queue.manager';
|
||||||
|
import { UpdateItemQueueManager } from './managers/update-item-queue.manager';
|
||||||
|
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
|
||||||
|
import { ActiveItemQueueManager } from './managers/active-item-queue.manager';
|
||||||
|
import { InactiveItemQueueManager } from './managers/inactive-item-queue.manager';
|
||||||
|
import { ConfirmItemQueueManager } from './managers/confirm-item-queue.manager';
|
||||||
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BatchConfirmItemQueueManager } from './managers/batch-confirm-item-queue.manager';
|
||||||
|
import { BatchInactiveItemQueueManager } from './managers/batch-inactive-item-queue.manager';
|
||||||
|
import { BatchActiveItemQueueManager } from './managers/batch-active-item-queue.manager';
|
||||||
|
import { BatchDeleteItemQueueManager } from './managers/batch-delete-item-queue.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ItemQueueDataOrchestrator extends BaseDataTransactionOrchestrator<ItemQueueEntity> {
|
||||||
|
constructor(
|
||||||
|
private createManager: CreateItemQueueManager,
|
||||||
|
private updateManager: UpdateItemQueueManager,
|
||||||
|
private deleteManager: DeleteItemQueueManager,
|
||||||
|
private activeManager: ActiveItemQueueManager,
|
||||||
|
private confirmManager: ConfirmItemQueueManager,
|
||||||
|
private inactiveManager: InactiveItemQueueManager,
|
||||||
|
private batchDeleteManager: BatchDeleteItemQueueManager,
|
||||||
|
private batchActiveManager: BatchActiveItemQueueManager,
|
||||||
|
private batchConfirmManager: BatchConfirmItemQueueManager,
|
||||||
|
private batchInactiveManager: BatchInactiveItemQueueManager,
|
||||||
|
private serviceData: ItemQueueDataService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data): Promise<ItemQueueEntity> {
|
||||||
|
data.items = data.item_ids.map((id) => {
|
||||||
|
return { id };
|
||||||
|
});
|
||||||
|
this.createManager.setData(data);
|
||||||
|
this.createManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.createManager.execute();
|
||||||
|
await this.createManager.generateConfig();
|
||||||
|
return this.createManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(dataId, data): Promise<ItemQueueEntity> {
|
||||||
|
this.updateManager.setData(dataId, data);
|
||||||
|
this.updateManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.updateManager.execute();
|
||||||
|
return this.updateManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(dataId): Promise<string> {
|
||||||
|
this.deleteManager.setData(dataId);
|
||||||
|
this.deleteManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.deleteManager.execute();
|
||||||
|
return this.deleteManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchDelete(dataIds: string[]): Promise<BatchResult> {
|
||||||
|
this.batchDeleteManager.setData(dataIds);
|
||||||
|
this.batchDeleteManager.setService(
|
||||||
|
this.serviceData,
|
||||||
|
TABLE_NAME.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
await this.batchDeleteManager.execute();
|
||||||
|
return this.batchDeleteManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async active(dataId): Promise<string> {
|
||||||
|
this.activeManager.setData(dataId, STATUS.ACTIVE);
|
||||||
|
this.activeManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.activeManager.execute();
|
||||||
|
return this.activeManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchActive(dataIds: string[]): Promise<BatchResult> {
|
||||||
|
this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
|
||||||
|
this.batchActiveManager.setService(
|
||||||
|
this.serviceData,
|
||||||
|
TABLE_NAME.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
await this.batchActiveManager.execute();
|
||||||
|
return this.batchActiveManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async confirm(dataId): Promise<string> {
|
||||||
|
this.confirmManager.setData(dataId, STATUS.ACTIVE);
|
||||||
|
this.confirmManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.confirmManager.execute();
|
||||||
|
return this.confirmManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchConfirm(dataIds: string[]): Promise<BatchResult> {
|
||||||
|
this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
|
||||||
|
this.batchConfirmManager.setService(
|
||||||
|
this.serviceData,
|
||||||
|
TABLE_NAME.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
await this.batchConfirmManager.execute();
|
||||||
|
return this.batchConfirmManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async inactive(dataId): Promise<string> {
|
||||||
|
this.inactiveManager.setData(dataId, STATUS.INACTIVE);
|
||||||
|
this.inactiveManager.setService(this.serviceData, TABLE_NAME.ITEM_CATEGORY);
|
||||||
|
await this.inactiveManager.execute();
|
||||||
|
return this.inactiveManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchInactive(dataIds: string[]): Promise<BatchResult> {
|
||||||
|
this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
|
||||||
|
this.batchInactiveManager.setService(
|
||||||
|
this.serviceData,
|
||||||
|
TABLE_NAME.ITEM_CATEGORY,
|
||||||
|
);
|
||||||
|
await this.batchInactiveManager.execute();
|
||||||
|
return this.batchInactiveManager.getResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { IndexItemQueueManager } from './managers/index-item-queue.manager';
|
||||||
|
import { ItemQueueReadService } from '../../data/services/item-queue-read.service';
|
||||||
|
import { ItemQueueEntity } from '../entities/item-queue.entity';
|
||||||
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-read.orchestrator';
|
||||||
|
import { DetailItemQueueManager } from './managers/detail-item-queue.manager';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ItemQueueReadOrchestrator extends BaseReadOrchestrator<ItemQueueEntity> {
|
||||||
|
constructor(
|
||||||
|
private indexManager: IndexItemQueueManager,
|
||||||
|
private detailManager: DetailItemQueueManager,
|
||||||
|
private serviceData: ItemQueueReadService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async index(params): Promise<PaginationResponse<ItemQueueEntity>> {
|
||||||
|
this.indexManager.setFilterParam(params);
|
||||||
|
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM_QUEUE);
|
||||||
|
await this.indexManager.execute();
|
||||||
|
return this.indexManager.getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
async list(): Promise<ItemQueueEntity[]> {
|
||||||
|
const items = await this.serviceData.list();
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
async detail(dataId: string): Promise<ItemQueueEntity> {
|
||||||
|
this.detailManager.setData(dataId);
|
||||||
|
this.detailManager.setService(this.serviceData, TABLE_NAME.ITEM_QUEUE);
|
||||||
|
await this.detailManager.execute();
|
||||||
|
return this.detailManager.getResult();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ActiveItemQueueManager extends BaseUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
getResult(): string {
|
||||||
|
return `Success active data ${this.result.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchActiveItemQueueManager extends BaseBatchUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
validateData(data: ItemQueueEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchConfirmItemQueueManager extends BaseBatchUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
validateData(data: ItemQueueEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { BaseBatchDeleteManager } from 'src/core/modules/domain/usecase/managers/base-batch-delete.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchDeleteItemQueueManager extends BaseBatchDeleteManager<ItemQueueEntity> {
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateData(data: ItemQueueEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
relation: 'items',
|
||||||
|
message:
|
||||||
|
'Gagal! tidak dapat mengubah tipe item karena sudah berelasi dengan item',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { BaseBatchUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-batch-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BatchInactiveItemQueueManager extends BaseBatchUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
validateData(data: ItemQueueEntity): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
relation: 'items',
|
||||||
|
message:
|
||||||
|
'Gagal! tidak dapat mengubah tipe item karena sudah berelasi dengan item',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): BatchResult {
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ConfirmItemQueueManager extends BaseUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
getResult(): string {
|
||||||
|
return `Success active data ${this.result.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
columnUniques,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CreateItemQueueManager extends BaseCreateManager<ItemQueueEntity> {
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
Object.assign(this.data, {
|
||||||
|
item_type: this.data.item_type.toLowerCase(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async generateConfig(): Promise<void> {
|
||||||
|
// TODO: Implement logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get uniqueColumns(): columnUniques[] {
|
||||||
|
return [{ column: 'name' }];
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDeleteManager } from 'src/core/modules/domain/usecase/managers/base-delete.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DeleteItemQueueManager extends BaseDeleteManager<ItemQueueEntity> {
|
||||||
|
getResult(): string {
|
||||||
|
return `Success`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseDetailManager } from 'src/core/modules/domain/usecase/managers/base-detail.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
|
async prepareData(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get relations(): RelationParam {
|
||||||
|
return {
|
||||||
|
joinRelations: [],
|
||||||
|
selectRelations: ['items'],
|
||||||
|
countRelations: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get selects(): string[] {
|
||||||
|
return [
|
||||||
|
`${this.tableName}.id`,
|
||||||
|
`${this.tableName}.status`,
|
||||||
|
`${this.tableName}.name`,
|
||||||
|
`${this.tableName}.information`,
|
||||||
|
`${this.tableName}.item_type`,
|
||||||
|
`${this.tableName}.created_at`,
|
||||||
|
`${this.tableName}.creator_name`,
|
||||||
|
`${this.tableName}.updated_at`,
|
||||||
|
`${this.tableName}.editor_name`,
|
||||||
|
`${this.tableName}.max_peak_level`,
|
||||||
|
`${this.tableName}.call_preparation`,
|
||||||
|
`${this.tableName}.use_notification`,
|
||||||
|
`${this.tableName}.requiring_notification`,
|
||||||
|
|
||||||
|
`items.id`,
|
||||||
|
`items.created_at`,
|
||||||
|
`items.status`,
|
||||||
|
`items.item_type`,
|
||||||
|
`items.name`,
|
||||||
|
`items.hpp`,
|
||||||
|
`items.limit_type`,
|
||||||
|
`items.limit_value`,
|
||||||
|
`items.base_price`,
|
||||||
|
`items.share_profit`,
|
||||||
|
`items.play_estimation`,
|
||||||
|
`items.video_url`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get setFindProperties(): any {
|
||||||
|
return {
|
||||||
|
id: this.dataId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getResult(): ItemQueueEntity {
|
||||||
|
const videos = this.result.items.map((item) => {
|
||||||
|
return item.video_url ?? [];
|
||||||
|
});
|
||||||
|
this.result['videos'] = videos.flat();
|
||||||
|
return this.result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class InactiveItemQueueManager extends BaseUpdateStatusManager<ItemQueueEntity> {
|
||||||
|
getResult(): string {
|
||||||
|
return `Success inactive data ${this.result.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
relation: 'items',
|
||||||
|
message:
|
||||||
|
'Gagal! tidak dapat mengubah tipe item karena sudah berelasi dengan item',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
|
import {
|
||||||
|
Param,
|
||||||
|
RelationParam,
|
||||||
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class IndexItemQueueManager extends BaseIndexManager<ItemQueueEntity> {
|
||||||
|
async prepareData(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get relations(): RelationParam {
|
||||||
|
return {
|
||||||
|
joinRelations: [],
|
||||||
|
selectRelations: ['items'],
|
||||||
|
countRelations: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get selects(): string[] {
|
||||||
|
return [
|
||||||
|
`${this.tableName}.id`,
|
||||||
|
`${this.tableName}.status`,
|
||||||
|
`${this.tableName}.name`,
|
||||||
|
`${this.tableName}.item_type`,
|
||||||
|
`${this.tableName}.created_at`,
|
||||||
|
`${this.tableName}.creator_name`,
|
||||||
|
`${this.tableName}.updated_at`,
|
||||||
|
`${this.tableName}.editor_name`,
|
||||||
|
`${this.tableName}.max_peak_level`,
|
||||||
|
`${this.tableName}.call_preparation`,
|
||||||
|
`${this.tableName}.use_notification`,
|
||||||
|
`${this.tableName}.requiring_notification`,
|
||||||
|
|
||||||
|
`items.id`,
|
||||||
|
`items.created_at`,
|
||||||
|
`items.status`,
|
||||||
|
`items.item_type`,
|
||||||
|
`items.name`,
|
||||||
|
`items.hpp`,
|
||||||
|
`items.limit_type`,
|
||||||
|
`items.limit_value`,
|
||||||
|
`items.base_price`,
|
||||||
|
`items.share_profit`,
|
||||||
|
`items.play_estimation`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
get specificFilter(): Param[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
cols: `${this.tableName}.name`,
|
||||||
|
data: this.filterParam.names,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cols: `${this.tableName}.item_type::text`,
|
||||||
|
data: this.filterParam.item_types,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
setQueryFilter(
|
||||||
|
queryBuilder: SelectQueryBuilder<ItemQueueEntity>,
|
||||||
|
): SelectQueryBuilder<ItemQueueEntity> {
|
||||||
|
return queryBuilder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
||||||
|
import { ItemQueueEntity } from '../../entities/item-queue.entity';
|
||||||
|
import { ItemQueueModel } from '../../../data/models/item-queue.model';
|
||||||
|
import {
|
||||||
|
EventTopics,
|
||||||
|
columnUniques,
|
||||||
|
validateRelations,
|
||||||
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UpdateItemQueueManager extends BaseUpdateManager<ItemQueueEntity> {
|
||||||
|
async validateProcess(): Promise<void> {
|
||||||
|
Object.assign(this.data, {
|
||||||
|
item_type: this.data.item_type.toLowerCase(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async beforeProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async afterProcess(): Promise<void> {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get validateRelations(): validateRelations[] {
|
||||||
|
if (this.data.item_type != this.oldData.item_type) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
relation: 'items',
|
||||||
|
message:
|
||||||
|
'Gagal! tidak dapat mengubah tipe item karena sudah berelasi dengan item',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get uniqueColumns(): columnUniques[] {
|
||||||
|
return [{ column: 'name' }];
|
||||||
|
}
|
||||||
|
|
||||||
|
get entityTarget(): any {
|
||||||
|
return ItemQueueModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get eventTopics(): EventTopics[] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { BaseFilterDto } from 'src/core/modules/infrastructure/dto/base-filter.dto';
|
||||||
|
import { FilterItemQueueEntity } from '../../domain/entities/filter-item-queue.entity';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
|
export class FilterItemQueueDto
|
||||||
|
extends BaseFilterDto
|
||||||
|
implements FilterItemQueueEntity
|
||||||
|
{
|
||||||
|
@ApiProperty({ type: ['string'], required: false })
|
||||||
|
@Transform((body) => {
|
||||||
|
return Array.isArray(body.value) ? body.value : [body.value];
|
||||||
|
})
|
||||||
|
item_types: string[];
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||||
|
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
||||||
|
import { IsArray, IsNumber, IsString } from 'class-validator';
|
||||||
|
import { ItemType } from '../../constants';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
import { Exclude, Transform } from 'class-transformer';
|
||||||
|
|
||||||
|
export class ItemQueueDto extends BaseStatusDto implements ItemQueueEntity {
|
||||||
|
@ApiProperty({
|
||||||
|
name: 'max_peak_level',
|
||||||
|
required: false,
|
||||||
|
example: 'Menentukan level peak maksimal penuhnya wahana',
|
||||||
|
default: 100,
|
||||||
|
})
|
||||||
|
@IsNumber()
|
||||||
|
max_peak_level: number;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
name: 'call_preparation',
|
||||||
|
required: false,
|
||||||
|
example: 'Waktu persiapan untuk memanggil antrian dalam menit',
|
||||||
|
default: 5,
|
||||||
|
})
|
||||||
|
@IsNumber()
|
||||||
|
call_preparation: number;
|
||||||
|
|
||||||
|
@Exclude()
|
||||||
|
items: ItemEntity[];
|
||||||
|
|
||||||
|
@ApiProperty({ name: 'name', required: true, example: 'Bundling w Entrance' })
|
||||||
|
@IsString()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
name: 'information',
|
||||||
|
required: false,
|
||||||
|
example: 'Running text untuk display antrian',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
information: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: `Select (${JSON.stringify(Object.values(ItemType))})`,
|
||||||
|
example: ItemType.BUNDLING,
|
||||||
|
})
|
||||||
|
item_type: ItemType;
|
||||||
|
|
||||||
|
@ApiProperty({ type: [String], required: true })
|
||||||
|
@Transform((body) => {
|
||||||
|
return Array.isArray(body.value) ? body.value : [body.value];
|
||||||
|
})
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
item_ids: string[];
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Param,
|
||||||
|
Patch,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ItemQueueDataOrchestrator } from '../domain/usecases/item-queue-data.orchestrator';
|
||||||
|
import { ItemQueueDto } from './dto/item-queue.dto';
|
||||||
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { ItemQueueEntity } from '../domain/entities/item-queue.entity';
|
||||||
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
|
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - data`)
|
||||||
|
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
||||||
|
@Public(false)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
export class ItemQueueDataController {
|
||||||
|
constructor(private orchestrator: ItemQueueDataOrchestrator) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async create(@Body() data: ItemQueueDto): Promise<ItemQueueEntity> {
|
||||||
|
return await this.orchestrator.create(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('/batch-delete')
|
||||||
|
async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
|
return await this.orchestrator.batchDelete(body.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id/active')
|
||||||
|
async active(@Param('id') dataId: string): Promise<string> {
|
||||||
|
return await this.orchestrator.active(dataId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('/batch-active')
|
||||||
|
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
|
return await this.orchestrator.batchActive(body.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id/confirm')
|
||||||
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
|
return await this.orchestrator.confirm(dataId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('/batch-confirm')
|
||||||
|
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
|
return await this.orchestrator.batchConfirm(body.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id/inactive')
|
||||||
|
async inactive(@Param('id') dataId: string): Promise<string> {
|
||||||
|
return await this.orchestrator.inactive(dataId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('/batch-inactive')
|
||||||
|
async batchInactive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||||
|
return await this.orchestrator.batchInactive(body.ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put(':id')
|
||||||
|
async update(
|
||||||
|
@Param('id') dataId: string,
|
||||||
|
@Body() data: ItemQueueDto,
|
||||||
|
): Promise<ItemQueueEntity> {
|
||||||
|
return await this.orchestrator.update(dataId, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
async delete(@Param('id') dataId: string): Promise<string> {
|
||||||
|
return await this.orchestrator.delete(dataId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Param,
|
||||||
|
Query,
|
||||||
|
UnauthorizedException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { FilterItemQueueDto } from './dto/filter-item-queue.dto';
|
||||||
|
import { Pagination } from 'src/core/response';
|
||||||
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { ItemQueueEntity } from '../domain/entities/item-queue.entity';
|
||||||
|
import { ItemQueueReadOrchestrator } from '../domain/usecases/item-queue-read.orchestrator';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
import { validate as isValidUUID } from 'uuid';
|
||||||
|
|
||||||
|
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
||||||
|
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
||||||
|
@Public(false)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
export class ItemQueueReadController {
|
||||||
|
constructor(private orchestrator: ItemQueueReadOrchestrator) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
@Pagination()
|
||||||
|
async index(
|
||||||
|
@Query() params: FilterItemQueueDto,
|
||||||
|
): Promise<PaginationResponse<ItemQueueEntity>> {
|
||||||
|
return await this.orchestrator.index(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('list')
|
||||||
|
@Public(true)
|
||||||
|
async list() {
|
||||||
|
const list = await this.orchestrator.list();
|
||||||
|
return list.map(({ id, name, item_type }) => {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
item_type,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async detail(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
|
return await this.orchestrator.detail(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('display/:id')
|
||||||
|
@Public(true)
|
||||||
|
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
|
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
||||||
|
return await this.orchestrator.detail(id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { ItemQueueDataService } from './data/services/item-queue-data.service';
|
||||||
|
import { ItemQueueReadService } from './data/services/item-queue-read.service';
|
||||||
|
import { ItemQueueReadController } from './infrastructure/item-queue-read.controller';
|
||||||
|
import { ItemQueueReadOrchestrator } from './domain/usecases/item-queue-read.orchestrator';
|
||||||
|
import { ItemQueueDataController } from './infrastructure/item-queue-data.controller';
|
||||||
|
import { ItemQueueDataOrchestrator } from './domain/usecases/item-queue-data.orchestrator';
|
||||||
|
import { CreateItemQueueManager } from './domain/usecases/managers/create-item-queue.manager';
|
||||||
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
|
import { IndexItemQueueManager } from './domain/usecases/managers/index-item-queue.manager';
|
||||||
|
import { DeleteItemQueueManager } from './domain/usecases/managers/delete-item-queue.manager';
|
||||||
|
import { UpdateItemQueueManager } from './domain/usecases/managers/update-item-queue.manager';
|
||||||
|
import { ActiveItemQueueManager } from './domain/usecases/managers/active-item-queue.manager';
|
||||||
|
import { ConfirmItemQueueManager } from './domain/usecases/managers/confirm-item-queue.manager';
|
||||||
|
import { InactiveItemQueueManager } from './domain/usecases/managers/inactive-item-queue.manager';
|
||||||
|
import { DetailItemQueueManager } from './domain/usecases/managers/detail-item-queue.manager';
|
||||||
|
import { BatchDeleteItemQueueManager } from './domain/usecases/managers/batch-delete-item-queue.manager';
|
||||||
|
import { BatchActiveItemQueueManager } from './domain/usecases/managers/batch-active-item-queue.manager';
|
||||||
|
import { BatchConfirmItemQueueManager } from './domain/usecases/managers/batch-confirm-item-queue.manager';
|
||||||
|
import { BatchInactiveItemQueueManager } from './domain/usecases/managers/batch-inactive-item-queue.manager';
|
||||||
|
import { ItemQueueModel } from './data/models/item-queue.model';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
TypeOrmModule.forFeature([ItemQueueModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
CqrsModule,
|
||||||
|
],
|
||||||
|
controllers: [ItemQueueDataController, ItemQueueReadController],
|
||||||
|
providers: [
|
||||||
|
IndexItemQueueManager,
|
||||||
|
DetailItemQueueManager,
|
||||||
|
CreateItemQueueManager,
|
||||||
|
DeleteItemQueueManager,
|
||||||
|
UpdateItemQueueManager,
|
||||||
|
ActiveItemQueueManager,
|
||||||
|
ConfirmItemQueueManager,
|
||||||
|
InactiveItemQueueManager,
|
||||||
|
BatchDeleteItemQueueManager,
|
||||||
|
BatchActiveItemQueueManager,
|
||||||
|
BatchConfirmItemQueueManager,
|
||||||
|
BatchInactiveItemQueueManager,
|
||||||
|
|
||||||
|
ItemQueueDataService,
|
||||||
|
ItemQueueReadService,
|
||||||
|
|
||||||
|
ItemQueueDataOrchestrator,
|
||||||
|
ItemQueueReadOrchestrator,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
export class ItemQueueModule {}
|
|
@ -16,6 +16,7 @@ import { ItemCategoryModel } from 'src/modules/item-related/item-category/data/m
|
||||||
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 { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';
|
||||||
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
||||||
|
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.ITEM)
|
@Entity(TABLE_NAME.ITEM)
|
||||||
export class ItemModel
|
export class ItemModel
|
||||||
|
@ -28,6 +29,9 @@ export class ItemModel
|
||||||
@Column('varchar', { name: 'image_url', nullable: true })
|
@Column('varchar', { name: 'image_url', nullable: true })
|
||||||
image_url: string;
|
image_url: string;
|
||||||
|
|
||||||
|
@Column('json', { nullable: true })
|
||||||
|
video_url: string[];
|
||||||
|
|
||||||
@Column('enum', {
|
@Column('enum', {
|
||||||
name: 'item_type',
|
name: 'item_type',
|
||||||
enum: ItemType,
|
enum: ItemType,
|
||||||
|
@ -50,7 +54,7 @@ export class ItemModel
|
||||||
@Column('bigint', { name: 'base_price', nullable: true })
|
@Column('bigint', { name: 'base_price', nullable: true })
|
||||||
base_price: number;
|
base_price: number;
|
||||||
|
|
||||||
@Column('int', { name: 'play_estimation', nullable: true })
|
@Column('decimal', { name: 'play_estimation', nullable: true })
|
||||||
play_estimation: number;
|
play_estimation: number;
|
||||||
|
|
||||||
@Column('boolean', { name: 'use_queue', default: false })
|
@Column('boolean', { name: 'use_queue', default: false })
|
||||||
|
@ -82,6 +86,16 @@ export class ItemModel
|
||||||
@JoinColumn({ name: 'item_category_id' })
|
@JoinColumn({ name: 'item_category_id' })
|
||||||
item_category: ItemCategoryModel;
|
item_category: ItemCategoryModel;
|
||||||
|
|
||||||
|
@ManyToOne(() => ItemQueueModel, (model) => model.items, {
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
onDelete: 'SET NULL',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'item_queue_id' })
|
||||||
|
item_queue: ItemQueueModel;
|
||||||
|
|
||||||
|
@Column('varchar', { name: 'item_queue_id', nullable: true })
|
||||||
|
item_queue_id: string;
|
||||||
|
|
||||||
// relation ke tenant
|
// relation ke tenant
|
||||||
// ? karena item bisajadi merupakan item dari tenant
|
// ? karena item bisajadi merupakan item dari tenant
|
||||||
@Column('varchar', { name: 'tenant_id', nullable: true })
|
@Column('varchar', { name: 'tenant_id', nullable: true })
|
||||||
|
|
|
@ -6,6 +6,7 @@ export interface ItemEntity extends BaseStatusEntity {
|
||||||
name: string;
|
name: string;
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
image_url: string;
|
image_url: string;
|
||||||
|
video_url?: string[];
|
||||||
|
|
||||||
hpp: number;
|
hpp: number;
|
||||||
sales_margin: number;
|
sales_margin: number;
|
||||||
|
|
|
@ -34,6 +34,7 @@ export class DetailItemManager extends BaseDetailManager<ItemEntity> {
|
||||||
return [
|
return [
|
||||||
`${this.tableName}.id`,
|
`${this.tableName}.id`,
|
||||||
`${this.tableName}.image_url`,
|
`${this.tableName}.image_url`,
|
||||||
|
`${this.tableName}.video_url`,
|
||||||
`${this.tableName}.created_at`,
|
`${this.tableName}.created_at`,
|
||||||
`${this.tableName}.status`,
|
`${this.tableName}.status`,
|
||||||
`${this.tableName}.item_type`,
|
`${this.tableName}.item_type`,
|
||||||
|
|
|
@ -84,6 +84,12 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
setQueryFilter(
|
setQueryFilter(
|
||||||
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
||||||
): SelectQueryBuilder<ItemEntity> {
|
): SelectQueryBuilder<ItemEntity> {
|
||||||
|
if (this.filterParam.q) {
|
||||||
|
queryBuilder.andWhere(
|
||||||
|
`${this.tableName}.name ILIKE '%${this.filterParam.q}%'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.filterParam.tenant_ids?.length) {
|
if (this.filterParam.tenant_ids?.length) {
|
||||||
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
|
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
|
||||||
tenantIds: this.filterParam.tenant_ids,
|
tenantIds: this.filterParam.tenant_ids,
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
ValidateIf,
|
ValidateIf,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { ItemCategoryEntity } from 'src/modules/item-related/item-category/domain/entities/item-category.entity';
|
import { ItemCategoryEntity } from 'src/modules/item-related/item-category/domain/entities/item-category.entity';
|
||||||
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class ItemDto extends BaseStatusDto implements ItemEntity {
|
export class ItemDto extends BaseStatusDto implements ItemEntity {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
@ -31,6 +32,18 @@ export class ItemDto extends BaseStatusDto implements ItemEntity {
|
||||||
@ValidateIf((body) => body.image)
|
@ValidateIf((body) => body.image)
|
||||||
image_url: string;
|
image_url: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
isArray: true,
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
// @IsString()
|
||||||
|
@ValidateIf((body) => body.video_url)
|
||||||
|
@Transform(({ value }) => {
|
||||||
|
if (!value) return [];
|
||||||
|
return Array.isArray(value) ? value : [value];
|
||||||
|
})
|
||||||
|
video_url: string[];
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
|
|
|
@ -41,18 +41,18 @@ export class ItemReadController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags(`Item Queue - Read`)
|
// @ApiTags(`Item Queue - Read`)
|
||||||
@Controller(`v1/item-queue`)
|
// @Controller(`v1/item-queue`)
|
||||||
@Public(true)
|
// @Public(true)
|
||||||
export class ItemReadQueueController {
|
// export class ItemReadQueueController {
|
||||||
constructor(private orchestrator: ItemReadOrchestrator) {}
|
// constructor(private orchestrator: ItemReadOrchestrator) {}
|
||||||
|
|
||||||
@Get()
|
// @Get()
|
||||||
@Pagination()
|
// @Pagination()
|
||||||
@ExcludePrivilege()
|
// @ExcludePrivilege()
|
||||||
async indexQueue(
|
// async indexQueue(
|
||||||
@Query() params: FilterItemDto,
|
// @Query() params: FilterItemDto,
|
||||||
): Promise<PaginationResponse<ItemEntity>> {
|
// ): Promise<PaginationResponse<ItemEntity>> {
|
||||||
return await this.orchestrator.indexQueue(params);
|
// return await this.orchestrator.indexQueue(params);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { ItemDataService } from './data/services/item-data.service';
|
||||||
import { ItemReadService } from './data/services/item-read.service';
|
import { ItemReadService } from './data/services/item-read.service';
|
||||||
import {
|
import {
|
||||||
ItemReadController,
|
ItemReadController,
|
||||||
ItemReadQueueController,
|
// ItemReadQueueController,
|
||||||
} from './infrastructure/item-read.controller';
|
} from './infrastructure/item-read.controller';
|
||||||
import { ItemReadOrchestrator } from './domain/usecases/item-read.orchestrator';
|
import { ItemReadOrchestrator } from './domain/usecases/item-read.orchestrator';
|
||||||
import { ItemDataController } from './infrastructure/item-data.controller';
|
import { ItemDataController } from './infrastructure/item-data.controller';
|
||||||
|
@ -44,7 +44,7 @@ import { IndexItemQueueManager } from './domain/usecases/managers/index-queue-it
|
||||||
controllers: [
|
controllers: [
|
||||||
ItemDataController,
|
ItemDataController,
|
||||||
ItemReadController,
|
ItemReadController,
|
||||||
ItemReadQueueController,
|
// ItemReadQueueController,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
IndexItemManager,
|
IndexItemManager,
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
import { QueueBucket } from '../../domain/entities/queue-bucket.entity';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.QUEUE_BUCKET)
|
||||||
|
export class QueueBucketModel implements QueueBucket {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
queue_item_id: string;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint', nullable: false })
|
||||||
|
date: number;
|
||||||
|
|
||||||
|
@Column('int')
|
||||||
|
regular: number;
|
||||||
|
|
||||||
|
@Column('int')
|
||||||
|
vip: number;
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
import { BaseCoreModel } from 'src/core/modules/data/model/base-core.model';
|
||||||
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
|
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||||
|
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
||||||
|
|
||||||
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
|
import { Queue } from '../../domain/entities/queue.entity';
|
||||||
|
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.QUEUE_ORDER)
|
||||||
|
export class QueueOrderModel
|
||||||
|
extends BaseCoreModel<QueueOrderModel>
|
||||||
|
implements QueueOrder
|
||||||
|
{
|
||||||
|
@Column('varchar')
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: true })
|
||||||
|
customer: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: true })
|
||||||
|
phone: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: false })
|
||||||
|
transaction_id: string;
|
||||||
|
|
||||||
|
@OneToMany(() => QueueTicketModel, (model) => model.order, {
|
||||||
|
cascade: true,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
tickets: QueueTicket[];
|
||||||
|
|
||||||
|
@Column({ type: 'bigint' })
|
||||||
|
date: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.QUEUE_TICKET)
|
||||||
|
export class QueueTicketModel
|
||||||
|
extends BaseCoreModel<QueueTicketModel>
|
||||||
|
implements QueueTicket
|
||||||
|
{
|
||||||
|
@Column('varchar')
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: true })
|
||||||
|
customer: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: true })
|
||||||
|
phone: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => QueueOrderModel, (model) => model.tickets, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'order_id' })
|
||||||
|
order: QueueOrder;
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
order_id: string;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint' })
|
||||||
|
date: number;
|
||||||
|
|
||||||
|
@OneToMany(() => QueueItemModel, (model) => model.ticket, {
|
||||||
|
cascade: true,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
items: QueueItemModel[];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.QUEUE_ITEM)
|
||||||
|
export class QueueItemModel
|
||||||
|
extends BaseCoreModel<QueueItemModel>
|
||||||
|
implements QueueItem
|
||||||
|
{
|
||||||
|
@ManyToOne(() => QueueTicketModel, (model) => model.items, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'ticket_id' })
|
||||||
|
ticket: QueueTicket;
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
ticket_id: string;
|
||||||
|
|
||||||
|
@OneToMany(() => QueueModel, (model) => model.item, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
queue: QueueModel[];
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
item_id: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => ItemModel)
|
||||||
|
@JoinColumn({ name: 'item_id' })
|
||||||
|
item: ItemModel;
|
||||||
|
|
||||||
|
@Column('int')
|
||||||
|
qty: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(TABLE_NAME.QUEUE)
|
||||||
|
export class QueueModel extends BaseModel<Queue> implements Queue {
|
||||||
|
@Column('varchar')
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint' })
|
||||||
|
time: number;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint', nullable: true })
|
||||||
|
last_notification: number;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint' })
|
||||||
|
call_time: number;
|
||||||
|
|
||||||
|
@Column({ type: 'boolean' })
|
||||||
|
vip: boolean;
|
||||||
|
|
||||||
|
@ManyToOne(() => QueueItemModel, (model) => model.queue, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
onUpdate: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn({ name: 'item_id' })
|
||||||
|
item: QueueItemModel;
|
||||||
|
|
||||||
|
@Column('varchar')
|
||||||
|
item_id: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: true })
|
||||||
|
item_queue_id: string;
|
||||||
|
|
||||||
|
@Column('int')
|
||||||
|
qty: number;
|
||||||
|
|
||||||
|
average = 0;
|
||||||
|
peak_level = 100;
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { Between, Repository } from 'typeorm';
|
||||||
|
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||||
|
import { QueueBucketModel } from '../models/queue-bucket.model';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { QueueItemModel } from '../models/queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class QueueBucketReadService extends BaseReadService<QueueBucketModel> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(QueueBucketModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<QueueBucketModel>,
|
||||||
|
|
||||||
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private item: Repository<QueueItemModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getQueue(item_id: string, vip = false): Promise<number> {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
|
||||||
|
const queue = await this.repo.findOne({
|
||||||
|
where: {
|
||||||
|
queue_item_id: item_id,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!queue) {
|
||||||
|
const regularNumber = vip ? 0 : 1;
|
||||||
|
const vipNumber = vip ? 1 : 0;
|
||||||
|
await this.repo.save({
|
||||||
|
queue_item_id: item_id,
|
||||||
|
date: start,
|
||||||
|
regular: regularNumber,
|
||||||
|
vip: vipNumber,
|
||||||
|
});
|
||||||
|
return Promise.resolve(1);
|
||||||
|
} else {
|
||||||
|
const field = vip ? 'vip' : 'regular';
|
||||||
|
const data = await this.repo
|
||||||
|
.createQueryBuilder('bucket')
|
||||||
|
.update(QueueBucketModel)
|
||||||
|
.set({
|
||||||
|
[field]: () => `${field} + 1`,
|
||||||
|
})
|
||||||
|
.where('id = :key', {
|
||||||
|
key: queue.id,
|
||||||
|
})
|
||||||
|
.returning(field)
|
||||||
|
.updateEntity(true)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
return data.raw[0]?.[field] ?? 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,256 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { Between, DataSource, In, Not, Repository } from 'typeorm';
|
||||||
|
import {
|
||||||
|
QueueItemModel,
|
||||||
|
QueueModel,
|
||||||
|
QueueOrderModel,
|
||||||
|
} from '../models/queue.model';
|
||||||
|
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||||
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import * as math from 'mathjs';
|
||||||
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class QueueDataService extends BaseReadService<QueueModel> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(QueueModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<QueueModel>,
|
||||||
|
|
||||||
|
@InjectRepository(ItemQueueModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private itemQueueRepo: Repository<ItemQueueModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
async waitingQueue(item_queue_id: string) {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
return this.repo.find({
|
||||||
|
where: {
|
||||||
|
time: Between(start, end),
|
||||||
|
item_queue_id,
|
||||||
|
status: 'waiting',
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
time: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async doneQueue(item_queue_id: string) {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
return this.repo.find({
|
||||||
|
where: {
|
||||||
|
time: Between(start, end),
|
||||||
|
item_queue_id,
|
||||||
|
status: In(['done', 'called']),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
time: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async exclude(item_queue_id: string[]) {
|
||||||
|
const queues = await this.itemQueueRepo.find({
|
||||||
|
relations: ['items'],
|
||||||
|
where: {
|
||||||
|
id: Not(In(item_queue_id)),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return queues.filter((q) => q.items.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async allQueue() {
|
||||||
|
const queues = await this.itemQueueRepo.find({
|
||||||
|
relations: ['items'],
|
||||||
|
});
|
||||||
|
|
||||||
|
return queues.filter((q) => q.items.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async lastQueue(item_queue_id: string) {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
return this.repo.findOne({
|
||||||
|
where: {
|
||||||
|
time: Between(start, end),
|
||||||
|
item_queue_id,
|
||||||
|
status: 'called',
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
call_time: 'DESC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Change to QueueTimeFormula (queue-time.formula.ts)
|
||||||
|
* @param item_queue_id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async queueTimes(item_queue_id: string): Promise<any> {
|
||||||
|
const queueTimes = {};
|
||||||
|
let now = moment().valueOf();
|
||||||
|
const itemQueue = await this.itemQueueRepo.findOne({
|
||||||
|
relations: ['items'],
|
||||||
|
where: {
|
||||||
|
id: item_queue_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
||||||
|
const average = math.mean(times) * 60 * 1000; // change average minute to milliseconds
|
||||||
|
const queues = await this.repo.find({
|
||||||
|
where: {
|
||||||
|
item_queue_id,
|
||||||
|
status: 'waiting',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
queueTimes[queues[0].id] = now; // first queue will be now
|
||||||
|
|
||||||
|
for (let i = 1; i < queues.length; i++) {
|
||||||
|
const queue = queues[i];
|
||||||
|
// duration will be total qty multiple by average
|
||||||
|
const duration = queue.qty * average;
|
||||||
|
|
||||||
|
// time to call will be now + duration
|
||||||
|
const time = now + duration;
|
||||||
|
queueTimes[queue.id] = time;
|
||||||
|
|
||||||
|
// update now to last call time
|
||||||
|
now = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queueTimes;
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueItems(item_queue_id: string[]): Promise<QueueModel[]> {
|
||||||
|
return this.repo.find({
|
||||||
|
relations: ['item', 'item.item', 'item.item.item_queue'],
|
||||||
|
where: {
|
||||||
|
item: { item: { item_queue: { id: In(item_queue_id) } } },
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
time: 'DESC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class QueueService extends BaseDataService<QueueModel> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(QueueModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<QueueModel>,
|
||||||
|
|
||||||
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private item: Repository<QueueItemModel>,
|
||||||
|
|
||||||
|
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private itemMaster: Repository<ItemModel>,
|
||||||
|
|
||||||
|
@InjectDataSource(CONNECTION_NAME.DEFAULT)
|
||||||
|
private dataSource: DataSource,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueTicket(queueId: string) {
|
||||||
|
return this.repo.findOne({
|
||||||
|
relations: ['item', 'item.ticket'],
|
||||||
|
where: {
|
||||||
|
id: queueId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queues(ids: string[]) {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
const playEstimations = {};
|
||||||
|
const queuePeakLevel = {};
|
||||||
|
|
||||||
|
for (const id of ids) {
|
||||||
|
const est = await this.itemAverageTimeEstimation(id);
|
||||||
|
playEstimations[id] = est.average;
|
||||||
|
queuePeakLevel[id] = est.peakLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
const queues = await this.repo.find({
|
||||||
|
where: {
|
||||||
|
item_queue_id: In(ids),
|
||||||
|
time: Between(start, end),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
time: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
queues.forEach((queue) => {
|
||||||
|
queue.average = playEstimations[queue.item_queue_id];
|
||||||
|
queue.peak_level = queuePeakLevel[queue.item_queue_id];
|
||||||
|
});
|
||||||
|
|
||||||
|
return queues;
|
||||||
|
}
|
||||||
|
|
||||||
|
async itemAverageTimeEstimation(item_queue_id: string) {
|
||||||
|
const items = await this.itemMaster.find({
|
||||||
|
relations: ['item_queue'],
|
||||||
|
where: {
|
||||||
|
item_queue_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const times = items.map((item) => item.play_estimation ?? 0);
|
||||||
|
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
||||||
|
const peakLevel = items[0]?.item_queue?.max_peak_level ?? 100;
|
||||||
|
return { average, peakLevel };
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTicketItems(ticket_id: string, item_id: string) {
|
||||||
|
return this.item.findOneOrFail({
|
||||||
|
relations: ['item'],
|
||||||
|
where: [
|
||||||
|
{
|
||||||
|
ticket_id,
|
||||||
|
item_id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ticket_id,
|
||||||
|
item: { item_queue_id: item_id },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateLastNotification(queue_id: string, time: number) {
|
||||||
|
const query = `UPDATE queues SET last_notification = ${time} WHERE id = '${queue_id}'`;
|
||||||
|
this.dataSource.query(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateItemQty(item_id: string, qty: number): Promise<void> {
|
||||||
|
const query = `UPDATE queue_items SET qty = qty - ${qty} WHERE id = '${item_id}'`;
|
||||||
|
this.dataSource.query(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class QueueOrderService extends BaseDataService<QueueOrderModel> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(QueueOrderModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<QueueOrderModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,304 @@
|
||||||
|
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||||
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
import { Between, In, IsNull, Like, Not, Repository } from 'typeorm';
|
||||||
|
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||||
|
import {
|
||||||
|
QueueItemModel,
|
||||||
|
QueueOrderModel,
|
||||||
|
QueueTicketModel,
|
||||||
|
} from '../models/queue.model';
|
||||||
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(QueueTicketModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private repo: Repository<QueueTicketModel>,
|
||||||
|
|
||||||
|
@InjectRepository(QueueOrderModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private order: Repository<QueueOrderModel>,
|
||||||
|
|
||||||
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private item: Repository<QueueItemModel>,
|
||||||
|
|
||||||
|
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private transaction: Repository<TransactionModel>,
|
||||||
|
) {
|
||||||
|
super(repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createQueueOrder(order: QueueOrder): Promise<QueueOrderModel> {
|
||||||
|
return await this.order.save(order);
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateQueueTicket(ticket: QueueTicket): Promise<QueueTicketModel> {
|
||||||
|
return await this.repo.save(ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
async loginQueue(id: string): Promise<QueueOrder> {
|
||||||
|
const order = await this.order.findOne({
|
||||||
|
relations: ['tickets'],
|
||||||
|
where: [
|
||||||
|
{ transaction_id: id },
|
||||||
|
{ code: id, transaction_id: Not(IsNull()) },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!order) {
|
||||||
|
const { customer_name, customer_phone } =
|
||||||
|
await this.transaction.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
const order = this.order.findOneOrFail({
|
||||||
|
relations: ['tickets'],
|
||||||
|
where: {
|
||||||
|
customer: customer_name,
|
||||||
|
phone: customer_phone,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
async ticketByCode(code: string): Promise<QueueTicketModel[]> {
|
||||||
|
return this.repo.find({
|
||||||
|
where: {
|
||||||
|
code: Like(`${code}%`),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async ticketByUser(user: string, phone: string): Promise<QueueTicket> {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
|
||||||
|
return this.repo.findOne({
|
||||||
|
relations: ['items'],
|
||||||
|
where: {
|
||||||
|
customer: user,
|
||||||
|
phone: phone,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async loginPhone(user: string, phone: string): Promise<QueueOrder> {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
|
||||||
|
return this.order.findOneOrFail({
|
||||||
|
relations: ['tickets'],
|
||||||
|
where: {
|
||||||
|
customer: user,
|
||||||
|
phone: `+${phone}`,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async orders(order_id: string): Promise<QueueOrderModel[]> {
|
||||||
|
const order = await this.order.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id: order_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (order.transaction_id != null) {
|
||||||
|
return this.order.find({
|
||||||
|
where: {
|
||||||
|
code: order.code,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [order];
|
||||||
|
}
|
||||||
|
|
||||||
|
async transactions(transaction_id: string): Promise<QueueOrderModel[]> {
|
||||||
|
const order = await this.order.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
transaction_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (order.transaction_id != null) {
|
||||||
|
return this.order.find({
|
||||||
|
where: {
|
||||||
|
code: order.code,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [order];
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteQueue(transaction_id: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const transactions = await this.transactions(transaction_id);
|
||||||
|
await this.order.remove(transactions);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('transaction not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async orderIds(order_id: string): Promise<string[]> {
|
||||||
|
const orders = await this.orders(order_id);
|
||||||
|
|
||||||
|
return orders.map((order) => order.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async orderItems(
|
||||||
|
order_id: string,
|
||||||
|
item_ids: string[],
|
||||||
|
): Promise<QueueOrderModel> {
|
||||||
|
const order = await this.orderIds(order_id);
|
||||||
|
try {
|
||||||
|
const ticket = await this.order.findOneOrFail({
|
||||||
|
relations: ['tickets', 'tickets.items'],
|
||||||
|
where: {
|
||||||
|
tickets: {
|
||||||
|
order_id: In(order),
|
||||||
|
items: {
|
||||||
|
id: In(item_ids),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
} catch (error) {
|
||||||
|
throw new UnprocessableEntityException('Ticket tidak dapat ditemukan');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async queuePosTickets(order_id: string): Promise<QueueTicketModel[]> {
|
||||||
|
return this.repo.find({
|
||||||
|
relations: [
|
||||||
|
'items',
|
||||||
|
'items.queue',
|
||||||
|
'items.item',
|
||||||
|
'items.item.item_queue',
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
order_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueTickets(order_id: string): Promise<QueueTicketModel[]> {
|
||||||
|
const order = await this.orderIds(order_id);
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
return this.repo.find({
|
||||||
|
relations: [
|
||||||
|
'items',
|
||||||
|
'items.queue',
|
||||||
|
'items.item',
|
||||||
|
'items.item.item_queue',
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
order_id: In(order),
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueUniqueTickets(order_id: string): Promise<QueueTicketModel[]> {
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
return this.repo.find({
|
||||||
|
relations: [
|
||||||
|
'items',
|
||||||
|
'items.queue',
|
||||||
|
'items.item',
|
||||||
|
'items.item.item_queue',
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
order_id: order_id,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueTicketItems(
|
||||||
|
order_id: string,
|
||||||
|
ticket_id: string,
|
||||||
|
): Promise<QueueTicketModel[]> {
|
||||||
|
const order = await this.orderIds(order_id);
|
||||||
|
return this.repo.find({
|
||||||
|
relations: [
|
||||||
|
'items',
|
||||||
|
'items.queue',
|
||||||
|
'items.item',
|
||||||
|
'items.item.item_queue',
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
order_id: In(order),
|
||||||
|
id: ticket_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueTicketActive(
|
||||||
|
order_id: string,
|
||||||
|
ticket_id: string,
|
||||||
|
): Promise<QueueTicketModel[]> {
|
||||||
|
// const order = await this.orderIds(order_id);
|
||||||
|
return this.repo.find({
|
||||||
|
relations: ['items', 'items.queue'],
|
||||||
|
where: {
|
||||||
|
// order_id: In(order),
|
||||||
|
id: ticket_id,
|
||||||
|
// items: {
|
||||||
|
// queue: {
|
||||||
|
// status: In(['waiting']),
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueItemTickets(
|
||||||
|
order_id: string,
|
||||||
|
item_id: string,
|
||||||
|
): Promise<QueueTicketModel[]> {
|
||||||
|
const order = await this.orderIds(order_id);
|
||||||
|
return this.repo.find({
|
||||||
|
relations: [
|
||||||
|
'items',
|
||||||
|
'items.queue',
|
||||||
|
'items.item',
|
||||||
|
'items.item.item_queue',
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
order_id: In(order),
|
||||||
|
items: [{ item_id }, { item: { item_queue: { id: item_id } } }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueItems(order_id: string): Promise<QueueItemModel[]> {
|
||||||
|
const order = await this.orderIds(order_id);
|
||||||
|
return this.item.find({
|
||||||
|
relations: ['queue', 'ticket'],
|
||||||
|
where: {
|
||||||
|
ticket: {
|
||||||
|
order_id: In(order),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue