Compare commits
398 Commits
feat/fix-c
...
developmen
Author | SHA1 | Date |
---|---|---|
|
7bb539db0c | |
|
92b54635d0 | |
|
7be4c26ef2 | |
|
23b3c31810 | |
|
b96d24de1a | |
|
5d3f9d7bff | |
|
831593e743 | |
|
162bd0918f | |
|
13b5838393 | |
|
63bb55b04b | |
|
9d1c240b6b | |
|
83f3377465 | |
|
69c2ee06cf | |
|
42060384aa | |
|
62cfb1f1a8 | |
|
08a35dfdf4 | |
|
8df836ff3e | |
|
822cfe606a | |
|
de43f0f28b | |
|
09b0133bf4 | |
|
a77e6b0381 | |
|
a5da557dd9 | |
|
afad02ba52 | |
|
6636c596f4 | |
|
01fb358875 | |
|
f9dc49f7d5 | |
|
1d9cdfe8e6 | |
|
ccc363f74f | |
|
af1ee2fbee | |
|
ec5229645f | |
|
47d45cb65c | |
|
d6717c9c60 | |
|
d995982203 | |
|
56e475d61f | |
|
3116acd5ab | |
|
068c4ce349 | |
|
79c9139c3c | |
|
d4e8e72af0 | |
|
7dd29c2a70 | |
|
0b5b0ce09b | |
|
e1d3ee7188 | |
|
838670c822 | |
|
34d8882ec3 | |
|
8fb8aac0f9 | |
|
3a0efb00a9 | |
|
737575176e | |
|
f0e8fbddc9 | |
|
d8fa72ba20 | |
|
ab9db39a5f | |
|
7c45a20866 | |
|
7ff0040f9e | |
|
9bbd37ba38 | |
|
b476c92b70 | |
|
dc926d84e4 | |
|
0172eea573 | |
|
464f5cb49e | |
|
1e395ae53f | |
|
2f2fc27965 | |
|
0512c51f8e | |
|
6da2118ab5 | |
|
033ed0046e | |
|
fdbd667b7d | |
|
baeb72fe7d | |
|
4e2ec4d94f | |
|
94fbec0c78 | |
|
e24fee86ba | |
|
16df6945b7 | |
|
8497a5779d | |
|
399ca0bdda | |
|
b8dd2a4e01 | |
|
6a7ab72e12 | |
|
ffc75ba174 | |
|
18afc47030 | |
|
dc1fadbe1f | |
|
a1ed81eec5 | |
|
8192396085 | |
|
3661d9d171 | |
|
d4d605d168 | |
|
10a553ac9d | |
|
d95f8fd6e5 | |
|
9bc2f5fde2 | |
|
0d8ec858eb | |
|
c97399ae8f | |
|
5b7df0e372 | |
|
ca886069f1 | |
|
73c87f6819 | |
|
d86f4075d4 | |
|
88753546b6 | |
|
cc78dfbd06 | |
|
f9025faf0b | |
|
6a0b1f6e05 | |
|
67129a8c69 | |
|
798476aaf5 | |
|
ee52a35af2 | |
|
538abb122f | |
|
36b6ee733f | |
|
d8cfa97612 | |
|
5f08b4be66 | |
|
5e328fda1e | |
|
ffd8595ab2 | |
|
63e43a7ba0 | |
|
bc8a0407a6 | |
|
9a3d544699 | |
|
845e0547ab | |
|
9e5d59baac | |
|
89dc1fc160 | |
|
16bbb1f02b | |
|
339b2bdab6 | |
|
a80e2e3419 | |
|
3b362d2822 | |
|
b4f39d5ccf | |
|
7c5b1b3aa8 | |
|
9e361da9cb | |
|
94e769795a | |
|
968697ee17 | |
|
0757d6791d | |
|
a438cc5f83 | |
|
2dd0bd45a8 | |
|
027025935c | |
|
10cd1a711e | |
|
bad4b2ea56 | |
|
35919b91f7 | |
|
8afbe33c01 | |
|
f2d7ea80d2 | |
|
b18a834129 | |
|
928e2e7648 | |
|
9b1f945873 | |
|
6882314a9e | |
|
94baf956dd | |
|
e92f325807 | |
|
66d76634b7 | |
|
b91080906e | |
|
714b075e1d | |
|
da024606ff | |
|
0b482be669 | |
|
064112e731 | |
|
05473fce3d | |
|
d6a238a224 | |
|
a8b3f67d1b | |
|
dc5e938f75 | |
|
eb4da7ccc4 | |
|
bef9f99f13 | |
|
46caaba6bd | |
|
8e0c8462b9 | |
|
7953c7dbbd | |
|
6911f6f0a2 | |
|
762340a72b | |
|
00e2b6e015 | |
|
61cbbf81ef | |
|
7b864d4163 | |
|
4ea53f7088 | |
|
00ec2c9342 | |
|
0548141e5f | |
|
440a589f8a | |
|
29e4dc5400 | |
|
f9d8f85179 | |
|
769e8174f4 | |
|
3ace59c450 | |
|
a51b6ea520 | |
|
187555a543 | |
|
750cee8853 | |
|
551bd12f5b | |
|
0a98bcfd59 | |
|
1692c8234a | |
|
9a612cc025 | |
|
903b7cfd18 | |
|
3aee1fdfc9 | |
|
26a6af2044 | |
|
0afaf1d195 | |
|
d7ed77934d | |
|
66720c5b8b | |
|
44e74de315 | |
|
82e7879969 | |
|
ceedf83385 | |
|
d612b6725a | |
|
54b9658075 | |
|
13ae23000f | |
|
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 | |
|
51be95b5ff | |
|
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 | |
|
b2659def9a | |
|
d597734467 | |
|
27a0c56af7 | |
|
50ac2d97a4 | |
|
d788a9f1a1 | |
|
c897e4fcde | |
|
14dd2880bc | |
|
3e920755bd | |
|
88b4c66139 | |
|
52c82a9a41 | |
|
19494b3328 | |
|
e1f2cdfa4d | |
|
918055beb9 | |
|
283b783007 | |
|
a2be2bb331 | |
|
d708ef9eee | |
|
9709c4719b | |
|
d2db62339f | |
|
07d1cc78e2 | |
|
8f430574ed | |
|
f7198010d3 | |
|
a1641504f1 | |
|
6c5019f814 | |
|
ff0ef28783 | |
|
40aafaf571 | |
|
6fbb2e33b2 | |
|
b20385dacc | |
|
6e5b19380b | |
|
ab9ec4ac0e | |
|
0457fc9e1d | |
|
3658ae4cdf | |
|
d1b20e6b96 | |
|
f4ecbf0e66 | |
|
7da22277f1 | |
|
bf73cb6b43 | |
|
6fb582204a | |
|
d283caa898 | |
|
1320492bf1 | |
|
4c25b2cbec | |
|
a6b1e5f49f | |
|
ac3ee266b9 | |
|
3720df31d8 |
89
.drone.yml
89
.drone.yml
|
@ -2,29 +2,37 @@ kind: pipeline
|
|||
type: docker
|
||||
name: server
|
||||
steps:
|
||||
- name: build
|
||||
image: appleboy/drone-ssh
|
||||
# - name: build
|
||||
# image: appleboy/drone-ssh
|
||||
# settings:
|
||||
# host:
|
||||
# - 172.10.10.10
|
||||
# username: eigen
|
||||
# key:
|
||||
# from_secret: DEVOPS_SSH_PRIVATE_OPEN
|
||||
# port: 22
|
||||
# script:
|
||||
# - cd /home/eigen/PROJECT/POS/POS.DEV/BE
|
||||
# - sh build.sh
|
||||
# when:
|
||||
# ref:
|
||||
# - refs/tags/devel_*
|
||||
# - refs/tags/*-alpha.*
|
||||
- name: build-testing
|
||||
image: plugins/docker
|
||||
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
|
||||
registry: registry.eigen.co.id
|
||||
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
||||
tags: ${DRONE_TAG}
|
||||
custom_dns: 172.10.10.16
|
||||
when:
|
||||
ref:
|
||||
- refs/tags/devel_*
|
||||
- refs/tags/*-alpha.*
|
||||
- name: build-production
|
||||
image: plugins/docker
|
||||
settings:
|
||||
registry: registry.eigen.co.id
|
||||
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
||||
build_args:
|
||||
- env_target=env.production
|
||||
tags: ${DRONE_TAG}
|
||||
custom_dns: 172.10.10.16
|
||||
when:
|
||||
|
@ -46,3 +54,56 @@ trigger:
|
|||
event:
|
||||
exclude:
|
||||
- promote
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: kustomize
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
||||
steps:
|
||||
- name: kustomize-testing
|
||||
image: registry.k8s.io/kustomize/kustomize:v5.0.0
|
||||
environment:
|
||||
DEVOPS_SSH_PRIVATE:
|
||||
from_secret: DEVOPS_SSH_PRIVATE
|
||||
DEVOPS_SSH_PUBLIC:
|
||||
from_secret: DEVOPS_SSH_PUBLIC
|
||||
INFRASTRUCTURE_REPO: "k8s-kustomize-external"
|
||||
DIRECTORY_NAME: "weplay-pos-testing"
|
||||
commands:
|
||||
- mkdir -p ~/.ssh &&
|
||||
- echo $DEVOPS_SSH_PRIVATE | base64 -d > ~/.ssh/id_rsa &&
|
||||
- echo $DEVOPS_SSH_PUBLIC | base64 -d > ~/.ssh/id_rsa.pub &&
|
||||
- ssh-keyscan -H -p 2222 git.eigen.co.id >> ~/.ssh/known_hosts &&
|
||||
- chmod 700 ~/.ssh/ &&
|
||||
- chmod 600 ~/.ssh/id_rsa &&
|
||||
- git clone ssh://git@git.eigen.co.id:2222/eigen/$INFRASTRUCTURE_REPO.git &&
|
||||
- cd $INFRASTRUCTURE_REPO/$DIRECTORY_NAME
|
||||
- kustomize edit set image registry.eigen.co.id/eigen/$DRONE_REPO_NAME=registry.eigen.co.id/eigen/$DRONE_REPO_NAME:$DRONE_TAG &&
|
||||
- git add . &&
|
||||
- |-
|
||||
git commit -m "feat: update $DRONE_REPO_NAME testing to $DRONE_TAG" &&
|
||||
- git push origin master
|
||||
- name: send-message
|
||||
image: harbor.eigen.co.id/docker.com/plugins/webhook
|
||||
settings:
|
||||
urls: https://mattermost.eigen.co.id/api/v4/posts
|
||||
content_type: application/json
|
||||
headers:
|
||||
- Authorization=Bearer 5zubexudb38uuradfa36qy98ca
|
||||
template: |
|
||||
{
|
||||
"channel_id": "s1ekqde1c3du5p35g6budnuotc",
|
||||
"message": "ALERT: {{ repo.name }} gagal update dengan tag ${DRONE_TAG}"
|
||||
}
|
||||
when:
|
||||
status:
|
||||
- failure
|
||||
trigger:
|
||||
ref:
|
||||
include:
|
||||
- refs/tags/*-alpha.*
|
||||
depends_on:
|
||||
- server
|
|
@ -1602,7 +1602,7 @@
|
|||
mso-line-height-rule: exactly;
|
||||
mso-text-raise: 2px;
|
||||
"
|
||||
>Pay Here</a
|
||||
>Click Here to Pay</a
|
||||
>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -44,3 +44,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
|||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||
SUPERSET_ADMIN_USERNAME=admin
|
||||
SUPERSET_ADMIN_PASSWORD=admin
|
||||
|
||||
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -41,3 +41,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
|||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||
SUPERSET_ADMIN_USERNAME=admin
|
||||
SUPERSET_ADMIN_PASSWORD=admin
|
||||
|
||||
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -49,6 +49,7 @@
|
|||
"exceljs": "^4.4.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"googleapis": "^140.0.0",
|
||||
"gtts": "^0.2.1",
|
||||
"handlebars": "^4.7.8",
|
||||
"mathjs": "^13.0.2",
|
||||
"midtrans-client": "^1.3.1",
|
||||
|
@ -58,6 +59,7 @@
|
|||
"pdfmake": "^0.2.10",
|
||||
"pg": "^8.11.5",
|
||||
"plop": "^4.0.1",
|
||||
"qrcode": "^1.5.4",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.5.0",
|
||||
"typeorm": "^0.3.20",
|
||||
|
@ -70,6 +72,7 @@
|
|||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "29.5.12",
|
||||
"@types/node": "^20.12.13",
|
||||
"@types/qrcode": "^1.5.5",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
|
|
|
@ -33,7 +33,10 @@ import { SeasonTypeModel } from './modules/season-related/season-type/data/model
|
|||
import { TaxModule } from './modules/transaction/tax/tax.module';
|
||||
import { TaxModel } from './modules/transaction/tax/data/models/tax.model';
|
||||
import { SalesPriceFormulaModule } from './modules/transaction/sales-price-formula/sales-price-formula.module';
|
||||
import { SalesPriceFormulaModel } from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
|
||||
import { ProfitShareFormulaModule } from './modules/transaction/profit-share-formula/profit-share-formula.module';
|
||||
import { PaymentMethodModule } from './modules/transaction/payment-method/payment-method.module';
|
||||
import { PaymentMethodModel } from './modules/transaction/payment-method/data/models/payment-method.model';
|
||||
|
@ -45,8 +48,10 @@ import { GoogleCalendarModule } from './modules/configuration/google-calendar/go
|
|||
import { TransactionModule } from './modules/transaction/transaction/transaction.module';
|
||||
import { TransactionModel } from './modules/transaction/transaction/data/models/transaction.model';
|
||||
import {
|
||||
TransactionBreakdownTaxModel,
|
||||
TransactionItemBreakdownModel,
|
||||
TransactionItemModel,
|
||||
TransactionItemTaxModel,
|
||||
} from './modules/transaction/transaction/data/models/transaction-item.model';
|
||||
import { TransactionTaxModel } from './modules/transaction/transaction/data/models/transaction-tax.model';
|
||||
import { ReconciliationModule } from './modules/transaction/reconciliation/reconciliation.module';
|
||||
|
@ -77,6 +82,31 @@ import { ExportModule } from './modules/configuration/export/export.module';
|
|||
import { TransactionDemographyModel } from './modules/transaction/transaction/data/models/transaction-demography.model';
|
||||
import { SupersetModule } from './modules/configuration/superset/superset.module';
|
||||
import { GateScanModule } from './modules/gates/gate.module';
|
||||
import { UserLoginModel } from './modules/user-related/user/data/models/user-login.model';
|
||||
import { LogUserLoginModel } from './modules/configuration/log/data/models/log-user-login.model';
|
||||
import { AuthService } from './core/guards/domain/services/auth.service';
|
||||
import { ReportSummaryModule } from './modules/reports/report-summary/report-summary.module';
|
||||
import { QueueModule } from './modules/queue/queue.module';
|
||||
import {
|
||||
QueueOrderModel,
|
||||
QueueTicketModel,
|
||||
QueueItemModel,
|
||||
QueueModel,
|
||||
} from './modules/queue/data/models/queue.model';
|
||||
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
|
||||
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
|
||||
import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model';
|
||||
import { VerificationModel } from './modules/booking-online/authentication/data/models/verification.model';
|
||||
import { BookingOnlineAuthModule } from './modules/booking-online/authentication/auth.module';
|
||||
import { BookingOrderModule } from './modules/booking-online/order/order.module';
|
||||
import { TimeGroupModule } from './modules/item-related/time-group/time-group.module';
|
||||
import { TimeGroupModel } from './modules/item-related/time-group/data/models/time-group.model';
|
||||
|
||||
import { OtpVerificationModule } from './modules/configuration/otp-verification/otp-verification.module';
|
||||
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
||||
import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -101,7 +131,10 @@ import { GateScanModule } from './modules/gates/gate.module';
|
|||
ItemModel,
|
||||
ItemCategoryModel,
|
||||
ItemRateModel,
|
||||
ItemQueueModel,
|
||||
TimeGroupModel,
|
||||
LogModel,
|
||||
LogUserLoginModel,
|
||||
NewsModel,
|
||||
PaymentMethodModel,
|
||||
PosLogModel,
|
||||
|
@ -117,13 +150,32 @@ import { GateScanModule } from './modules/gates/gate.module';
|
|||
TransactionTaxModel,
|
||||
TransactionDemographyModel,
|
||||
TransactionItemBreakdownModel,
|
||||
TransactionItemTaxModel,
|
||||
TransactionBreakdownTaxModel,
|
||||
TransactionSettingModel,
|
||||
UserModel,
|
||||
UserLoginModel,
|
||||
|
||||
VipCategoryModel,
|
||||
VipCodeModel,
|
||||
|
||||
// report
|
||||
ReportBookmarkModel,
|
||||
ExportReportHistoryModel,
|
||||
|
||||
// Queue
|
||||
QueueOrderModel,
|
||||
QueueTicketModel,
|
||||
QueueItemModel,
|
||||
QueueModel,
|
||||
QueueBucketModel,
|
||||
|
||||
// Booking Online
|
||||
VerificationModel,
|
||||
RescheduleVerificationModel,
|
||||
|
||||
OtpVerificationModel,
|
||||
OtpVerifierModel,
|
||||
],
|
||||
synchronize: false,
|
||||
}),
|
||||
|
@ -149,6 +201,8 @@ import { GateScanModule } from './modules/gates/gate.module';
|
|||
ItemCategoryModule,
|
||||
ItemModule,
|
||||
ItemRateModule,
|
||||
ItemQueueModule,
|
||||
TimeGroupModule,
|
||||
|
||||
// transaction
|
||||
PaymentMethodModule,
|
||||
|
@ -176,15 +230,25 @@ import { GateScanModule } from './modules/gates/gate.module';
|
|||
ReportModule,
|
||||
ReportBookmarkModule,
|
||||
ReportExportModule,
|
||||
ReportSummaryModule,
|
||||
|
||||
// superset
|
||||
SupersetModule,
|
||||
|
||||
GateScanModule,
|
||||
|
||||
QueueModule,
|
||||
|
||||
BookingOnlineAuthModule,
|
||||
BookingOrderModule,
|
||||
OtpVerificationModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [
|
||||
AuthService,
|
||||
PrivilegeService,
|
||||
OtpCheckerGuard,
|
||||
|
||||
/**
|
||||
* By default all request from client will protect by JWT
|
||||
* if there is some endpoint/function that does'nt require authentication
|
||||
|
|
|
@ -7,10 +7,10 @@ import {
|
|||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { SessionService, UsersSession } from 'src/core/sessions';
|
||||
import { UNPROTECTED_URL } from '../constants';
|
||||
import { PrivilegeService } from './services/privilege.service';
|
||||
import { AuthService } from './services/auth.service';
|
||||
|
||||
@Injectable({ scope: Scope.REQUEST })
|
||||
export class JWTGuard implements CanActivate {
|
||||
|
@ -18,14 +18,13 @@ export class JWTGuard implements CanActivate {
|
|||
protected readonly session: SessionService,
|
||||
protected readonly reflector: Reflector,
|
||||
protected readonly privilege: PrivilegeService,
|
||||
protected readonly authService: AuthService,
|
||||
) {}
|
||||
|
||||
protected isPublic = false;
|
||||
protected userSession: UsersSession;
|
||||
|
||||
canActivate(
|
||||
context: ExecutionContext,
|
||||
): boolean | Promise<boolean> | Observable<boolean> {
|
||||
async canActivate(context: ExecutionContext) {
|
||||
/**
|
||||
* Check if access url is protected or not
|
||||
* By default `isUnprotected` equals `false`
|
||||
|
@ -61,9 +60,29 @@ export class JWTGuard implements CanActivate {
|
|||
*/
|
||||
try {
|
||||
this.userSession = this.session.verifyToken(token);
|
||||
await this.authService.verifyRegisteredLoginToken(token);
|
||||
|
||||
Logger.log(`Access from ${this.userSession.name}`, 'AuthGuard');
|
||||
return true;
|
||||
} catch (error) {
|
||||
const expiredError = error.message;
|
||||
if (expiredError === 'jwt expired') {
|
||||
const [, body] = token.split('.');
|
||||
const bodyToken = JSON.parse(atob(body));
|
||||
|
||||
const user = {
|
||||
role: bodyToken.role,
|
||||
user_id: bodyToken.id,
|
||||
username: bodyToken.username,
|
||||
user_privilege_id: bodyToken.user_privilege_id,
|
||||
item_id: bodyToken.item_id,
|
||||
item_name: bodyToken.item_name,
|
||||
source: bodyToken.source,
|
||||
};
|
||||
|
||||
this.authService.logoutUser(user, token);
|
||||
}
|
||||
|
||||
throw new UnauthorizedException({
|
||||
code: 10001,
|
||||
message:
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectDataSource } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { OtpVerificationModel } from 'src/modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||
import { OtpVerificationEntity } from 'src/modules/configuration/otp-verification/domain/entities/otp-verification.entity';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class OtpCheckerGuard implements CanActivate {
|
||||
constructor(
|
||||
@InjectDataSource(CONNECTION_NAME.DEFAULT)
|
||||
protected readonly dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
get otpRepository() {
|
||||
return this.dataSource.getRepository(OtpVerificationModel);
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const verificationCode = request.headers['x-verification-code'];
|
||||
console.log({ verificationCode });
|
||||
|
||||
if (verificationCode) {
|
||||
const decoded = Buffer.from(verificationCode, 'base64').toString('ascii');
|
||||
const [dataIdentity, otpCode] = decoded.split('|');
|
||||
|
||||
let otpData: OtpVerificationEntity;
|
||||
|
||||
otpData = await this.otpRepository.findOne({
|
||||
where: {
|
||||
otp_code: otpCode,
|
||||
target_id: dataIdentity,
|
||||
},
|
||||
});
|
||||
|
||||
if (!otpData) {
|
||||
otpData = await this.otpRepository.findOne({
|
||||
where: {
|
||||
otp_code: otpCode,
|
||||
reference: dataIdentity,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// console.log({ dataIdentity, otpCode, otpData });
|
||||
if (otpData && otpData?.verified_at) return true;
|
||||
}
|
||||
|
||||
throw new UnprocessableEntityException('OTP not verified.');
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import { MAIN_MENU } from '../constants';
|
|||
@Injectable()
|
||||
export class RolesGuard extends JWTGuard {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
super.canActivate(context);
|
||||
await super.canActivate(context);
|
||||
|
||||
// jika endpoint tersebut bukan public, maka lakukan check lanjutan
|
||||
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',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
export enum LogUserType {
|
||||
login = 'login',
|
||||
logout = 'logout',
|
||||
}
|
||||
|
||||
export enum AppSource {
|
||||
POS_ADMIN = 'POS_ADMIN',
|
||||
POS_COUNTER = 'POS_COUNTER',
|
||||
QUEUE_ADMIN = 'QUEUE_ADMIN',
|
||||
QUEUE_CUSTOMER = 'QUEUE_CUSTOMER',
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
interface OtpServiceEntity {
|
||||
length?: number;
|
||||
}
|
||||
|
||||
export class OtpService {
|
||||
private readonly otpLength: number;
|
||||
|
||||
constructor({ length = 4 }: OtpServiceEntity) {
|
||||
this.otpLength = Math.max(length, 4); // Minimum of 4 digits
|
||||
}
|
||||
|
||||
private hasSequentialDigits(str: string): boolean {
|
||||
for (let i = 0; i < str.length - 1; i++) {
|
||||
const current = parseInt(str[i], 10);
|
||||
const next = parseInt(str[i + 1], 10);
|
||||
if (next === current + 1 || next === current - 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private hasRepeatedDigits(str: string): boolean {
|
||||
return str.split('').every((char) => char === str[0]);
|
||||
}
|
||||
|
||||
private isPalindrome(str: string): boolean {
|
||||
return str === str.split('').reverse().join('');
|
||||
}
|
||||
|
||||
private hasPartiallyRepeatedDigits(str: string): boolean {
|
||||
const counts: Record<string, number> = {};
|
||||
for (const char of str) {
|
||||
counts[char] = (counts[char] || 0) + 1;
|
||||
}
|
||||
|
||||
// Reject if any digit appears more than twice
|
||||
return Object.values(counts).some((count) => count > 2);
|
||||
}
|
||||
|
||||
private hasNoMatchLength(str: string) {
|
||||
return str.length !== this.otpLength;
|
||||
}
|
||||
|
||||
private hasStartWithZero(str: string) {
|
||||
return str.split('')[0] === '0';
|
||||
}
|
||||
|
||||
public generateSecureOTP(): string {
|
||||
let otp: string;
|
||||
|
||||
do {
|
||||
otp = Array.from({ length: this.otpLength }, () =>
|
||||
Math.floor(Math.random() * 10).toString(),
|
||||
).join('');
|
||||
} while (
|
||||
this.hasNoMatchLength(otp) ||
|
||||
this.hasSequentialDigits(otp) ||
|
||||
this.hasRepeatedDigits(otp) ||
|
||||
this.isPalindrome(otp) ||
|
||||
this.hasPartiallyRepeatedDigits(otp) ||
|
||||
this.hasStartWithZero(otp)
|
||||
);
|
||||
return otp;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,9 @@ import { diskStorage } from 'multer';
|
|||
const MB = 1024 * 1024;
|
||||
|
||||
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);
|
||||
} else {
|
||||
callback(
|
||||
|
|
|
@ -55,7 +55,7 @@ export class ValidateRelationHelper<Entity> {
|
|||
const relationColumn =
|
||||
data[relation.relation]?.[`${relation.singleQuery[0]}`];
|
||||
if (
|
||||
!!relationColumn &&
|
||||
// !!relationColumn &&
|
||||
this.mappingValidator(
|
||||
relationColumn,
|
||||
relation.singleQuery[1],
|
||||
|
|
|
@ -32,7 +32,7 @@ export abstract class BaseManager {
|
|||
|
||||
setUser() {
|
||||
try {
|
||||
this.user = this.userProvider?.user;
|
||||
this.user = this.userProvider?.user ?? BLANK_USER;
|
||||
} catch (error) {
|
||||
this.user = BLANK_USER;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
|||
}
|
||||
|
||||
async publishEvents() {
|
||||
this.eventBus.publish(
|
||||
this.eventBus?.publish(
|
||||
new RecordLog({
|
||||
id: this.result['id'],
|
||||
old: null,
|
||||
|
|
|
@ -50,7 +50,7 @@ export abstract class BaseIndexManager<Entity> extends BaseReadManager {
|
|||
|
||||
// jika searching status terdapat dalam enum, maka dia mencari specific data
|
||||
// ? karena jika tidak, ketika dia search "active" maka "inactive" juga ikut
|
||||
return `'${STATUS[statusData.toUpperCase()]}'` ?? `'%${statusData}%'`;
|
||||
return `'${STATUS[statusData.toUpperCase()]}'`;
|
||||
});
|
||||
|
||||
const exist = specificFilter.find((item) => item.isStatus);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import { ValidateRelationHelper } from 'src/core/helpers/validation/validate-relation.helper';
|
||||
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 { 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 result: Entity;
|
||||
protected oldData: Entity;
|
||||
protected dataStatus: STATUS;
|
||||
protected dataStatus: STATUS | QUEUE_STATUS;
|
||||
protected relations = [];
|
||||
protected duplicateColumn: string[];
|
||||
abstract get entityTarget(): any;
|
||||
|
||||
setData(id: string, status: STATUS): void {
|
||||
setData(id: string, status: STATUS | QUEUE_STATUS): void {
|
||||
/**
|
||||
* // TODO: Handle case confirm multiple tabs;
|
||||
* Pola id yang dikirim dirubah menjadi data_id___updated_at
|
||||
|
|
|
@ -23,6 +23,7 @@ export class BaseFilterDto implements BaseFilterEntity {
|
|||
@IsNumber()
|
||||
limit = 10;
|
||||
|
||||
@ApiProperty({ type: String, required: false })
|
||||
q: string;
|
||||
|
||||
@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';
|
||||
|
||||
export interface UsersSession {
|
||||
id: number;
|
||||
name: string;
|
||||
role: UserRole;
|
||||
source?: AppSource;
|
||||
item_id?: string;
|
||||
user_privilege_id: string;
|
||||
}
|
||||
|
|
|
@ -23,4 +23,9 @@ export class UserProvider {
|
|||
const [, token] = this.request.headers['authorization'].split(' ');
|
||||
return this.session.verifyToken(token);
|
||||
}
|
||||
|
||||
get token(): string {
|
||||
const [, token] = this.request.headers['authorization'].split(' ');
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@ export enum STATUS {
|
|||
WAITING = 'waiting',
|
||||
}
|
||||
|
||||
export enum QUEUE_STATUS {
|
||||
DONE = 'done',
|
||||
CALLED = 'called',
|
||||
}
|
||||
|
||||
export enum ORDER_TYPE {
|
||||
ASC = 'ASC',
|
||||
DESC = 'DESC',
|
||||
|
|
|
@ -4,6 +4,7 @@ export enum MODULE_NAME {
|
|||
GATE = 'gates',
|
||||
ITEM = 'items',
|
||||
ITEM_CATEGORY = 'item-categories',
|
||||
ITEM_QUEUE = 'item-queues',
|
||||
ITEM_RATE = 'item-rates',
|
||||
NEWS = 'news',
|
||||
PAYMENT_METHOD = 'payment-methods',
|
||||
|
@ -24,4 +25,12 @@ export enum MODULE_NAME {
|
|||
REPORT = 'report',
|
||||
REPORT_BOOKMARK = 'report-bookmark',
|
||||
REPORT_EXPORT = 'report-export',
|
||||
REPORT_SUMMARY = 'report-summary',
|
||||
|
||||
QUEUE = 'queue',
|
||||
|
||||
TIME_GROUPS = 'time-groups',
|
||||
OTP_VERIFICATIONS = 'otp-verification',
|
||||
|
||||
OTP_VERIFIER = 'otp-verifier',
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ export enum TABLE_NAME {
|
|||
FAQ = 'faqs',
|
||||
ITEM = 'items',
|
||||
ITEM_CATEGORY = 'item_categories',
|
||||
ITEM_QUEUE = 'item_queues',
|
||||
ITEM_RATE = 'item_rates',
|
||||
GATE = 'gates',
|
||||
LOG = 'logs',
|
||||
|
@ -11,6 +12,7 @@ export enum TABLE_NAME {
|
|||
NEWS = 'news',
|
||||
PAYMENT_METHOD = 'payment_methods',
|
||||
PRICE_FORMULA = 'price_formulas',
|
||||
TRANSACTION_SETTING = 'transaction_settings',
|
||||
REFUND = 'refunds',
|
||||
REFUND_ITEM = 'refund_items',
|
||||
SEASON_TYPE = 'season_types',
|
||||
|
@ -22,8 +24,12 @@ export enum TABLE_NAME {
|
|||
TRANSACTION_ITEM = 'transaction_items',
|
||||
TRANSACTION_ITEM_BREAKDOWN = 'transaction_item_breakdowns',
|
||||
TRANSACTION_TAX = 'transaction_taxes',
|
||||
TRANSACTION_ITEM_TAX = 'transaction_item_taxes',
|
||||
TRANSACTION_ITEM_BREAKDOWN_TAX = 't_breakdown_item_taxes',
|
||||
TRANSACTION_DEMOGRAPHY = 'transaction_demographies',
|
||||
USER = 'users',
|
||||
USER_LOGIN = 'users_login',
|
||||
LOG_USER_LOGIN = 'log_users_login',
|
||||
USER_PRIVILEGE = 'user_privileges',
|
||||
USER_PRIVILEGE_CONFIGURATION = 'user_privilege_configurations',
|
||||
VIP_CATEGORY = 'vip_categories',
|
||||
|
@ -31,4 +37,14 @@ export enum TABLE_NAME {
|
|||
|
||||
REPORT_BOOKMARK = 'report_bookmark',
|
||||
EXPORT_REPORT_HISTORY = 'export_report_history',
|
||||
|
||||
QUEUE = 'queues',
|
||||
QUEUE_ORDER = 'queue_orders',
|
||||
QUEUE_TICKET = 'queue_tickets',
|
||||
QUEUE_ITEM = 'queue_items',
|
||||
QUEUE_BUCKET = 'queue_bucket',
|
||||
|
||||
TIME_GROUPS = 'time_groups',
|
||||
OTP_VERIFICATIONS = 'otp_verifications',
|
||||
OTP_VERIFIER = 'otp_verifier',
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export class AddEstimationToItem1723801180604 implements MigrationInterface {
|
|||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD "play_estimation" integer`,
|
||||
`ALTER TABLE "items" ADD "play_estimation" numeric`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddPaymentDateBankColumnAtTransaction1725962197762
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddPaymentDateBankColumnAtTransaction1725962197762';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" ADD "payment_date_bank" date`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" DROP COLUMN "payment_date_bank"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddPosNameColumn1726033041774 implements MigrationInterface {
|
||||
name = 'AddPosNameColumn1726033041774';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" ADD "creator_counter_name" character varying`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "logs_pos" ADD "pos_name" character varying`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "logs_pos" DROP COLUMN "pos_name"`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" DROP COLUMN "creator_counter_name"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddFlagRoleQueue1726041175749 implements MigrationInterface {
|
||||
name = 'AddFlagRoleQueue1726041175749';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."users_role_enum" RENAME TO "users_role_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."users_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" TYPE "public"."users_role_enum" USING "role"::"text"::"public"."users_role_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'staff'`,
|
||||
);
|
||||
await queryRunner.query(`DROP TYPE "public"."users_role_enum_old"`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."users_role_enum_old" AS ENUM('superadmin', 'staff', 'tenant')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" DROP DEFAULT`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" TYPE "public"."users_role_enum_old" USING "role"::"text"::"public"."users_role_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users" ALTER COLUMN "role" SET DEFAULT 'staff'`,
|
||||
);
|
||||
await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."users_role_enum_old" RENAME TO "users_role_enum"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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,21 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTableUserLogin1726115025759 implements MigrationInterface {
|
||||
name = 'AddTableUserLogin1726115025759';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "login_date" bigint NOT NULL, "login_token" character varying, "user_id" uuid, CONSTRAINT "REL_2a80a213b51423ce5b8211f058" UNIQUE ("user_id"), CONSTRAINT "PK_e564194a9a22f8c623354284f75" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "users_login"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class UpdateTableUserLogin1726122619596 implements MigrationInterface {
|
||||
name = 'UpdateTableUserLogin1726122619596';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" DROP CONSTRAINT "FK_2a80a213b51423ce5b8211f0584"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" ADD CONSTRAINT "FK_2a80a213b51423ce5b8211f0584" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTableLogUserLogin1726123955427 implements MigrationInterface {
|
||||
name = 'AddTableLogUserLogin1726123955427';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."log_users_login_type_enum" AS ENUM('login', 'logout')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."log_users_login_role_enum" AS ENUM('superadmin', 'staff', 'tenant', 'queue_admin')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "log_users_login" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."log_users_login_type_enum", "role" "public"."log_users_login_role_enum", "user_id" uuid, "username" character varying, "created_at" bigint, CONSTRAINT "PK_75141588aa6ee560504f7d3adce" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "log_users_login"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."log_users_login_role_enum"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."log_users_login_type_enum"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddColumnItemId1726139426994 implements MigrationInterface {
|
||||
name = 'AddColumnItemId1726139426994';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "users_login" ADD "item_id" uuid`);
|
||||
await queryRunner.query(`ALTER TABLE "log_users_login" ADD "item_id" uuid`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "log_users_login" DROP COLUMN "item_id"`,
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE "users_login" DROP COLUMN "item_id"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddColumnItemName1726141393404 implements MigrationInterface {
|
||||
name = 'AddColumnItemName1726141393404';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" ADD "item_name" character varying`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "log_users_login" ADD "item_name" character varying`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "log_users_login" DROP COLUMN "item_name"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "users_login" DROP COLUMN "item_name"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class TransactionSettingModel1745991391299
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'TransactionSettingModel1745991391299';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "transaction_settings" ("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, "value" numeric NOT NULL DEFAULT '100', CONSTRAINT "PK_db7fb38a439358b499ebdee4761" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "transaction_settings"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class BookingAuthentication1748313715598 implements MigrationInterface {
|
||||
name = 'BookingAuthentication1748313715598';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "booking_verification" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "phone_number" character varying NOT NULL, "code" character varying, "tried" integer NOT NULL DEFAULT '0', "created_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, "updated_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, CONSTRAINT "PK_046e9288c7dd05c7259275d9fc0" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "booking_verification"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class CreateTimeGroupTable1748409891706 implements MigrationInterface {
|
||||
name = 'CreateTimeGroupTable1748409891706';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."time_groups_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'partial refund', 'pending', 'proses refund', 'refunded', 'rejected', 'settled', 'waiting')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "time_groups" ("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"."time_groups_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, "start_time" TIME NOT NULL, "end_time" TIME NOT NULL, "max_usage_time" TIME NOT NULL, CONSTRAINT "PK_083d02988db7bedfe3b7c869b50" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE "items" ADD "time_group_id" uuid`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD CONSTRAINT "FK_f44f222e1808448dca1b6cc4557" FOREIGN KEY ("time_group_id") REFERENCES "time_groups"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" DROP CONSTRAINT "FK_f44f222e1808448dca1b6cc4557"`,
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "time_group_id"`);
|
||||
await queryRunner.query(`DROP TABLE "time_groups"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."time_groups_status_enum"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddColumnOtpCode1748935417155 implements MigrationInterface {
|
||||
name = 'AddColumnOtpCode1748935417155';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "vip_codes" ADD "otp_code" character varying`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" ADD "otp_code" character varying`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" DROP COLUMN "otp_code"`,
|
||||
);
|
||||
await queryRunner.query(`ALTER TABLE "vip_codes" DROP COLUMN "otp_code"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class CreateTableOtpCerifications1749028279580
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'CreateTableOtpCerifications1749028279580';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_source_enum" AS ENUM('POS', 'WEB')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "otp_verifications" ("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, "otp_code" character varying NOT NULL, "action_type" "public"."otp_verifications_action_type_enum" NOT NULL, "target_id" character varying, "reference" character varying, "source" "public"."otp_verifications_source_enum" NOT NULL, "is_used" boolean NOT NULL DEFAULT false, "expired_at" bigint NOT NULL, "verified_at" bigint, CONSTRAINT "PK_91d17e75ac3182dba6701869b39" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "otp_verifications"`);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_source_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddColumnIsReplacedOtpVerification1749030419440
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddColumnIsReplacedOtpVerification1749030419440';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ADD "is_replaced" boolean NOT NULL DEFAULT false`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" DROP COLUMN "is_replaced"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTableOtpVerifier1749043616622 implements MigrationInterface {
|
||||
name = 'AddTableOtpVerifier1749043616622';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "otp_verifier" ("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, "name" character varying, "phone_number" character varying NOT NULL, CONSTRAINT "PK_884e2d0873fc589a1bdc477b2ea" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE "otp_verifier"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class UpdateEnumOtpActionType1749046285398
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'UpdateEnumOtpActionType1749046285398';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum" RENAME TO "otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum_old" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum_old" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum_old" RENAME TO "otp_verifications_action_type_enum"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class RescheduleOtp1749524993295 implements MigrationInterface {
|
||||
name = 'RescheduleOtp1749524993295';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE "reschedule_verification" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "phone_number" character varying NOT NULL, "booking_id" character varying NOT NULL, "reschedule_date" character varying NOT NULL, "code" integer NOT NULL, "tried" integer NOT NULL DEFAULT '0', "created_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, "updated_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, CONSTRAINT "PK_d4df453337ca12771eb223323d8" PRIMARY KEY ("id"))`,
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "booking_verification" ALTER COLUMN "created_at" SET DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "booking_verification" ALTER COLUMN "updated_at" SET DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "booking_verification" ALTER COLUMN "updated_at" SET DEFAULT (EXTRACT(epoch FROM now()) * (1000))`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "booking_verification" ALTER COLUMN "created_at" SET DEFAULT (EXTRACT(epoch FROM now()) * (1000))`,
|
||||
);
|
||||
await queryRunner.query(`DROP TABLE "reschedule_verification"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddBookingDescriptionToItem1749537252986
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddBookingDescriptionToItem1749537252986';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD "booking_description" text`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" DROP COLUMN "booking_description"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddBookingParentToTransaction1749604239749
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddBookingParentToTransaction1749604239749';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "transactions" ADD "parent_id" uuid`);
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" ADD CONSTRAINT "FK_413e95171729ba18cabce1c31e3" FOREIGN KEY ("parent_id") REFERENCES "transactions"("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_413e95171729ba18cabce1c31e3"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "transactions" DROP COLUMN "parent_id"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifier" ADD "is_all_action" boolean NOT NULL DEFAULT false`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifier_action_types_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifier" ADD "action_types" "public"."otp_verifier_action_types_enum" array`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum" RENAME TO "otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."otp_verifications_action_type_enum_old" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum_old" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum_old"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TYPE "public"."otp_verifications_action_type_enum_old" RENAME TO "otp_verifications_action_type_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifier" DROP COLUMN "action_types"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`DROP TYPE "public"."otp_verifier_action_types_enum"`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "otp_verifier" DROP COLUMN "is_all_action"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddUsageTypeToItem1750319148269 implements MigrationInterface {
|
||||
name = 'AddUsageTypeToItem1750319148269';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."item_queues_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_queues" ADD "usage_type" "public"."item_queues_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE TYPE "public"."items_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD "usage_type" "public"."items_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "usage_type"`);
|
||||
await queryRunner.query(`DROP TYPE "public"."items_usage_type_enum"`);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "item_queues" DROP COLUMN "usage_type"`,
|
||||
);
|
||||
await queryRunner.query(`DROP TYPE "public"."item_queues_usage_type_enum"`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class RemoveItemNameUnique1750834308368 implements MigrationInterface {
|
||||
name = 'RemoveItemNameUnique1750834308368';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" DROP CONSTRAINT "UQ_213736582899b3599acaade2cd1"`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "items" ADD CONSTRAINT "UQ_213736582899b3599acaade2cd1" UNIQUE ("name")`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { VerificationModel } from './data/models/verification.model';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { BookingAuthenticationController } from './infrastructure/controllers/booking-authentication.controller';
|
||||
import { VerificationService } from './data/services/verification.service';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||
import { JWT_SECRET } from 'src/core/sessions/constants';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([VerificationModel], CONNECTION_NAME.DEFAULT),
|
||||
|
||||
JwtModule.register({
|
||||
secret: JWT_SECRET,
|
||||
signOptions: { expiresIn: JWT_EXPIRED },
|
||||
}),
|
||||
],
|
||||
controllers: [BookingAuthenticationController],
|
||||
providers: [VerificationService],
|
||||
})
|
||||
export class BookingOnlineAuthModule {}
|
|
@ -0,0 +1,29 @@
|
|||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||
@Entity('booking_verification')
|
||||
export class VerificationModel implements BookingVerification {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
phone_number: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
code?: string;
|
||||
|
||||
@Column({ default: 0 })
|
||||
tried: number;
|
||||
|
||||
@Column({ type: 'bigint', default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000' })
|
||||
created_at: number;
|
||||
|
||||
@Column({
|
||||
type: 'bigint',
|
||||
default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||
onUpdate: 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||
})
|
||||
updated_at: number;
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { VerificationModel } from '../models/verification.model';
|
||||
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||
import { UnprocessableEntityException } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
export class VerificationService {
|
||||
constructor(
|
||||
@InjectRepository(VerificationModel)
|
||||
private readonly verificationRepository: Repository<VerificationModel>,
|
||||
private readonly jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
maxAttempts = 3;
|
||||
expiredTime = 5 * 60 * 1000;
|
||||
expiredTimeRegister = 1 * 60 * 1000;
|
||||
|
||||
async generateToken(payload: BookingVerification) {
|
||||
return this.jwtService.sign({
|
||||
phone_number: payload.phone_number,
|
||||
name: payload.name,
|
||||
created_at: payload.created_at,
|
||||
});
|
||||
}
|
||||
|
||||
async register(data: BookingVerification) {
|
||||
const isProduction = process.env.NODE_ENV === 'true';
|
||||
const currentTime = Math.floor(Date.now()); // current time in seconds
|
||||
|
||||
// Generate a 4 digit OTP code
|
||||
const otpCode = Math.floor(1000 + Math.random() * 9000).toString();
|
||||
|
||||
let verification = await this.verificationRepository.findOne({
|
||||
where: { phone_number: data.phone_number },
|
||||
});
|
||||
|
||||
if (
|
||||
isProduction &&
|
||||
verification.updated_at &&
|
||||
currentTime - verification.updated_at < this.expiredTimeRegister
|
||||
) {
|
||||
throw new UnprocessableEntityException('Please try again in 1 minute');
|
||||
}
|
||||
|
||||
data.code = otpCode;
|
||||
data.tried = 0;
|
||||
data.updated_at = currentTime;
|
||||
|
||||
if (verification) {
|
||||
// Update existing record
|
||||
verification = this.verificationRepository.merge(verification, data);
|
||||
} else {
|
||||
// Create new record
|
||||
verification = this.verificationRepository.create(data);
|
||||
}
|
||||
const payload = await this.verificationRepository.save(verification);
|
||||
|
||||
const notificationService = new WhatsappService();
|
||||
notificationService.sendOtpNotification({
|
||||
phone: data.phone_number,
|
||||
code: otpCode,
|
||||
});
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
async findByPhoneNumber(phoneNumber: string) {
|
||||
return this.verificationRepository.findOne({
|
||||
where: { phone_number: phoneNumber },
|
||||
});
|
||||
}
|
||||
|
||||
async verify(data: BookingVerification): Promise<BookingVerification> {
|
||||
const verification = await this.findByPhoneNumber(data.phone_number);
|
||||
if (!verification) {
|
||||
throw new UnprocessableEntityException('Phone number not found');
|
||||
}
|
||||
|
||||
if (verification.tried >= this.maxAttempts) {
|
||||
throw new UnprocessableEntityException(
|
||||
'Too many attempts, please resend OTP Code',
|
||||
);
|
||||
}
|
||||
|
||||
if (verification.code != data.code) {
|
||||
verification.tried++;
|
||||
await this.verificationRepository.save(verification);
|
||||
throw new UnprocessableEntityException('Invalid verification code');
|
||||
}
|
||||
|
||||
const currentTime = Math.floor(Date.now());
|
||||
if (
|
||||
verification.updated_at &&
|
||||
currentTime - verification.updated_at > this.expiredTime
|
||||
) {
|
||||
throw new UnprocessableEntityException('Verification code expired');
|
||||
}
|
||||
|
||||
return verification;
|
||||
}
|
||||
|
||||
async update(id: string, data: BookingVerification) {
|
||||
return this.verificationRepository.update(id, data);
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
return this.verificationRepository.delete(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export interface BookingVerification {
|
||||
id: string;
|
||||
name: string;
|
||||
phone_number: string;
|
||||
code?: string;
|
||||
tried?: number;
|
||||
created_at?: number;
|
||||
updated_at?: number;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import { Controller, Post, Body, Get, Param } from '@nestjs/common';
|
||||
|
||||
import {
|
||||
BookingVerificationDto,
|
||||
VerificationCodeDto,
|
||||
} from '../dto/booking-verification.dto';
|
||||
import { VerificationService } from '../../data/services/verification.service';
|
||||
import { Public } from 'src/core/guards/domain/decorators/unprotected.guard';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Booking Authentication')
|
||||
@Public()
|
||||
@Controller('v1/booking-authentication')
|
||||
export class BookingAuthenticationController {
|
||||
constructor(
|
||||
private readonly bookingAuthenticationService: VerificationService,
|
||||
) {}
|
||||
|
||||
@Post('verify')
|
||||
async verify(@Body() body: VerificationCodeDto) {
|
||||
const verification = await this.bookingAuthenticationService.verify(body);
|
||||
const token = await this.bookingAuthenticationService.generateToken(
|
||||
verification,
|
||||
);
|
||||
return {
|
||||
message: `Verification successful for ${verification.phone_number}`,
|
||||
token,
|
||||
};
|
||||
}
|
||||
|
||||
@Post('register')
|
||||
async register(@Body() body: BookingVerificationDto) {
|
||||
const verification = await this.bookingAuthenticationService.register(body);
|
||||
return {
|
||||
message: `Verification code sent to ${verification.phone_number}`,
|
||||
};
|
||||
}
|
||||
|
||||
@Get('get-by-phone/:phone_number')
|
||||
async getByPhoneNumber(@Param('phone_number') phone_number: string) {
|
||||
return this.bookingAuthenticationService.findByPhoneNumber(phone_number);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||
import { IsString, IsNotEmpty, Matches } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class BookingVerificationDto implements BookingVerification {
|
||||
id: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: 'John Doe',
|
||||
description: 'Name of the person booking',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '628123456789',
|
||||
description: 'Phone number containing only numeric characters',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^\d+$/, {
|
||||
message: 'phone_number must contain only numeric characters',
|
||||
})
|
||||
phone_number: string;
|
||||
}
|
||||
|
||||
export class VerificationCodeDto implements BookingVerification {
|
||||
id: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: 'John Doe',
|
||||
description: 'Name of the person booking',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '628123456789',
|
||||
description: 'Phone number containing only numeric characters',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^\d+$/, {
|
||||
message: 'phone_number must contain only numeric characters',
|
||||
})
|
||||
phone_number: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '1234',
|
||||
description: 'Verification code',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
code?: string;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export function generateOtp(digits = 4): number {
|
||||
if (digits < 1) {
|
||||
throw new Error('OTP digits must be at least 1');
|
||||
}
|
||||
const min = Math.pow(10, digits - 1);
|
||||
const max = Math.pow(10, digits) - 1;
|
||||
const otp = Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
return otp;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { RescheduleVerification } from '../../domain/entities/reschedule-verification.entity';
|
||||
|
||||
@Entity('reschedule_verification')
|
||||
export class RescheduleVerificationModel implements RescheduleVerification {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
phone_number: string;
|
||||
|
||||
@Column()
|
||||
booking_id: string;
|
||||
|
||||
@Column()
|
||||
reschedule_date: string;
|
||||
|
||||
@Column()
|
||||
code: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
tried: number;
|
||||
|
||||
@Column({ type: 'bigint', default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000' })
|
||||
created_at: number;
|
||||
|
||||
@Column({
|
||||
type: 'bigint',
|
||||
default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||
onUpdate: 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||
})
|
||||
updated_at: number;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
export interface RescheduleVerification {
|
||||
id: string;
|
||||
name: string;
|
||||
phone_number: string;
|
||||
booking_id: string;
|
||||
reschedule_date: string;
|
||||
code: number;
|
||||
tried?: number;
|
||||
created_at?: number;
|
||||
updated_at?: number;
|
||||
}
|
||||
|
||||
export interface RescheduleRequest {
|
||||
booking_id: string;
|
||||
reschedule_date: string;
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class BookingItemManager extends IndexItemManager {
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
// relation only join (for query purpose)
|
||||
joinRelations: [],
|
||||
|
||||
// relation join and select (relasi yang ingin ditampilkan),
|
||||
selectRelations: [
|
||||
'item_category',
|
||||
'bundling_items',
|
||||
'tenant',
|
||||
'time_group',
|
||||
'item_rates',
|
||||
],
|
||||
|
||||
// relation yang hanya ingin dihitung (akan return number)
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
const parent = super.selects;
|
||||
return [
|
||||
...parent,
|
||||
`${this.tableName}.image_url`,
|
||||
'item_rates.id',
|
||||
'item_rates.price',
|
||||
'item_rates.season_period_id',
|
||||
];
|
||||
}
|
||||
|
||||
getResult(): PaginationResponse<ItemEntity> {
|
||||
const result = super.getResult();
|
||||
const { data, total } = result;
|
||||
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
||||
const items = data.map((item) => {
|
||||
const currentRate = item.item_rates.find((rate) =>
|
||||
this.filterParam.season_period_ids?.includes(rate.season_period_id),
|
||||
);
|
||||
const { item_rates, ...rest } = item;
|
||||
const rate = currentRate?.['price'] ?? rest.base_price;
|
||||
return {
|
||||
...rest,
|
||||
base_price: hasRates ? rate : rest.base_price,
|
||||
};
|
||||
});
|
||||
return { total, data: items };
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
||||
): SelectQueryBuilder<ItemEntity> {
|
||||
const query = super.setQueryFilter(queryBuilder);
|
||||
|
||||
query.andWhere(`${this.tableName}.status = 'active'`);
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
import { HttpStatus } from '@nestjs/common';
|
||||
import { UnprocessableEntityException } from '@nestjs/common';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||
import { CreateTransactionManager } from 'src/modules/transaction/transaction/domain/usecases/managers/create-transaction.manager';
|
||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
||||
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export class CreateBookingManager extends CreateTransactionManager {
|
||||
async beforeProcess(): Promise<void> {
|
||||
mappingRevertTransaction(this.data, TransactionType.ONLINE);
|
||||
|
||||
const id = uuidv4();
|
||||
const invoiceCode = await generateInvoiceCodeHelper(
|
||||
this.dataService,
|
||||
'BOOK',
|
||||
);
|
||||
|
||||
try {
|
||||
const { token, redirect_url } = await this.dataServiceFirstOpt.create({
|
||||
...this.data,
|
||||
id,
|
||||
});
|
||||
Object.assign(this.data, {
|
||||
payment_midtrans_token: token,
|
||||
payment_midtrans_url: redirect_url,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log({ error });
|
||||
throw new UnprocessableEntityException({
|
||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
||||
message: `Gagal! transaksi telah terbuat, silahkan periksa email untuk melanjutkan pembayaran`,
|
||||
error: 'Unprocessable Entity',
|
||||
});
|
||||
}
|
||||
|
||||
Object.assign(this.data, {
|
||||
id,
|
||||
invoice_code: invoiceCode,
|
||||
status: STATUS.PENDING,
|
||||
invoice_date: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
const whatsapp = new WhatsappService();
|
||||
console.log(`/snap/v4/redirection/${this.data.payment_midtrans_token}`);
|
||||
console.log(this.data.payment_midtrans_url);
|
||||
await whatsapp.bookingRegister(
|
||||
{
|
||||
phone: this.data.customer_phone,
|
||||
code: this.data.invoice_code,
|
||||
name: this.data.customer_name,
|
||||
time: this.data.booking_date,
|
||||
id: this.data.id,
|
||||
},
|
||||
this.data.payment_total,
|
||||
`snap/v4/redirection/${this.data.payment_midtrans_token}`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { RescheduleVerificationModel } from '../../../data/models/reschedule-verification.model';
|
||||
import {
|
||||
RescheduleRequest,
|
||||
RescheduleVerification,
|
||||
} from '../../entities/reschedule-verification.entity';
|
||||
import { generateOtp } from 'src/modules/booking-online/helpers/generate-otp';
|
||||
import { TransactionReadService } from 'src/modules/transaction/transaction/data/services/transaction-read.service';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
|
||||
@Injectable()
|
||||
export class RescheduleVerificationManager {
|
||||
constructor(
|
||||
@InjectRepository(RescheduleVerificationModel)
|
||||
private readonly rescheduleVerificationRepository: Repository<RescheduleVerificationModel>,
|
||||
private readonly transactionService: TransactionReadService,
|
||||
) {}
|
||||
|
||||
async saveVerification(
|
||||
request: RescheduleRequest,
|
||||
): Promise<RescheduleVerificationModel> {
|
||||
try {
|
||||
const otp = generateOtp();
|
||||
const transaction = await this.findDetailByBookingId(request.booking_id);
|
||||
|
||||
if (!transaction) {
|
||||
throw new Error('Transaction not found for the provided booking id');
|
||||
}
|
||||
|
||||
const data: Partial<RescheduleVerification> = {
|
||||
code: otp,
|
||||
booking_id: transaction.id,
|
||||
name: transaction.customer_name,
|
||||
phone_number: transaction.customer_phone,
|
||||
reschedule_date: request.reschedule_date,
|
||||
};
|
||||
|
||||
const existTransaction =
|
||||
await this.rescheduleVerificationRepository.findOne({
|
||||
where: {
|
||||
booking_id: transaction.id,
|
||||
},
|
||||
});
|
||||
|
||||
const verification =
|
||||
existTransaction ?? this.rescheduleVerificationRepository.create(data);
|
||||
const result = await this.rescheduleVerificationRepository.save({
|
||||
...verification,
|
||||
code: otp,
|
||||
});
|
||||
|
||||
const whatsapp = new WhatsappService();
|
||||
whatsapp.sendOtpNotification({
|
||||
phone: transaction.customer_phone,
|
||||
code: otp.toString(),
|
||||
});
|
||||
// whatsapp.bookingRescheduleOTP({
|
||||
// phone: transaction.customer_phone,
|
||||
// code: otp.toString(),
|
||||
// name: transaction.customer_name,
|
||||
// time: new Date(request.reschedule_date).getTime(),
|
||||
// id: transaction.id,
|
||||
// });
|
||||
return result;
|
||||
} catch (error) {
|
||||
// You can customize the error handling as needed, e.g., throw HttpException for NestJS
|
||||
throw new UnprocessableEntityException(
|
||||
`Failed to save reschedule verification: ${error.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async verifyOtp(
|
||||
booking_id: string,
|
||||
code: number,
|
||||
): Promise<RescheduleVerificationModel> {
|
||||
const verification = await this.rescheduleVerificationRepository.findOne({
|
||||
where: { booking_id, code },
|
||||
order: { created_at: 'DESC' },
|
||||
});
|
||||
|
||||
if (!verification) {
|
||||
throw new UnprocessableEntityException({
|
||||
success: false,
|
||||
message: 'Verification code not match',
|
||||
});
|
||||
}
|
||||
|
||||
// Optionally, you can implement OTP expiration logic here
|
||||
|
||||
if (verification.code !== code) {
|
||||
// Increment tried count
|
||||
verification.tried = (verification.tried || 0) + 1;
|
||||
await this.rescheduleVerificationRepository.save(verification);
|
||||
throw new UnprocessableEntityException({
|
||||
success: false,
|
||||
message: 'Invalid verification code.',
|
||||
});
|
||||
}
|
||||
|
||||
// Optionally, you can mark the verification as used or verified here
|
||||
|
||||
return verification;
|
||||
}
|
||||
|
||||
async findDetailByBookingId(bookingId: string): Promise<TransactionEntity> {
|
||||
const transaction = await this.transactionService.getOneByOptions({
|
||||
where: { id: bookingId },
|
||||
});
|
||||
return transaction;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
||||
import * as moment from 'moment';
|
||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||
import { RescheduleVerificationModel } from '../../../data/models/reschedule-verification.model';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
|
||||
@Injectable()
|
||||
export class RescheduleManager {
|
||||
constructor(private serviceData: TransactionDataService) {}
|
||||
|
||||
async reschedule(data: RescheduleVerificationModel) {
|
||||
const transaction = await this.serviceData.getTransactionWithReschedule(
|
||||
data.booking_id,
|
||||
);
|
||||
|
||||
const rescheduleDate = moment(data.reschedule_date, 'DD-MM-YYYY');
|
||||
|
||||
const id = uuidv4();
|
||||
const invoiceCode = await generateInvoiceCodeHelper(
|
||||
this.serviceData,
|
||||
'BOOK',
|
||||
);
|
||||
|
||||
const items = this.makeItemZeroPrice(transaction.items);
|
||||
const transactionData = this.makeTransactionZeroPrice(transaction);
|
||||
|
||||
Object.assign(transactionData, {
|
||||
parent_id: transaction.id,
|
||||
id,
|
||||
invoice_code: invoiceCode,
|
||||
status: STATUS.SETTLED,
|
||||
invoice_date: rescheduleDate.format('YYYY-MM-DD'),
|
||||
booking_date: rescheduleDate.format('YYYY-MM-DD'),
|
||||
created_at: moment().unix() * 1000,
|
||||
updated_at: moment().unix() * 1000,
|
||||
items,
|
||||
});
|
||||
|
||||
await this.serviceData.getRepository().save(transactionData);
|
||||
|
||||
const whatsapp = new WhatsappService();
|
||||
whatsapp.rescheduleCreated({
|
||||
id: transactionData.id,
|
||||
name: transactionData.customer_name,
|
||||
phone: transactionData.customer_phone,
|
||||
time: moment(transactionData.invoice_date).unix() * 1000,
|
||||
code: transactionData.invoice_code,
|
||||
});
|
||||
|
||||
return transactionData;
|
||||
}
|
||||
|
||||
private makeItemZeroPrice(items: TransactionItemModel[]) {
|
||||
return items.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
id: uuidv4(),
|
||||
item_price: 0,
|
||||
total_price: 0,
|
||||
total_hpp: 0,
|
||||
total_profit: 0,
|
||||
total_profit_share: 0,
|
||||
payment_total_dpp: 0,
|
||||
payment_total_tax: 0,
|
||||
total_net_price: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private makeTransactionZeroPrice(transaction: TransactionModel) {
|
||||
return {
|
||||
...transaction,
|
||||
payment_sub_total: 0,
|
||||
payment_discount_total: 0,
|
||||
payment_total: 0,
|
||||
payment_total_pay: 0,
|
||||
payment_total_share: 0,
|
||||
payment_total_tax: 0,
|
||||
payment_total_profit: 0,
|
||||
payment_total_net_profit: 0,
|
||||
payment_total_dpp: 0,
|
||||
discount_percentage: 0,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
IsArray,
|
||||
IsNumber,
|
||||
IsObject,
|
||||
IsString,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { SeasonPeriodEntity } from 'src/modules/season-related/season-period/domain/entities/season-period.entity';
|
||||
import { TransactionItemEntity } from 'src/modules/transaction/transaction/domain/entities/transaction-item.entity';
|
||||
import {
|
||||
TransactionPaymentType,
|
||||
TransactionUserType,
|
||||
} from 'src/modules/transaction/transaction/constants';
|
||||
|
||||
export class TransactionDto extends BaseStatusDto {
|
||||
@ApiProperty({
|
||||
type: Object,
|
||||
required: false,
|
||||
example: {
|
||||
id: 'uuid',
|
||||
season_type: {
|
||||
id: 'uuid',
|
||||
name: 'high season',
|
||||
},
|
||||
},
|
||||
})
|
||||
@IsObject()
|
||||
@ValidateIf((body) => body.season_period)
|
||||
season_period: SeasonPeriodEntity;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: TransactionUserType.GROUP,
|
||||
})
|
||||
@IsString()
|
||||
customer_type: TransactionUserType;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: 'Andika',
|
||||
})
|
||||
@IsString()
|
||||
customer_name: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
example: '0823...',
|
||||
})
|
||||
@ValidateIf((body) => body.customer_phone)
|
||||
customer_phone: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: Date,
|
||||
required: true,
|
||||
example: '2024-01-01',
|
||||
})
|
||||
booking_date: Date;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
example: TransactionPaymentType.MIDTRANS,
|
||||
})
|
||||
payment_type: TransactionPaymentType;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
required: true,
|
||||
example: 7000000,
|
||||
})
|
||||
@IsNumber()
|
||||
payment_sub_total: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
required: true,
|
||||
example: 3500000,
|
||||
})
|
||||
@IsNumber()
|
||||
payment_total: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: [Object],
|
||||
required: true,
|
||||
example: [
|
||||
{
|
||||
item: {
|
||||
id: '68aa12f7-2cce-422b-9bae-185eb1343b94',
|
||||
created_at: '1718876384378',
|
||||
status: 'active',
|
||||
name: 'tes',
|
||||
item_type: 'bundling',
|
||||
hpp: '100000',
|
||||
base_price: '100000',
|
||||
limit_type: 'no limit',
|
||||
limit_value: 0,
|
||||
item_category: {
|
||||
id: 'ab15981a-a656-4efc-856c-b2abfbe30979',
|
||||
name: 'Kategori Bundling 2',
|
||||
},
|
||||
bundling_items: [
|
||||
{
|
||||
id: 'bd5a7a38-df25-4203-a1cd-bf94867946b2',
|
||||
name: 'Wahana 21 panjangggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg',
|
||||
},
|
||||
],
|
||||
tenant: null,
|
||||
},
|
||||
qty: 40,
|
||||
total_price: 4000000,
|
||||
},
|
||||
],
|
||||
})
|
||||
@IsArray()
|
||||
items: TransactionItemEntity[];
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
import { IsString, Matches } from 'class-validator';
|
||||
import { RescheduleRequest } from 'src/modules/booking-online/order/domain/entities/reschedule-verification.entity';
|
||||
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class RescheduleRequestDTO implements RescheduleRequest {
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '123e4567-e89b-12d3-a456-426614174000',
|
||||
description: 'The unique identifier of the booking',
|
||||
})
|
||||
@IsString()
|
||||
booking_id: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '25-12-2024',
|
||||
description: 'The new date for rescheduling in the format DD-MM-YYYY',
|
||||
})
|
||||
@IsString()
|
||||
@Matches(/^(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-\d{4}$/, {
|
||||
message: 'reschedule_date must be in the format DD-MM-YYYY',
|
||||
})
|
||||
reschedule_date: string;
|
||||
}
|
||||
|
||||
export class RescheduleVerificationOTP {
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '123e4567-e89b-12d3-a456-426614174000',
|
||||
description: 'The unique identifier of the booking',
|
||||
})
|
||||
@IsString()
|
||||
booking_id: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: true,
|
||||
example: '123456',
|
||||
description: 'The OTP code sent for verification',
|
||||
})
|
||||
@IsString()
|
||||
code: string;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
||||
import { BookingItemManager } from '../domain/usecases/managers/booking-item.manager';
|
||||
|
||||
@ApiTags('Booking Item')
|
||||
@Controller('v1/booking-item')
|
||||
@Public(true)
|
||||
export class ItemController {
|
||||
constructor(
|
||||
private indexManager: BookingItemManager,
|
||||
private serviceData: ItemReadService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
async index(
|
||||
@Query() params: FilterItemDto,
|
||||
): Promise<PaginationResponse<ItemEntity>> {
|
||||
params.limit = 1000;
|
||||
params.show_to_booking = true;
|
||||
params.all_item = true;
|
||||
this.indexManager.setFilterParam(params);
|
||||
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
||||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Res,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { TransactionDto } from './dto/booking-order.dto';
|
||||
import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity';
|
||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { MidtransService } from 'src/modules/configuration/midtrans/data/services/midtrans.service';
|
||||
import { CreateBookingManager } from '../domain/usecases/managers/create-booking.manager';
|
||||
import * as QRCode from 'qrcode';
|
||||
import { Gate } from 'src/core/response/domain/decorators/pagination.response';
|
||||
import { Response } from 'express';
|
||||
import {
|
||||
RescheduleRequestDTO,
|
||||
RescheduleVerificationOTP,
|
||||
} from './dto/reschedule.dto';
|
||||
import { RescheduleVerificationManager } from '../domain/usecases/managers/reschedule-verification.manager';
|
||||
import { RescheduleManager } from '../domain/usecases/managers/reschedule.manager';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import * as moment from 'moment';
|
||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||
|
||||
@ApiTags('Booking Order')
|
||||
@Controller('v1/booking')
|
||||
@Public(true)
|
||||
export class BookingOrderController {
|
||||
constructor(
|
||||
private createBooking: CreateBookingManager,
|
||||
private serviceData: TransactionDataService,
|
||||
private midtransService: MidtransService,
|
||||
private rescheduleVerification: RescheduleVerificationManager,
|
||||
private rescheduleManager: RescheduleManager,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
async create(@Body() data: TransactionDto) {
|
||||
const payload: Partial<TransactionEntity> = data;
|
||||
|
||||
this.createBooking.setData(payload as any);
|
||||
this.createBooking.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.TRANSACTION,
|
||||
this.midtransService,
|
||||
);
|
||||
await this.createBooking.execute();
|
||||
const result = await this.createBooking.getResult();
|
||||
const {
|
||||
invoice_code,
|
||||
status,
|
||||
payment_midtrans_token,
|
||||
payment_midtrans_url,
|
||||
id,
|
||||
} = result;
|
||||
|
||||
return {
|
||||
id,
|
||||
invoice_code,
|
||||
status,
|
||||
payment_midtrans_token,
|
||||
payment_midtrans_url,
|
||||
};
|
||||
}
|
||||
|
||||
@Post('reschedule')
|
||||
async reschedule(@Body() data: RescheduleRequestDTO) {
|
||||
const transaction = await this.serviceData.getTransactionWithReschedule(
|
||||
data.booking_id,
|
||||
);
|
||||
|
||||
const today = moment().startOf('day');
|
||||
const rescheduleDate = moment(data.reschedule_date, 'DD-MM-YYYY');
|
||||
const rescheduleDateStartOfDay = rescheduleDate.startOf('day');
|
||||
|
||||
//TODO: validate session period priority
|
||||
|
||||
if (rescheduleDateStartOfDay.isSameOrBefore(today)) {
|
||||
throw new UnprocessableEntityException(
|
||||
'Reschedule date must be in the future',
|
||||
);
|
||||
}
|
||||
|
||||
if (!transaction) {
|
||||
throw new UnprocessableEntityException('Transaction not found');
|
||||
}
|
||||
|
||||
if (transaction.status !== STATUS.SETTLED) {
|
||||
throw new UnprocessableEntityException('Transaction is not settled');
|
||||
}
|
||||
|
||||
if (transaction.children_transactions.length > 0) {
|
||||
throw new UnprocessableEntityException('Transaction already rescheduled');
|
||||
}
|
||||
|
||||
if (transaction.parent_id) {
|
||||
throw new UnprocessableEntityException('Transaction is a reschedule');
|
||||
}
|
||||
|
||||
const result = await this.rescheduleVerification.saveVerification(data);
|
||||
const maskedPhoneNumber = result.phone_number.replace(/.(?=.{4})/g, '*');
|
||||
result.phone_number = maskedPhoneNumber;
|
||||
|
||||
return `Verification code sent to ${maskedPhoneNumber}`;
|
||||
}
|
||||
|
||||
@Post('reschedule/verification')
|
||||
async verificationReschedule(@Body() data: RescheduleVerificationOTP) {
|
||||
const result = await this.rescheduleVerification.verifyOtp(
|
||||
data.booking_id,
|
||||
+data.code,
|
||||
);
|
||||
|
||||
const reschedule = await this.rescheduleManager.reschedule(result);
|
||||
const transaction = await this.get(reschedule.id);
|
||||
|
||||
return {
|
||||
id: reschedule.id,
|
||||
phone_number: result.phone_number,
|
||||
name: result.name,
|
||||
reschedule_date: result.reschedule_date,
|
||||
transaction,
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async get(@Param('id') transactionId: string) {
|
||||
const data = await this.serviceData.getOneByOptions({
|
||||
relations: [
|
||||
'items',
|
||||
'parent_transaction',
|
||||
'items.item',
|
||||
'items.item.time_group',
|
||||
],
|
||||
where: { id: transactionId },
|
||||
});
|
||||
|
||||
const {
|
||||
parent_id,
|
||||
customer_name,
|
||||
customer_phone,
|
||||
booking_date,
|
||||
invoice_code,
|
||||
status,
|
||||
id,
|
||||
items,
|
||||
parent_transaction,
|
||||
} = data;
|
||||
|
||||
let timeGroup = null;
|
||||
|
||||
const usageItems = items.map((item) => {
|
||||
const itemData = item.item;
|
||||
if (itemData.time_group) {
|
||||
const timeGroupData = itemData.time_group;
|
||||
const {
|
||||
id: groupId,
|
||||
name,
|
||||
start_time,
|
||||
end_time,
|
||||
max_usage_time,
|
||||
} = timeGroupData;
|
||||
timeGroup = {
|
||||
id: groupId,
|
||||
name,
|
||||
start_time,
|
||||
end_time,
|
||||
max_usage_time,
|
||||
};
|
||||
}
|
||||
const {
|
||||
id,
|
||||
item_id,
|
||||
item_name,
|
||||
item_price,
|
||||
item_category_name,
|
||||
total_price,
|
||||
total_net_price,
|
||||
qty,
|
||||
qty_remaining,
|
||||
} = item;
|
||||
return {
|
||||
id,
|
||||
item_id,
|
||||
item_name,
|
||||
item_price,
|
||||
item_category_name,
|
||||
total_price,
|
||||
total_net_price,
|
||||
qty,
|
||||
qty_remaining,
|
||||
};
|
||||
});
|
||||
|
||||
// Mask customer_phone with * and keep last 4 numbers
|
||||
let maskedCustomerPhone = customer_phone;
|
||||
if (typeof customer_phone === 'string' && customer_phone.length > 4) {
|
||||
const last4 = customer_phone.slice(-4);
|
||||
maskedCustomerPhone = '*'.repeat(customer_phone.length - 4) + last4;
|
||||
}
|
||||
|
||||
let parentTransaction = undefined;
|
||||
if (parent_transaction) {
|
||||
const {
|
||||
id: parentId,
|
||||
invoice_code: parentInvoiceCode,
|
||||
invoice_date: parentInvoiceDate,
|
||||
} = parent_transaction;
|
||||
parentTransaction = {
|
||||
id: parentId,
|
||||
invoice_code: parentInvoiceCode,
|
||||
invoice_date: parentInvoiceDate,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
customer_name,
|
||||
customer_phone: maskedCustomerPhone,
|
||||
booking_date,
|
||||
invoice_code,
|
||||
status,
|
||||
id,
|
||||
is_reschedule: !!parent_id,
|
||||
items: usageItems,
|
||||
time_group: timeGroup,
|
||||
parent: parentTransaction,
|
||||
};
|
||||
}
|
||||
|
||||
@Gate()
|
||||
@Get('qrcode/:id')
|
||||
async getQRcode(@Param('id') id: string, @Res() res: Response) {
|
||||
console.log(QRCode);
|
||||
const qrData = id;
|
||||
const data = await QRCode.toDataURL(qrData);
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
const base64Data = data.split(',')[1];
|
||||
const buffer = Buffer.from(base64Data, 'base64');
|
||||
res.send(buffer);
|
||||
}
|
||||
|
||||
@Post('resend-notification/:id')
|
||||
async resendNotification(@Param('id') id: string) {
|
||||
try {
|
||||
const transaction = await this.serviceData.getOneByOptions({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
const whatsappService = new WhatsappService();
|
||||
const formattedDate = moment(transaction.booking_date);
|
||||
const payload = {
|
||||
id: transaction.id,
|
||||
phone: transaction.customer_phone,
|
||||
code: transaction.invoice_code,
|
||||
name: transaction.customer_name,
|
||||
time: formattedDate.valueOf(),
|
||||
};
|
||||
await whatsappService.bookingCreated(payload);
|
||||
return {
|
||||
message: 'Notification sent successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new UnprocessableEntityException({
|
||||
message: 'Failed to send notification',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||
import { ItemModule } from 'src/modules/item-related/item/item.module';
|
||||
import { ItemController } from './infrastructure/item.controller';
|
||||
import { TransactionModule } from 'src/modules/transaction/transaction/transaction.module';
|
||||
import { BookingOrderController } from './infrastructure/order.controller';
|
||||
import { CreateBookingManager } from './domain/usecases/managers/create-booking.manager';
|
||||
import { MidtransModule } from 'src/modules/configuration/midtrans/midtrans.module';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { RescheduleVerificationModel } from './data/models/reschedule-verification.model';
|
||||
import { RescheduleVerificationManager } from './domain/usecases/managers/reschedule-verification.manager';
|
||||
import { RescheduleManager } from './domain/usecases/managers/reschedule.manager';
|
||||
import { BookingItemManager } from './domain/usecases/managers/booking-item.manager';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature(
|
||||
[ItemModel, RescheduleVerificationModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
ItemModule,
|
||||
TransactionModule,
|
||||
MidtransModule,
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [ItemController, BookingOrderController],
|
||||
providers: [
|
||||
CreateBookingManager,
|
||||
RescheduleVerificationManager,
|
||||
RescheduleManager,
|
||||
BookingItemManager,
|
||||
],
|
||||
})
|
||||
export class BookingOrderModule {}
|
|
@ -9,14 +9,32 @@ import { CqrsModule } from '@nestjs/cqrs';
|
|||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||
import { AuthAdminQueueController } from './infrastructure/auth-admin-queue.controller';
|
||||
import { AuthAdminQueueOrchestrator } from './domain/auth-admin-queue.orchestrator';
|
||||
import { LoginAdminQueueManager } from './domain/managers/admin-queue/login-admin-queue.manager';
|
||||
import { LogoutAdminQueueManager } from './domain/managers/admin-queue/logout-admin-queue.manager';
|
||||
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([UserModel], CONNECTION_NAME.DEFAULT),
|
||||
TypeOrmModule.forFeature(
|
||||
[UserModel, UserLoginModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [AuthController],
|
||||
providers: [LoginManager, LogoutManager, UserDataService, AuthOrchestrator],
|
||||
controllers: [AuthController, AuthAdminQueueController],
|
||||
providers: [
|
||||
LoginManager,
|
||||
LogoutManager,
|
||||
UserDataService,
|
||||
AuthOrchestrator,
|
||||
|
||||
// ADMIN QUEUE
|
||||
AuthAdminQueueOrchestrator,
|
||||
LoginAdminQueueManager,
|
||||
LogoutAdminQueueManager,
|
||||
],
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { LoginAdminQueueManager } from './managers/admin-queue/login-admin-queue.manager';
|
||||
import { LogoutAdminQueueManager } from './managers/admin-queue/logout-admin-queue.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthAdminQueueOrchestrator {
|
||||
constructor(
|
||||
private loginManager: LoginAdminQueueManager,
|
||||
private logoutManager: LogoutAdminQueueManager,
|
||||
private serviceData: UserDataService,
|
||||
) {}
|
||||
|
||||
async login(data): Promise<any> {
|
||||
this.loginManager.setData(data);
|
||||
this.loginManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.loginManager.execute();
|
||||
return this.loginManager.getResult();
|
||||
}
|
||||
|
||||
async logout(userId?: string): Promise<any> {
|
||||
if (userId) this.logoutManager.setData({ user_id: userId });
|
||||
this.logoutManager.setService(this.serviceData, TABLE_NAME.USER);
|
||||
await this.logoutManager.execute();
|
||||
return this.logoutManager.getResult();
|
||||
}
|
||||
|
||||
async forceLogout(token): Promise<any> {
|
||||
return this.serviceData.forceLogout(token);
|
||||
}
|
||||
}
|
|
@ -24,4 +24,8 @@ export class AuthOrchestrator {
|
|||
await this.logoutManager.execute();
|
||||
return this.logoutManager.getResult();
|
||||
}
|
||||
|
||||
async forceLogout(token): Promise<any> {
|
||||
return this.serviceData.forceLogout(token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,168 @@
|
|||
import {
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { validatePassword } from 'src/core/helpers/password/bcrypt.helpers';
|
||||
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
|
||||
import { SessionService } from 'src/core/sessions';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
import { In } from 'typeorm';
|
||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
||||
import { UserLoginEntity } from 'src/modules/user-related/user/domain/entities/user-login.entity';
|
||||
|
||||
@Injectable()
|
||||
export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||
@Inject()
|
||||
protected session: SessionService;
|
||||
protected token;
|
||||
protected userLogin;
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async process(): Promise<void> {
|
||||
const itemLogin = await this.dataService.getLoginUserByItem(
|
||||
this.data.item_id,
|
||||
);
|
||||
|
||||
// get user active by username
|
||||
this.userLogin = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
username: this.data.username,
|
||||
status: STATUS.ACTIVE,
|
||||
role: In([UserRole.QUEUE_ADMIN, UserRole.SUPERADMIN]),
|
||||
},
|
||||
relations: ['user_login'],
|
||||
});
|
||||
|
||||
if (!this.userLogin) this.throwError();
|
||||
|
||||
// validasi password
|
||||
const valid = await validatePassword(
|
||||
this.data.password,
|
||||
this.userLogin?.password,
|
||||
);
|
||||
if (!valid) this.throwError();
|
||||
|
||||
const userLoginItem = await this.dataService.getOneByOptions({
|
||||
where: {
|
||||
id: itemLogin?.user_id,
|
||||
},
|
||||
});
|
||||
|
||||
const hasLoginAsQueue = this.userLogin?.user_login?.find(
|
||||
(item) => item.source === AppSource.QUEUE_ADMIN,
|
||||
);
|
||||
|
||||
if (hasLoginAsQueue && hasLoginAsQueue?.item_id !== this.data.item_id) {
|
||||
throw new UnauthorizedException({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||
error: 'Unauthorized',
|
||||
});
|
||||
}
|
||||
// else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
||||
// throw new UnauthorizedException({
|
||||
// statusCode: HttpStatus.UNAUTHORIZED,
|
||||
// message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
||||
// error: 'Unauthorized',
|
||||
// });
|
||||
// }
|
||||
|
||||
// * Disini untuk isi token
|
||||
const tokenData = {
|
||||
id: this.userLogin.id,
|
||||
name: this.userLogin.name,
|
||||
username: this.userLogin.username,
|
||||
role: this.userLogin.role,
|
||||
user_privilege_id: this.userLogin.user_privilege_id,
|
||||
item_id: this.data.item_id,
|
||||
item_name: this.data.item_name,
|
||||
source: AppSource.QUEUE_ADMIN,
|
||||
};
|
||||
|
||||
Logger.debug('Sign Token Admin Queue', 'LoginAdminQueueManager');
|
||||
this.token = this.session.createAccessToken(tokenData);
|
||||
|
||||
Logger.debug('Save Login Token', 'LoginManager');
|
||||
const userLoginData: UserLoginEntity = {
|
||||
user_id: this.userLogin.id,
|
||||
login_token: this.token,
|
||||
login_date: new Date().getTime(),
|
||||
source: AppSource.QUEUE_ADMIN,
|
||||
role: this.userLogin.role,
|
||||
item_id: this.data.item_id,
|
||||
item_name: this.data.item_name,
|
||||
};
|
||||
if (hasLoginAsQueue?.item_id === this.data.item_id) {
|
||||
Object.assign(userLoginData, { id: hasLoginAsQueue.id });
|
||||
}
|
||||
// Update refresh token
|
||||
await this.dataService.saveUserLogin(userLoginData);
|
||||
|
||||
await this.publishEvents();
|
||||
|
||||
Logger.debug('Process Login Admin Queue Done', 'LoginAdminQueueManager');
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return {
|
||||
id: this.userLogin.id,
|
||||
name: this.userLogin.name,
|
||||
username: this.userLogin.username,
|
||||
role: this.userLogin.role,
|
||||
token: this.token,
|
||||
item_id: this.data.item_id,
|
||||
item_name: this.data.item_name,
|
||||
};
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: LogUserLoginEvent,
|
||||
data: {
|
||||
type: LogUserType.login,
|
||||
role: this.userLogin.role,
|
||||
user_id: this.userLogin.id,
|
||||
username: this.userLogin.username,
|
||||
created_at: new Date().getTime(),
|
||||
item_id: this.data.item_id,
|
||||
item_name: this.data.item_name,
|
||||
source: AppSource.QUEUE_ADMIN,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// !throw errornya akan sama, untuk security
|
||||
throwError() {
|
||||
throw new UnauthorizedException({
|
||||
statusCode: HttpStatus.UNAUTHORIZED,
|
||||
message: `Gagal! username atau password tidak sesuai`,
|
||||
error: 'Unauthorized',
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||
import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base-custom.manager';
|
||||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
|
||||
export class LogoutAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||
protected userLogin;
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async process(): Promise<void> {
|
||||
const id = this.data?.user_id ?? this.user.id;
|
||||
|
||||
this.userLogin = await this.dataService.getOneByOptions({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
await this.dataService.removeUserLogin({
|
||||
user_id: id,
|
||||
source: AppSource.QUEUE_ADMIN,
|
||||
});
|
||||
|
||||
await this.publishEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return `Success Logout User`;
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: LogUserLoginEvent,
|
||||
data: {
|
||||
type: LogUserType.logout,
|
||||
role: this.userLogin.role,
|
||||
user_id: this.userLogin.id,
|
||||
username: this.userLogin.name,
|
||||
created_at: new Date().getTime(),
|
||||
source: AppSource.QUEUE_ADMIN,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
|
@ -12,7 +12,11 @@ import { STATUS } from 'src/core/strings/constants/base.constants';
|
|||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
import { UserLoginEvent } from '../entities/login.event';
|
||||
import { Not } from 'typeorm';
|
||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
||||
import { UserLoginEntity } from 'src/modules/user-related/user/domain/entities/user-login.entity';
|
||||
|
||||
@Injectable()
|
||||
export class LoginManager extends BaseCustomManager<UserEntity> {
|
||||
|
@ -36,6 +40,7 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
|
|||
where: {
|
||||
username: this.data.username,
|
||||
status: STATUS.ACTIVE,
|
||||
role: Not(UserRole.QUEUE_ADMIN),
|
||||
},
|
||||
relations: [
|
||||
'user_privilege',
|
||||
|
@ -58,25 +63,27 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
|
|||
username: this.userLogin.username,
|
||||
role: this.userLogin.role,
|
||||
user_privilege_id: this.userLogin.user_privilege_id,
|
||||
source: AppSource.POS_ADMIN,
|
||||
};
|
||||
|
||||
Logger.debug('Sign Token', 'LoginManager');
|
||||
this.token = this.session.createAccessToken(tokenData);
|
||||
|
||||
Logger.debug('refreshToken', 'LoginManager');
|
||||
const refreshToken = this.session.createAccessToken(tokenData);
|
||||
Logger.debug('Save Login Token', 'LoginManager');
|
||||
const userLoginData: UserLoginEntity = {
|
||||
user_id: this.userLogin.id,
|
||||
login_token: this.token,
|
||||
login_date: new Date().getTime(),
|
||||
source: AppSource.POS_ADMIN,
|
||||
role: this.userLogin.role,
|
||||
item_id: null,
|
||||
item_name: null,
|
||||
};
|
||||
|
||||
Logger.debug('Update Refresh Token', 'LoginManager');
|
||||
// Update refresh token
|
||||
await this.dataService.update(
|
||||
this.queryRunner,
|
||||
this.entityTarget,
|
||||
{ id: this.userLogin.id },
|
||||
{
|
||||
refresh_token: refreshToken,
|
||||
},
|
||||
);
|
||||
await this.dataService.saveUserLogin(userLoginData);
|
||||
|
||||
await this.publishEvents();
|
||||
Logger.debug('Process Login Done', 'LoginManager');
|
||||
return;
|
||||
}
|
||||
|
@ -119,11 +126,14 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
|
|||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserLoginEvent,
|
||||
topic: LogUserLoginEvent,
|
||||
data: {
|
||||
id: this.userLogin.id,
|
||||
type: 'login',
|
||||
timestamp: new Date().getTime(),
|
||||
type: LogUserType.login,
|
||||
role: this.userLogin.role,
|
||||
user_id: this.userLogin.id,
|
||||
username: this.userLogin.username,
|
||||
created_at: new Date().getTime(),
|
||||
source: AppSource.POS_ADMIN,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -2,7 +2,8 @@ import { BaseCustomManager } from 'src/core/modules/domain/usecase/managers/base
|
|||
import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||
import { UserLogoutEvent } from '../entities/logout.event';
|
||||
import { AppSource, LogUserType } from 'src/core/helpers/constant';
|
||||
import { LogUserLoginEvent } from 'src/modules/configuration/log/domain/entities/log-user-login.event';
|
||||
|
||||
export class LogoutManager extends BaseCustomManager<UserEntity> {
|
||||
async validateProcess(): Promise<void> {
|
||||
|
@ -14,15 +15,12 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
|
|||
}
|
||||
|
||||
async process(): Promise<void> {
|
||||
await this.dataService.update(
|
||||
this.queryRunner,
|
||||
this.entityTarget,
|
||||
{ id: this.user.id },
|
||||
{
|
||||
refresh_token: null,
|
||||
},
|
||||
);
|
||||
|
||||
await this.dataService.removeUserLogin({
|
||||
user_id: this.user.id,
|
||||
login_token: this.userProvider.token,
|
||||
source: AppSource.POS_ADMIN,
|
||||
});
|
||||
await this.publishEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -41,11 +39,14 @@ export class LogoutManager extends BaseCustomManager<UserEntity> {
|
|||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserLogoutEvent,
|
||||
topic: LogUserLoginEvent,
|
||||
data: {
|
||||
id: this.user.id,
|
||||
type: 'logout',
|
||||
timestamp: new Date().getTime(),
|
||||
type: LogUserType.logout,
|
||||
role: this.user.role,
|
||||
user_id: this.user.id,
|
||||
username: this.user.name,
|
||||
created_at: new Date().getTime(),
|
||||
source: AppSource.POS_ADMIN,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { ForceLogoutDto, LoginQueueDto } from './dto/login.dto';
|
||||
import { AuthAdminQueueOrchestrator } from '../domain/auth-admin-queue.orchestrator';
|
||||
|
||||
@Controller('v1/auth/queue')
|
||||
export class AuthAdminQueueController {
|
||||
constructor(private orchestrator: AuthAdminQueueOrchestrator) {}
|
||||
|
||||
@Post()
|
||||
@Public(true)
|
||||
async login(@Body() body: LoginQueueDto) {
|
||||
return await this.orchestrator.login(body);
|
||||
}
|
||||
|
||||
@ApiBearerAuth('JWT')
|
||||
@Public(false)
|
||||
@ExcludePrivilege()
|
||||
@Delete('logout')
|
||||
async logout() {
|
||||
return await this.orchestrator.logout();
|
||||
}
|
||||
|
||||
@Put(':user_id/logout')
|
||||
async logoutQueueAdmin(@Param('user_id') userId: string) {
|
||||
return await this.orchestrator.logout(userId);
|
||||
}
|
||||
|
||||
@Post('force-logout')
|
||||
@Public(true)
|
||||
async forceLogout(@Body() body: ForceLogoutDto) {
|
||||
return await this.orchestrator.forceLogout(body.token);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import { Body, Controller, Delete, Post } from '@nestjs/common';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { AuthOrchestrator } from '../domain/auth.orchestrator';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { ForceLogoutDto, LoginDto } from './dto/login.dto';
|
||||
|
||||
@Controller('v1/auth')
|
||||
export class AuthController {
|
||||
|
@ -16,8 +16,15 @@ export class AuthController {
|
|||
|
||||
@ApiBearerAuth('JWT')
|
||||
@Public(false)
|
||||
@ExcludePrivilege()
|
||||
@Delete('logout')
|
||||
async logoout() {
|
||||
async logout() {
|
||||
return await this.orchestrator.logout();
|
||||
}
|
||||
|
||||
@Post('force-logout')
|
||||
@Public(true)
|
||||
async forceLogout(@Body() body: ForceLogoutDto) {
|
||||
return await this.orchestrator.forceLogout(body.token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,3 +11,27 @@ export class LoginDto implements LoginRequest {
|
|||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class LoginQueueDto implements LoginRequest {
|
||||
@ApiProperty({ name: 'username', required: true, default: 'superadmin' })
|
||||
@IsString()
|
||||
username: string;
|
||||
|
||||
@ApiProperty({ name: 'password', required: true, default: 'Eigen123!' })
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@ApiProperty({ name: 'item_id', required: true, default: 'string' })
|
||||
@IsString()
|
||||
item_id: string;
|
||||
|
||||
@ApiProperty({ name: 'item_name', required: true, default: 'string' })
|
||||
@IsString()
|
||||
item_name: string;
|
||||
}
|
||||
|
||||
export class ForceLogoutDto {
|
||||
@ApiProperty({ required: true })
|
||||
@IsString()
|
||||
token: string;
|
||||
}
|
||||
|
|
|
@ -3,4 +3,5 @@ export const DatabaseListen = [
|
|||
'vip_code',
|
||||
'pos_activity',
|
||||
'pos_cash_activity',
|
||||
'time_groups',
|
||||
];
|
||||
|
|
|
@ -51,6 +51,11 @@ import {
|
|||
import { SeasonPeriodDataService } from 'src/modules/season-related/season-period/data/services/season-period-data.service';
|
||||
import { SeasonPeriodModel } from 'src/modules/season-related/season-period/data/models/season-period.model';
|
||||
import { TransactionDemographyModel } from 'src/modules/transaction/transaction/data/models/transaction-demography.model';
|
||||
import { UserLoginModel } from 'src/modules/user-related/user/data/models/user-login.model';
|
||||
import {
|
||||
TimeGroupDeletedHandler,
|
||||
TimeGroupUpdatedHandler,
|
||||
} from './domain/managers/time-group.handle';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -61,6 +66,7 @@ import { TransactionDemographyModel } from 'src/modules/transaction/transaction/
|
|||
ItemRateModel,
|
||||
SeasonPeriodModel,
|
||||
UserModel,
|
||||
UserLoginModel,
|
||||
TransactionModel,
|
||||
TransactionTaxModel,
|
||||
TransactionItemModel,
|
||||
|
@ -81,6 +87,10 @@ import { TransactionDemographyModel } from 'src/modules/transaction/transaction/
|
|||
VipCodeCreatedHandler,
|
||||
VipCategoryDeletedHandler,
|
||||
VipCategoryUpdatedHandler,
|
||||
|
||||
TimeGroupDeletedHandler,
|
||||
TimeGroupUpdatedHandler,
|
||||
|
||||
SeasonPeriodDeletedHandler,
|
||||
SeasonPeriodUpdatedHandler,
|
||||
ItemUpdatedHandler,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue