feat: update quotation status on expired
This commit is contained in:
parent
4d2dadbc05
commit
18fb64b9cc
5 changed files with 52 additions and 0 deletions
|
|
@ -37,6 +37,7 @@
|
||||||
"@tsoa/runtime": "^6.5.1",
|
"@tsoa/runtime": "^6.5.1",
|
||||||
"@types/morgan": "^1.9.9",
|
"@types/morgan": "^1.9.9",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
"cron": "^3.1.9",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"fast-jwt": "^4.0.5",
|
"fast-jwt": "^4.0.5",
|
||||||
|
|
|
||||||
22
pnpm-lock.yaml
generated
22
pnpm-lock.yaml
generated
|
|
@ -29,6 +29,9 @@ importers:
|
||||||
cors:
|
cors:
|
||||||
specifier: ^2.8.5
|
specifier: ^2.8.5
|
||||||
version: 2.8.5
|
version: 2.8.5
|
||||||
|
cron:
|
||||||
|
specifier: ^3.1.9
|
||||||
|
version: 3.1.9
|
||||||
dotenv:
|
dotenv:
|
||||||
specifier: ^16.4.5
|
specifier: ^16.4.5
|
||||||
version: 16.4.5
|
version: 16.4.5
|
||||||
|
|
@ -429,6 +432,9 @@ packages:
|
||||||
'@types/koa@2.15.0':
|
'@types/koa@2.15.0':
|
||||||
resolution: {integrity: sha512-7QFsywoE5URbuVnG3loe03QXuGajrnotr3gQkXcEBShORai23MePfFYdhz90FEtBBpkyIYQbVD+evKtloCgX3g==}
|
resolution: {integrity: sha512-7QFsywoE5URbuVnG3loe03QXuGajrnotr3gQkXcEBShORai23MePfFYdhz90FEtBBpkyIYQbVD+evKtloCgX3g==}
|
||||||
|
|
||||||
|
'@types/luxon@3.4.2':
|
||||||
|
resolution: {integrity: sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==}
|
||||||
|
|
||||||
'@types/mime@1.3.5':
|
'@types/mime@1.3.5':
|
||||||
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
|
resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
|
||||||
|
|
||||||
|
|
@ -777,6 +783,9 @@ packages:
|
||||||
create-require@1.1.1:
|
create-require@1.1.1:
|
||||||
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
|
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
|
||||||
|
|
||||||
|
cron@3.1.9:
|
||||||
|
resolution: {integrity: sha512-eNZu+YhLRHLxNJNqZgYuy8mXhzMV0XXmOSh+Ls2j1yTeQLCQ04ya7oNpujxwl4lEyck1fcVa1aRVZ+T4tAC7SA==}
|
||||||
|
|
||||||
cross-spawn@7.0.3:
|
cross-spawn@7.0.3:
|
||||||
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
|
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
|
|
@ -1523,6 +1532,10 @@ packages:
|
||||||
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
|
luxon@3.5.0:
|
||||||
|
resolution: {integrity: sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
make-dir@3.1.0:
|
make-dir@3.1.0:
|
||||||
resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}
|
resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
@ -3070,6 +3083,8 @@ snapshots:
|
||||||
'@types/koa-compose': 3.2.8
|
'@types/koa-compose': 3.2.8
|
||||||
'@types/node': 20.17.6
|
'@types/node': 20.17.6
|
||||||
|
|
||||||
|
'@types/luxon@3.4.2': {}
|
||||||
|
|
||||||
'@types/mime@1.3.5': {}
|
'@types/mime@1.3.5': {}
|
||||||
|
|
||||||
'@types/mime@4.0.0':
|
'@types/mime@4.0.0':
|
||||||
|
|
@ -3486,6 +3501,11 @@ snapshots:
|
||||||
|
|
||||||
create-require@1.1.1: {}
|
create-require@1.1.1: {}
|
||||||
|
|
||||||
|
cron@3.1.9:
|
||||||
|
dependencies:
|
||||||
|
'@types/luxon': 3.4.2
|
||||||
|
luxon: 3.5.0
|
||||||
|
|
||||||
cross-spawn@7.0.3:
|
cross-spawn@7.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
path-key: 3.1.1
|
path-key: 3.1.1
|
||||||
|
|
@ -4348,6 +4368,8 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
yallist: 4.0.0
|
yallist: 4.0.0
|
||||||
|
|
||||||
|
luxon@3.5.0: {}
|
||||||
|
|
||||||
make-dir@3.1.0:
|
make-dir@3.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
semver: 6.3.1
|
semver: 6.3.1
|
||||||
|
|
|
||||||
|
|
@ -1166,6 +1166,7 @@ enum QuotationStatus {
|
||||||
PaymentSuccess
|
PaymentSuccess
|
||||||
ProcessComplete
|
ProcessComplete
|
||||||
Canceled
|
Canceled
|
||||||
|
Expired
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PayCondition {
|
enum PayCondition {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { RegisterRoutes } from "./routes";
|
||||||
import { initThailandAreaDatabase } from "./utils/thailand-area";
|
import { initThailandAreaDatabase } from "./utils/thailand-area";
|
||||||
import { initFirstAdmin } from "./utils/database";
|
import { initFirstAdmin } from "./utils/database";
|
||||||
import { apiReference } from "@scalar/express-api-reference";
|
import { apiReference } from "@scalar/express-api-reference";
|
||||||
|
import { initSchedule } from "./services/schedule";
|
||||||
|
|
||||||
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
|
||||||
const APP_PORT = +(process.env.APP_PORT || 3000);
|
const APP_PORT = +(process.env.APP_PORT || 3000);
|
||||||
|
|
@ -17,6 +18,8 @@ const APP_PORT = +(process.env.APP_PORT || 3000);
|
||||||
await initThailandAreaDatabase();
|
await initThailandAreaDatabase();
|
||||||
await initFirstAdmin();
|
await initFirstAdmin();
|
||||||
|
|
||||||
|
initSchedule();
|
||||||
|
|
||||||
const originalSend = app.response.json;
|
const originalSend = app.response.json;
|
||||||
|
|
||||||
app.response.json = function (body: unknown) {
|
app.response.json = function (body: unknown) {
|
||||||
|
|
|
||||||
25
src/services/schedule.ts
Normal file
25
src/services/schedule.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { CronJob } from "cron";
|
||||||
|
|
||||||
|
import prisma from "../db";
|
||||||
|
|
||||||
|
const jobs = [
|
||||||
|
CronJob.from({
|
||||||
|
cronTime: "0 0 0 * * *",
|
||||||
|
runOnInit: true,
|
||||||
|
onTick: async () => {
|
||||||
|
await prisma.quotation
|
||||||
|
.updateMany({
|
||||||
|
where: {
|
||||||
|
dueDate: { lte: new Date() },
|
||||||
|
},
|
||||||
|
data: { quotationStatus: "Expired" },
|
||||||
|
})
|
||||||
|
.then(() => console.log("[INFO]: Update expired quotation status, OK."))
|
||||||
|
.catch((e) => console.error(e));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
export function initSchedule() {
|
||||||
|
for (const job of jobs) job.start();
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue