This commit is contained in:
2024-03-29 14:32:56 +07:00
commit acc048af5b
14 changed files with 2669 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules
/certs

12
README.md Normal file
View File

@ -0,0 +1,12 @@
# Install Certificate
## Windows
## MacOS
```brew install mkcert
mkcert -install
mkcert localhost
mkdir certs
mv localhost.pem localhost-key.pem certs/
```

0
db.json Normal file
View File

50
db/audit-log.js Normal file
View File

@ -0,0 +1,50 @@
import { faker } from "@faker-js/faker";
const MAX = 10;
function createAuditLog() {
return {
guid: faker.string.uuid(),
dateOfAction: faker.date.anytime(),
actionBy: faker.internet.displayName(),
mainModule: faker.helpers.arrayElement([
"Customer Accounts",
"Reports",
"Settings",
"Notification Management",
"Announcement Management",
"Cron Job Management",
"Audit Log",
]),
subModule: faker.helpers.arrayElement(["Role", "Account", "Detail"]),
action: faker.helpers.arrayElement([
"Edit Role",
"edit User",
"edit Account",
"create Announcement",
"Filter Log",
]),
oldValue: faker.helpers.arrayElement([
null,
faker.animal.cat(),
faker.location.country(),
]),
newValue: faker.helpers.arrayElement([
null,
faker.animal.cat(),
faker.location.country(),
]),
};
}
export default () => {
const data = {
status: 200,
data: {
totalRecords: MAX,
auditLogList: faker.helpers.multiple(createAuditLog, { count: MAX }),
},
};
return data;
};

65
db/cron-job.js Normal file
View File

@ -0,0 +1,65 @@
import { faker } from "@faker-js/faker";
const MAX = 10;
function createCronJob() {
return {
guid: faker.string.uuid(),
cronjobName: faker.helpers.arrayElement([
"cronjob-mdms-pull-meter-alert",
"DAP PERCENTILE DATA",
"DAP WEIS DATA",
]),
fileName: `DAP_WEIS_${faker.date.anytime().toTimeString()}.txt`,
scheduleDateTime: faker.date.anytime(),
fileReceivedTime: faker.date.anytime(),
fileIngestionTime: faker.date.anytime(),
totalRecords: faker.number.int({ min: 0, max: 40 }),
totalFailedRecords: faker.number.int({ min: 0, max: 40 }),
errorDetail: faker.helpers.arrayElement([
null,
"Header invalid",
"Connect sftp failed…",
"File incomplete ingestion",
]),
jobFiles: faker.helpers.multiple(
() => ({
guid: faker.string.uuid(),
fileName: `FILE NAME ${faker.number.int()}.txt`,
processTime: Math.floor(faker.date.anytime().getTime() / 1000),
noOfRecordsSuccess: faker.number.int({ min: 2, max: 500 }),
noOfRecordsInvalid: faker.number.int({ min: 1, max: 50 }),
fileStatus: faker.helpers.arrayElement([
"SUCCESS",
"FAILED (STAGING)",
"CANCEL",
]),
errorDetail: {
message: faker.helpers.arrayElement([
"Header invalid",
null,
"File incomplete ingestion",
]),
rejectedRecordsFile: `DAP_WEIS_${faker.date
.anytime()
.toTimeString()}_${faker.string.uuid()}.txt`,
},
}),
{
count: faker.number.int({ min: 1, max: 5 }),
}
),
};
}
export default () => {
const data = {
status: 200,
data: {
totalCronjobRecords: MAX,
cronjobLogList: faker.helpers.multiple(createCronJob, { count: MAX }),
},
};
return data;
};

59
db/get-cron-job-list.js Normal file
View File

@ -0,0 +1,59 @@
export default {
status: 200,
data: [
{
cronjobName: "cronjob-ebs-import-water-account",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4775944+00:00",
},
{
cronjobName: "cronjob-dap-import-dap-data",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4776397+00:00",
},
{
cronjobName: "cronjob-mdms-import-meter-alert",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.47764+00:00",
},
{
cronjobName: "cronjob-mdms-pull-meter-alert",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4776402+00:00",
},
{
cronjobName: "cronjob-mdms-export-enrolment-status",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4776403+00:00",
},
{
cronjobName: "cronjob-ebs-import-avg",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4776415+00:00",
},
{
cronjobName: "cronjob-water-account-user-goal-notification",
noOfFailedRecordsThreshold: 10,
fileIngestionTimeThreshold: 60,
dateOfLastUpdated: "2023-08-16T09:35:44.4776416+00:00",
},
{
cronjobName: "cronjob-water-account-whitelist-sp-accounts",
noOfFailedRecordsThreshold: 44,
fileIngestionTimeThreshold: 44,
dateOfLastUpdated: "2023-08-28T15:20:56.4036081Z",
},
{
cronjobName: "cronjob-mdms-import-meter-data",
noOfFailedRecordsThreshold: 4,
fileIngestionTimeThreshold: 4,
dateOfLastUpdated: "2023-08-28T15:19:44.4816081Z",
},
],
};

6
db/image.js Normal file
View File

@ -0,0 +1,6 @@
import { faker } from "@faker-js/faker";
export default {
status: 200,
data: faker.image.urlPicsumPhotos(),
};

16
db/index.js Normal file
View File

@ -0,0 +1,16 @@
import cronJob from "./cron-job.js";
import nameCronjobs from "./name-cronjobs.js";
import messageTemplate from "./message-template.js";
import auditLog from "./audit-log.js";
import imageURL from "./image.js";
import cronJobList from "./get-cron-job-list.js";
export default {
cronjob: { ...cronJob() },
"audit-log": { ...auditLog() },
"name-cronjobs": nameCronjobs,
"message-template": messageTemplate,
"get-image": imageURL,
"get-cronjob-list": cronJobList,
"update-cronjob": {},
};

26
db/message-template.js Normal file
View File

@ -0,0 +1,26 @@
import { faker } from "@faker-js/faker";
const MAX = 10;
function createMessageTemplate() {
return {
id: faker.string.uuid(),
createBy: "DEV",
templateFormat: faker.helpers.arrayElement([1, 2]),
templateName: faker.lorem.words({ min: 2, max: 4 }),
templateDesc: faker.lorem.words({ min: 2, max: 5 }),
templateContent: faker.lorem.paragraphs({ min: 1, max: 10 }),
createDate: Math.floor(faker.date.anytime().getTime() / 1000),
lastModifyDate: Math.floor(faker.date.anytime().getTime() / 1000),
};
}
export default {
status: 200,
data: {
totalMessageTemplateRecord: MAX,
cronjobLogList: faker.helpers.multiple(createMessageTemplate, {
count: MAX,
}),
},
};

8
db/name-cronjobs.js Normal file
View File

@ -0,0 +1,8 @@
export default {
status: 200,
data: [
"cronjob-mdms-pull-meter-alert",
"DAP PERCENTILE DATA",
"DAP WEIS DATA",
],
};

12
package.json Normal file
View File

@ -0,0 +1,12 @@
{
"type": "module",
"scripts": {
"start": "node server.js"
},
"devDependencies": {
"json-server": "^0.17.3"
},
"dependencies": {
"@faker-js/faker": "^8.0.2"
}
}

2377
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
routes.json Normal file
View File

@ -0,0 +1,3 @@
{
"/api/*": "/$1"
}

33
server.js Normal file
View File

@ -0,0 +1,33 @@
import jsonServer from "json-server";
import db from "./db/index.js";
import https from "https";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const server = jsonServer.create();
const PORT = 4000;
const keyFile = path.join(__dirname, "/certs/localhost-key.pem");
const certFile = path.join(__dirname, "/certs/localhost.pem");
const router = jsonServer.router(db);
const middleware = jsonServer.defaults();
server.use(middleware);
server.use("/api", router);
https
.createServer(
{
key: fs.readFileSync(keyFile),
cert: fs.readFileSync(certFile),
},
server
)
.listen(PORT, () => {
console.log(`Go to https://localhost:${PORT}/`);
});