@hapico/cli 0.0.16 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +326 -58
- package/bin/templates/base/.gen/functions.js +126 -0
- package/bin/templates/base/.gen/plugins/router.plugin.js +12 -0
- package/bin/templates/base/plugins/vite-plugin-app-router.js +108 -0
- package/bin/templates/base/src/app.js +18 -0
- package/bin/templates/base/src/db/index.js +132 -0
- package/bin/templates/base/src/server.js +17 -0
- package/bin/utils/codemod/utils/path.mockup.js +84 -0
- package/bun.lock +77 -0
- package/dist/index.js +326 -58
- package/dist/templates/base/.gen/functions.js +126 -0
- package/dist/templates/base/.gen/plugins/router.plugin.js +12 -0
- package/dist/templates/base/plugins/vite-plugin-app-router.js +108 -0
- package/dist/templates/base/src/app.js +18 -0
- package/dist/templates/base/src/db/index.js +132 -0
- package/dist/templates/base/src/server.js +17 -0
- package/dist/utils/codemod/utils/path.mockup.js +84 -0
- package/index.ts +498 -58
- package/package.json +4 -1
- package/utils/codemod/index.tsx +1588 -0
- package/utils/codemod/utils/path.mockup.ts +97 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ALL_FUNCS = void 0;
|
|
7
|
+
const getNewsDetails_1 = __importDefault(require("../src/functions/getNewsDetails"));
|
|
8
|
+
const getNewsFavoriteStatus_1 = __importDefault(require("../src/functions/getNewsFavoriteStatus"));
|
|
9
|
+
const rejectPointRequest_1 = __importDefault(require("../src/functions/rejectPointRequest"));
|
|
10
|
+
const getPhoneNumber_1 = __importDefault(require("../src/functions/getPhoneNumber"));
|
|
11
|
+
const getZaloOaIdConfig_1 = __importDefault(require("../src/functions/getZaloOaIdConfig"));
|
|
12
|
+
const getFlashSalesWithGifts_1 = __importDefault(require("../src/functions/getFlashSalesWithGifts"));
|
|
13
|
+
const getProductDetails_1 = __importDefault(require("../src/functions/getProductDetails"));
|
|
14
|
+
const getLatestGifts_1 = __importDefault(require("../src/functions/getLatestGifts"));
|
|
15
|
+
const updateGiftRedemptionStatus_1 = __importDefault(require("../src/functions/updateGiftRedemptionStatus"));
|
|
16
|
+
const getProducts_1 = __importDefault(require("../src/functions/getProducts"));
|
|
17
|
+
const getVehicleForEdit_1 = __importDefault(require("../src/functions/getVehicleForEdit"));
|
|
18
|
+
const getHomepageBanners_1 = __importDefault(require("../src/functions/getHomepageBanners"));
|
|
19
|
+
const getMembershipRanks_1 = __importDefault(require("../src/functions/getMembershipRanks"));
|
|
20
|
+
const approvePointRequest_1 = __importDefault(require("../src/functions/approvePointRequest"));
|
|
21
|
+
const getRelatedNews_1 = __importDefault(require("../src/functions/getRelatedNews"));
|
|
22
|
+
const getNotifications_1 = __importDefault(require("../src/functions/getNotifications"));
|
|
23
|
+
const deleteVehicle_1 = __importDefault(require("../src/functions/deleteVehicle"));
|
|
24
|
+
const getVehicleModelsByBrand_1 = __importDefault(require("../src/functions/getVehicleModelsByBrand"));
|
|
25
|
+
const getVehiclesByUser_1 = __importDefault(require("../src/functions/getVehiclesByUser"));
|
|
26
|
+
const getUserRedemptions_1 = __importDefault(require("../src/functions/getUserRedemptions"));
|
|
27
|
+
const getOilChangeHistoryByVehicleId_1 = __importDefault(require("../src/functions/getOilChangeHistoryByVehicleId"));
|
|
28
|
+
const getUserRedemptionDetail_1 = __importDefault(require("../src/functions/getUserRedemptionDetail"));
|
|
29
|
+
const recordOilChange_1 = __importDefault(require("../src/functions/recordOilChange"));
|
|
30
|
+
const getGiftCategories_1 = __importDefault(require("../src/functions/getGiftCategories"));
|
|
31
|
+
const getAgencies_1 = __importDefault(require("../src/functions/getAgencies"));
|
|
32
|
+
const redeemGift_1 = __importDefault(require("../src/functions/redeemGift"));
|
|
33
|
+
const getGifts_1 = __importDefault(require("../src/functions/getGifts"));
|
|
34
|
+
const getAgencyDetail_1 = __importDefault(require("../src/functions/getAgencyDetail"));
|
|
35
|
+
const getVehicleBrandsAndModels_1 = __importDefault(require("../src/functions/getVehicleBrandsAndModels"));
|
|
36
|
+
const getNews_1 = __importDefault(require("../src/functions/getNews"));
|
|
37
|
+
const markRedemptionAsUsed_1 = __importDefault(require("../src/functions/markRedemptionAsUsed"));
|
|
38
|
+
const getNearbyAgencies_1 = __importDefault(require("../src/functions/getNearbyAgencies"));
|
|
39
|
+
const addVehicle_1 = __importDefault(require("../src/functions/addVehicle"));
|
|
40
|
+
const claimTask_1 = __importDefault(require("../src/functions/claimTask"));
|
|
41
|
+
const createVehicle_1 = __importDefault(require("../src/functions/createVehicle"));
|
|
42
|
+
const redeemGotitVoucher_1 = __importDefault(require("../src/functions/redeemGotitVoucher"));
|
|
43
|
+
const getGiftDetails_1 = __importDefault(require("../src/functions/getGiftDetails"));
|
|
44
|
+
const markNotificationAsRead_1 = __importDefault(require("../src/functions/markNotificationAsRead"));
|
|
45
|
+
const completeTask_1 = __importDefault(require("../src/functions/completeTask"));
|
|
46
|
+
const getTasks_1 = __importDefault(require("../src/functions/getTasks"));
|
|
47
|
+
const addNewVehicle_1 = __importDefault(require("../src/functions/addNewVehicle"));
|
|
48
|
+
const getQrCodeDetails_1 = __importDefault(require("../src/functions/getQrCodeDetails"));
|
|
49
|
+
const getLocation_1 = __importDefault(require("../src/functions/getLocation"));
|
|
50
|
+
const loginZalo_1 = __importDefault(require("../src/functions/loginZalo"));
|
|
51
|
+
const getOilChangeRecords_1 = __importDefault(require("../src/functions/getOilChangeRecords"));
|
|
52
|
+
const getPendingPointRequests_1 = __importDefault(require("../src/functions/getPendingPointRequests"));
|
|
53
|
+
const getUserLoyaltyInfo_1 = __importDefault(require("../src/functions/getUserLoyaltyInfo"));
|
|
54
|
+
const updateVehicle_1 = __importDefault(require("../src/functions/updateVehicle"));
|
|
55
|
+
const getPointsRedeemed_1 = __importDefault(require("../src/functions/getPointsRedeemed"));
|
|
56
|
+
const getRefreshToken_1 = __importDefault(require("../src/functions/getRefreshToken"));
|
|
57
|
+
const getVehicleBrands_1 = __importDefault(require("../src/functions/getVehicleBrands"));
|
|
58
|
+
const sendMessage_1 = __importDefault(require("../src/functions/sendMessage"));
|
|
59
|
+
const getMembershipBenefits_1 = __importDefault(require("../src/functions/getMembershipBenefits"));
|
|
60
|
+
const updateProfile_1 = __importDefault(require("../src/functions/updateProfile"));
|
|
61
|
+
const processScannedQrCode_1 = __importDefault(require("../src/functions/processScannedQrCode"));
|
|
62
|
+
const toggleNewsFavorite_1 = __importDefault(require("../src/functions/toggleNewsFavorite"));
|
|
63
|
+
const getLoyaltyHistory_1 = __importDefault(require("../src/functions/getLoyaltyHistory"));
|
|
64
|
+
const getNewsDetail_1 = __importDefault(require("../src/functions/getNewsDetail"));
|
|
65
|
+
const getVehicles_1 = __importDefault(require("../src/functions/getVehicles"));
|
|
66
|
+
exports.ALL_FUNCS = {
|
|
67
|
+
getNewsDetails: getNewsDetails_1.default,
|
|
68
|
+
getNewsFavoriteStatus: getNewsFavoriteStatus_1.default,
|
|
69
|
+
rejectPointRequest: rejectPointRequest_1.default,
|
|
70
|
+
getPhoneNumber: getPhoneNumber_1.default,
|
|
71
|
+
getZaloOaIdConfig: getZaloOaIdConfig_1.default,
|
|
72
|
+
getFlashSalesWithGifts: getFlashSalesWithGifts_1.default,
|
|
73
|
+
getProductDetails: getProductDetails_1.default,
|
|
74
|
+
getLatestGifts: getLatestGifts_1.default,
|
|
75
|
+
updateGiftRedemptionStatus: updateGiftRedemptionStatus_1.default,
|
|
76
|
+
getProducts: getProducts_1.default,
|
|
77
|
+
getVehicleForEdit: getVehicleForEdit_1.default,
|
|
78
|
+
getHomepageBanners: getHomepageBanners_1.default,
|
|
79
|
+
getMembershipRanks: getMembershipRanks_1.default,
|
|
80
|
+
approvePointRequest: approvePointRequest_1.default,
|
|
81
|
+
getRelatedNews: getRelatedNews_1.default,
|
|
82
|
+
getNotifications: getNotifications_1.default,
|
|
83
|
+
deleteVehicle: deleteVehicle_1.default,
|
|
84
|
+
getVehicleModelsByBrand: getVehicleModelsByBrand_1.default,
|
|
85
|
+
getVehiclesByUser: getVehiclesByUser_1.default,
|
|
86
|
+
getUserRedemptions: getUserRedemptions_1.default,
|
|
87
|
+
getOilChangeHistoryByVehicleId: getOilChangeHistoryByVehicleId_1.default,
|
|
88
|
+
getUserRedemptionDetail: getUserRedemptionDetail_1.default,
|
|
89
|
+
recordOilChange: recordOilChange_1.default,
|
|
90
|
+
getGiftCategories: getGiftCategories_1.default,
|
|
91
|
+
getAgencies: getAgencies_1.default,
|
|
92
|
+
redeemGift: redeemGift_1.default,
|
|
93
|
+
getGifts: getGifts_1.default,
|
|
94
|
+
getAgencyDetail: getAgencyDetail_1.default,
|
|
95
|
+
getVehicleBrandsAndModels: getVehicleBrandsAndModels_1.default,
|
|
96
|
+
getNews: getNews_1.default,
|
|
97
|
+
markRedemptionAsUsed: markRedemptionAsUsed_1.default,
|
|
98
|
+
getNearbyAgencies: getNearbyAgencies_1.default,
|
|
99
|
+
addVehicle: addVehicle_1.default,
|
|
100
|
+
claimTask: claimTask_1.default,
|
|
101
|
+
createVehicle: createVehicle_1.default,
|
|
102
|
+
redeemGotitVoucher: redeemGotitVoucher_1.default,
|
|
103
|
+
getGiftDetails: getGiftDetails_1.default,
|
|
104
|
+
markNotificationAsRead: markNotificationAsRead_1.default,
|
|
105
|
+
completeTask: completeTask_1.default,
|
|
106
|
+
getTasks: getTasks_1.default,
|
|
107
|
+
addNewVehicle: addNewVehicle_1.default,
|
|
108
|
+
getQrCodeDetails: getQrCodeDetails_1.default,
|
|
109
|
+
getLocation: getLocation_1.default,
|
|
110
|
+
loginZalo: loginZalo_1.default,
|
|
111
|
+
getOilChangeRecords: getOilChangeRecords_1.default,
|
|
112
|
+
getPendingPointRequests: getPendingPointRequests_1.default,
|
|
113
|
+
getUserLoyaltyInfo: getUserLoyaltyInfo_1.default,
|
|
114
|
+
updateVehicle: updateVehicle_1.default,
|
|
115
|
+
getPointsRedeemed: getPointsRedeemed_1.default,
|
|
116
|
+
getRefreshToken: getRefreshToken_1.default,
|
|
117
|
+
getVehicleBrands: getVehicleBrands_1.default,
|
|
118
|
+
sendMessage: sendMessage_1.default,
|
|
119
|
+
getMembershipBenefits: getMembershipBenefits_1.default,
|
|
120
|
+
updateProfile: updateProfile_1.default,
|
|
121
|
+
processScannedQrCode: processScannedQrCode_1.default,
|
|
122
|
+
toggleNewsFavorite: toggleNewsFavorite_1.default,
|
|
123
|
+
getLoyaltyHistory: getLoyaltyHistory_1.default,
|
|
124
|
+
getNewsDetail: getNewsDetail_1.default,
|
|
125
|
+
getVehicles: getVehicles_1.default,
|
|
126
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const functions_1 = require("../functions");
|
|
4
|
+
const funcs = (app) => {
|
|
5
|
+
app.post("/functions/:functionName", async ({ params, body }) => {
|
|
6
|
+
const functionName = params.functionName;
|
|
7
|
+
const response = await functions_1.ALL_FUNCS[functionName](body);
|
|
8
|
+
return response;
|
|
9
|
+
});
|
|
10
|
+
return app;
|
|
11
|
+
};
|
|
12
|
+
exports.default = funcs;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = appRouterPlugin;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
// Function to scan directory and generate routes
|
|
7
|
+
function generateRoutes(dir, basePath = "") {
|
|
8
|
+
const routes = [];
|
|
9
|
+
const entries = (0, fs_1.readdirSync)(dir);
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
12
|
+
const stat = (0, fs_1.statSync)(fullPath);
|
|
13
|
+
if (stat.isDirectory()) {
|
|
14
|
+
const subRoutes = generateRoutes(fullPath, `${basePath}/${entry}`);
|
|
15
|
+
routes.push(...subRoutes);
|
|
16
|
+
}
|
|
17
|
+
else if (stat.isFile() &&
|
|
18
|
+
(entry === "page.tsx" || entry === "page.jsx")) {
|
|
19
|
+
const routePath = basePath || "/";
|
|
20
|
+
routes.push({
|
|
21
|
+
path: routePath,
|
|
22
|
+
componentPath: fullPath,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return routes;
|
|
27
|
+
}
|
|
28
|
+
// Vite plugin
|
|
29
|
+
function appRouterPlugin() {
|
|
30
|
+
let config;
|
|
31
|
+
return {
|
|
32
|
+
name: "vite-plugin-app-router",
|
|
33
|
+
enforce: "pre",
|
|
34
|
+
configResolved(resolvedConfig) {
|
|
35
|
+
config = resolvedConfig;
|
|
36
|
+
},
|
|
37
|
+
// Configure server to handle virtual module
|
|
38
|
+
configureServer(server) {
|
|
39
|
+
server.middlewares.use((req, res, next) => {
|
|
40
|
+
var _a;
|
|
41
|
+
if ((_a = req.url) === null || _a === void 0 ? void 0 : _a.includes("virtual:app-routes")) {
|
|
42
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
43
|
+
next();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
next();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
// Transform virtual module ID
|
|
51
|
+
resolveId(id) {
|
|
52
|
+
if (id === "virtual:app-routes") {
|
|
53
|
+
return "\0virtual:app-routes.tsx";
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
// Load virtual module
|
|
57
|
+
load(id) {
|
|
58
|
+
if (id === "\0virtual:app-routes.tsx") {
|
|
59
|
+
const appDir = (0, path_1.resolve)(config.root, "src/app"); // Changed from 'src/app' to 'app'
|
|
60
|
+
console.log("App Directory:", appDir); // Debug log
|
|
61
|
+
const routes = generateRoutes(appDir);
|
|
62
|
+
console.log("Generated Routes:", routes); // Debug log
|
|
63
|
+
const code = `
|
|
64
|
+
import * as React from 'react';
|
|
65
|
+
import { Routes, Route } from 'react-router-dom';
|
|
66
|
+
|
|
67
|
+
${routes
|
|
68
|
+
.map((route, i) => `import Component${i} from '${route.componentPath.replace(/\\/g, "/")}';`)
|
|
69
|
+
.join("\n")}
|
|
70
|
+
|
|
71
|
+
export const AppRoutes = () => {
|
|
72
|
+
return React.createElement(
|
|
73
|
+
Routes,
|
|
74
|
+
null,
|
|
75
|
+
${routes
|
|
76
|
+
.map((route, i) => `React.createElement(Route, { path: '${route.path}', element: React.createElement(Component${i}) })`)
|
|
77
|
+
.join(",\n")}
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
`;
|
|
81
|
+
console.log("Generated Code:", code); // Debug log
|
|
82
|
+
return {
|
|
83
|
+
code,
|
|
84
|
+
map: null,
|
|
85
|
+
moduleSideEffects: "no-treeshake",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
// Transform the virtual module to ensure JSX processing
|
|
90
|
+
transform(code, id) {
|
|
91
|
+
if (id === "\0virtual:app-routes.tsx") {
|
|
92
|
+
return {
|
|
93
|
+
code,
|
|
94
|
+
map: null,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
// Hot reload for changes in src/app
|
|
99
|
+
handleHotUpdate({ file, server }) {
|
|
100
|
+
if (file.includes("/src/app/") &&
|
|
101
|
+
(file.endsWith("page.tsx") || file.endsWith("page.jsx"))) {
|
|
102
|
+
server.ws.send({
|
|
103
|
+
type: "full-reload",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
require("zmp-ui/zaui.css");
|
|
7
|
+
require("@/css/tailwind.scss");
|
|
8
|
+
require("@/css/app.scss");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const client_1 = require("react-dom/client");
|
|
11
|
+
require("./app.css");
|
|
12
|
+
const app_config_json_1 = __importDefault(require("../app-config.json"));
|
|
13
|
+
const main_1 = require("./main");
|
|
14
|
+
if (!window.APP_CONFIG) {
|
|
15
|
+
window.APP_CONFIG = app_config_json_1.default;
|
|
16
|
+
}
|
|
17
|
+
const root = (0, client_1.createRoot)(document.getElementById("app"));
|
|
18
|
+
root.render(react_1.default.createElement(main_1.Main));
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.auth = exports.HttpError = exports.db = exports.client = void 0;
|
|
4
|
+
const pglite_1 = require("@electric-sql/pglite");
|
|
5
|
+
const client = new pglite_1.PGlite();
|
|
6
|
+
exports.client = client;
|
|
7
|
+
console.log("Connecting to the database...");
|
|
8
|
+
const MIGRATION = `CREATE SEQUENCE IF NOT EXISTS "public"."users_id_seq";;
|
|
9
|
+
CREATE SEQUENCE IF NOT EXISTS "public"."schools_id_seq";;
|
|
10
|
+
CREATE SEQUENCE IF NOT EXISTS "public"."regions_id_seq";;
|
|
11
|
+
CREATE SEQUENCE IF NOT EXISTS "public"."region_admins_id_seq";;
|
|
12
|
+
CREATE TABLE IF NOT EXISTS "public"."users" (
|
|
13
|
+
"id" integer NOT NULL DEFAULT nextval('users_id_seq'::regclass),
|
|
14
|
+
"username" text NOT NULL,
|
|
15
|
+
"password" text NOT NULL,
|
|
16
|
+
"email" text NOT NULL,
|
|
17
|
+
"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
+
"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
+
"deleted_at" timestamp with time zone,
|
|
20
|
+
CONSTRAINT "users_email_key" UNIQUE ("email"),
|
|
21
|
+
CONSTRAINT "users_pkey" PRIMARY KEY ("id"),
|
|
22
|
+
CONSTRAINT "users_username_key" UNIQUE ("username")
|
|
23
|
+
);;
|
|
24
|
+
COMMENT ON COLUMN "public"."users"."username" IS '{"label": "Username", "type": "short_text", "required": true, "description": "Unique username for the user", "visible": true}';;
|
|
25
|
+
COMMENT ON COLUMN "public"."users"."password" IS '{"label": "Password", "type": "password", "required": true, "description": "User password", "visible": false}';;
|
|
26
|
+
COMMENT ON COLUMN "public"."users"."email" IS '{"label": "Email", "type": "email", "required": true, "description": "User email address", "visible": true}';;
|
|
27
|
+
COMMENT ON COLUMN "public"."users"."created_at" IS '{"label": "Created At", "type": "datetime", "required": true, "description": "Timestamp when the user was created", "visible": false}';;
|
|
28
|
+
COMMENT ON COLUMN "public"."users"."updated_at" IS '{"label": "Updated At", "type": "datetime", "required": true, "description": "Timestamp when the user was last updated", "visible": false}';;
|
|
29
|
+
COMMENT ON COLUMN "public"."users"."deleted_at" IS '{"label": "Deleted At", "type": "datetime", "required": false, "description": "Timestamp when the user was deleted", "visible": false}';;
|
|
30
|
+
CREATE TABLE IF NOT EXISTS "public"."regions" (
|
|
31
|
+
"id" integer NOT NULL DEFAULT nextval('regions_id_seq'::regclass),
|
|
32
|
+
"name" character varying NOT NULL,
|
|
33
|
+
"description" text,
|
|
34
|
+
"created_by" integer,
|
|
35
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
36
|
+
"updated_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
37
|
+
"deleted_at" timestamp with time zone,
|
|
38
|
+
CONSTRAINT "fk_regions_created_by" FOREIGN KEY ("created_by") REFERENCES "users" ("id"),
|
|
39
|
+
CONSTRAINT "regions_pkey" PRIMARY KEY ("id")
|
|
40
|
+
);;
|
|
41
|
+
COMMENT ON COLUMN "public"."regions"."id" IS '{"label": "ID", "type": "number", "required": true, "description": "Mã định danh duy nhất của vùng", "visible": false}';;
|
|
42
|
+
COMMENT ON COLUMN "public"."regions"."name" IS '{"label": "Tên vùng", "type": "short_text", "required": true, "description": "Tên của vùng", "visible": true}';;
|
|
43
|
+
COMMENT ON COLUMN "public"."regions"."description" IS '{"label": "Mô tả", "type": "long_text", "required": false, "description": "Mô tả về vùng", "visible": true}';;
|
|
44
|
+
COMMENT ON COLUMN "public"."regions"."created_by" IS '{"label": "Người tạo", "type": "foreign_key", "required": false, "description": "Người đã tạo bản ghi này", "table": "users", "column": "id", "visible": false}';;
|
|
45
|
+
COMMENT ON COLUMN "public"."regions"."created_at" IS '{"label": "Ngày tạo", "type": "datetime", "required": true, "description": "Thời điểm tạo bản ghi", "visible": false}';;
|
|
46
|
+
COMMENT ON COLUMN "public"."regions"."updated_at" IS '{"label": "Ngày cập nhật", "type": "datetime", "required": true, "description": "Thời điểm cập nhật bản ghi cuối cùng", "visible": false}';;
|
|
47
|
+
COMMENT ON COLUMN "public"."regions"."deleted_at" IS '{"label": "Ngày xoá", "type": "datetime", "required": false, "description": "Thời điểm xoá bản ghi (soft delete)", "visible": false}';;
|
|
48
|
+
CREATE TABLE IF NOT EXISTS "public"."schools" (
|
|
49
|
+
"id" integer NOT NULL DEFAULT nextval('schools_id_seq'::regclass),
|
|
50
|
+
"name" character varying NOT NULL,
|
|
51
|
+
"address" text,
|
|
52
|
+
"latitude" numeric NOT NULL,
|
|
53
|
+
"longitude" numeric NOT NULL,
|
|
54
|
+
"created_by" integer,
|
|
55
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
56
|
+
"updated_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
57
|
+
"deleted_at" timestamp with time zone,
|
|
58
|
+
"region_id" integer,
|
|
59
|
+
CONSTRAINT "fk_schools_created_by" FOREIGN KEY ("created_by") REFERENCES "users" ("id"),
|
|
60
|
+
CONSTRAINT "fk_schools_region_id" FOREIGN KEY ("region_id") REFERENCES "regions" ("id"),
|
|
61
|
+
CONSTRAINT "schools_pkey" PRIMARY KEY ("id")
|
|
62
|
+
);;
|
|
63
|
+
COMMENT ON COLUMN "public"."schools"."id" IS '{"label": "ID", "type": "number", "required": true, "description": "Mã định danh duy nhất của trường học", "visible": false}';;
|
|
64
|
+
COMMENT ON COLUMN "public"."schools"."name" IS '{"label": "Tên trường", "type": "short_text", "required": true, "description": "Tên của trường học", "visible": true}';;
|
|
65
|
+
COMMENT ON COLUMN "public"."schools"."address" IS '{"label": "Địa chỉ", "type": "long_text", "required": false, "description": "Địa chỉ của trường học", "visible": true}';;
|
|
66
|
+
COMMENT ON COLUMN "public"."schools"."latitude" IS '{"label": "Vĩ độ", "type": "decimal", "required": true, "description": "Vĩ độ địa lý của trường học", "visible": true}';;
|
|
67
|
+
COMMENT ON COLUMN "public"."schools"."longitude" IS '{"label": "Kinh độ", "type": "decimal", "required": true, "description": "Kinh độ địa lý của trường học", "visible": true}';;
|
|
68
|
+
COMMENT ON COLUMN "public"."schools"."created_by" IS '{"label": "Người tạo", "type": "foreign_key", "required": false, "description": "Người đã tạo bản ghi này", "table": "users", "column": "id", "visible": false}';;
|
|
69
|
+
COMMENT ON COLUMN "public"."schools"."created_at" IS '{"label": "Ngày tạo", "type": "datetime", "required": true, "description": "Thời điểm tạo bản ghi", "visible": false}';;
|
|
70
|
+
COMMENT ON COLUMN "public"."schools"."updated_at" IS '{"label": "Ngày cập nhật", "type": "datetime", "required": true, "description": "Thời điểm cập nhật bản ghi cuối cùng", "visible": false}';;
|
|
71
|
+
COMMENT ON COLUMN "public"."schools"."deleted_at" IS '{"label": "Ngày xoá", "type": "datetime", "required": false, "description": "Thời điểm xoá bản ghi (soft delete)", "visible": false}';;
|
|
72
|
+
COMMENT ON COLUMN "public"."schools"."region_id" IS '{"label": "Vùng", "type": "foreign_key", "required": false, "description": "Vùng mà trường học thuộc về", "table": "regions", "column": "id", "visible": true}';;
|
|
73
|
+
CREATE TABLE IF NOT EXISTS "public"."region_admins" (
|
|
74
|
+
"id" integer NOT NULL DEFAULT nextval('region_admins_id_seq'::regclass),
|
|
75
|
+
"region_id" integer NOT NULL,
|
|
76
|
+
"user_id" integer NOT NULL,
|
|
77
|
+
"created_by" integer,
|
|
78
|
+
"created_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
79
|
+
"updated_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
80
|
+
"deleted_at" timestamp with time zone,
|
|
81
|
+
CONSTRAINT "fk_region_admins_created_by" FOREIGN KEY ("created_by") REFERENCES "users" ("id"),
|
|
82
|
+
CONSTRAINT "fk_region_admins_region_id" FOREIGN KEY ("region_id") REFERENCES "regions" ("id"),
|
|
83
|
+
CONSTRAINT "fk_region_admins_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id"),
|
|
84
|
+
CONSTRAINT "region_admins_pkey" PRIMARY KEY ("id"),
|
|
85
|
+
CONSTRAINT "uq_region_admins_region_user" UNIQUE ("region_id", "user_id")
|
|
86
|
+
);;
|
|
87
|
+
COMMENT ON COLUMN "public"."region_admins"."id" IS '{"label": "ID", "type": "number", "required": true, "description": "Mã định danh duy nhất của liên kết admin vùng", "visible": false}';;
|
|
88
|
+
COMMENT ON COLUMN "public"."region_admins"."region_id" IS '{"label": "Vùng", "type": "foreign_key", "required": true, "description": "Mã định danh của vùng", "table": "regions", "column": "id", "visible": true}';;
|
|
89
|
+
COMMENT ON COLUMN "public"."region_admins"."user_id" IS '{"label": "Người dùng (Admin)", "type": "foreign_key", "required": true, "description": "Mã định danh của người dùng là admin cho vùng này", "table": "users", "column": "id", "visible": true}';;
|
|
90
|
+
COMMENT ON COLUMN "public"."region_admins"."created_by" IS '{"label": "Người tạo", "type": "foreign_key", "required": false, "description": "Người đã tạo liên kết này", "table": "users", "column": "id", "visible": false}';;
|
|
91
|
+
COMMENT ON COLUMN "public"."region_admins"."created_at" IS '{"label": "Ngày tạo", "type": "datetime", "required": true, "description": "Thời điểm tạo bản ghi", "visible": false}';;
|
|
92
|
+
COMMENT ON COLUMN "public"."region_admins"."updated_at" IS '{"label": "Ngày cập nhật", "type": "datetime", "required": true, "description": "Thời điểm cập nhật bản ghi cuối cùng", "visible": false}';;
|
|
93
|
+
COMMENT ON COLUMN "public"."region_admins"."deleted_at" IS '{"label": "Ngày xoá", "type": "datetime", "required": false, "description": "Thời điểm xoá bản ghi (soft delete)", "visible": false}';
|
|
94
|
+
|
|
95
|
+
INSERT INTO "public"."users" ("username", "password", "email") VALUES ('admin', '$2a$12$fx1EZ0GDonLi5rv9w3d0F.HWt1j9jmibw1b76TzaYytBZlALXrH0m', 'sohutek@gmaail.com')
|
|
96
|
+
`;
|
|
97
|
+
client.exec(MIGRATION);
|
|
98
|
+
class HttpError extends Error {
|
|
99
|
+
constructor(message, status) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.status = status;
|
|
102
|
+
this.name = "HttpError";
|
|
103
|
+
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return {
|
|
106
|
+
message: this.message,
|
|
107
|
+
status: this.status,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
toString() {
|
|
111
|
+
return JSON.stringify(this.toJSON());
|
|
112
|
+
}
|
|
113
|
+
static fromError(error) {
|
|
114
|
+
return new HttpError(error.message, 500);
|
|
115
|
+
}
|
|
116
|
+
static fromStatus(status, message) {
|
|
117
|
+
return new HttpError(message, status);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.HttpError = HttpError;
|
|
121
|
+
const auth = async () => {
|
|
122
|
+
// Simulate authentication logic
|
|
123
|
+
// In a real application, you would verify a token or session here
|
|
124
|
+
return {
|
|
125
|
+
id: 1, // Example user ID
|
|
126
|
+
username: "admin", // Example username
|
|
127
|
+
email: "",
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
exports.auth = auth;
|
|
131
|
+
const db = client; // Exporting client as db for compatibility
|
|
132
|
+
exports.db = db;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var _a, _b;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const elysia_1 = require("elysia");
|
|
8
|
+
const cors_1 = require("@elysiajs/cors");
|
|
9
|
+
const router_plugin_1 = __importDefault(require("../.gen/plugins/router.plugin"));
|
|
10
|
+
const swagger_1 = __importDefault(require("@elysiajs/swagger"));
|
|
11
|
+
const app = new elysia_1.Elysia()
|
|
12
|
+
.use((0, cors_1.cors)())
|
|
13
|
+
.use((0, swagger_1.default)())
|
|
14
|
+
.use(router_plugin_1.default)
|
|
15
|
+
.get("/", () => "Hello Elysia")
|
|
16
|
+
.listen(3006);
|
|
17
|
+
console.log(`🦊 Elysia is running at ${(_a = app.server) === null || _a === void 0 ? void 0 : _a.hostname}:${(_b = app.server) === null || _b === void 0 ? void 0 : _b.port}`);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Path {
|
|
4
|
+
static normalizeSlashes(path) {
|
|
5
|
+
return path.replace(/\\/g, "/");
|
|
6
|
+
}
|
|
7
|
+
// Tương tự path.join()
|
|
8
|
+
static join(...paths) {
|
|
9
|
+
const normalizedPaths = paths
|
|
10
|
+
.filter((p) => p && typeof p === "string")
|
|
11
|
+
.map((p) => this.normalizeSlashes(p.trim()))
|
|
12
|
+
.map((p) => p.replace(/^\/+|\/+$/g, "")); // Loại bỏ slash đầu và cuối
|
|
13
|
+
return normalizedPaths.join("/");
|
|
14
|
+
}
|
|
15
|
+
// Tương tự path.resolve()
|
|
16
|
+
static resolve(...paths) {
|
|
17
|
+
let resolvedPath = "";
|
|
18
|
+
const segments = [];
|
|
19
|
+
paths
|
|
20
|
+
.filter((p) => p && typeof p === "string")
|
|
21
|
+
.map((p) => this.normalizeSlashes(p))
|
|
22
|
+
.forEach((path) => {
|
|
23
|
+
if (path.startsWith("/")) {
|
|
24
|
+
segments.length = 0; // Reset nếu gặp absolute path
|
|
25
|
+
segments.push(...path.split("/").filter(Boolean));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
segments.push(...path.split("/").filter(Boolean));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const resolvedSegments = [];
|
|
32
|
+
for (const segment of segments) {
|
|
33
|
+
if (segment === "..") {
|
|
34
|
+
resolvedSegments.pop();
|
|
35
|
+
}
|
|
36
|
+
else if (segment !== ".") {
|
|
37
|
+
resolvedSegments.push(segment);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
resolvedPath = resolvedSegments.join("/");
|
|
41
|
+
return resolvedPath.startsWith("/") ? `/${resolvedPath}` : resolvedPath;
|
|
42
|
+
}
|
|
43
|
+
// Tương tự path.basename()
|
|
44
|
+
static basename(path, ext) {
|
|
45
|
+
const normalized = this.normalizeSlashes(path);
|
|
46
|
+
const base = normalized.split("/").pop() || "";
|
|
47
|
+
return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base;
|
|
48
|
+
}
|
|
49
|
+
// Tương tự path.dirname()
|
|
50
|
+
static dirname(path) {
|
|
51
|
+
const normalized = this.normalizeSlashes(path);
|
|
52
|
+
const segments = normalized.split("/");
|
|
53
|
+
segments.pop();
|
|
54
|
+
return segments.join("/") || ".";
|
|
55
|
+
}
|
|
56
|
+
// Tương tự path.extname()
|
|
57
|
+
static extname(path) {
|
|
58
|
+
const base = this.basename(path);
|
|
59
|
+
const dotIndex = base.lastIndexOf(".");
|
|
60
|
+
return dotIndex > 0 ? base.slice(dotIndex) : "";
|
|
61
|
+
}
|
|
62
|
+
// Tương tự path.isAbsolute()
|
|
63
|
+
static isAbsolute(path) {
|
|
64
|
+
return this.normalizeSlashes(path).startsWith("/");
|
|
65
|
+
}
|
|
66
|
+
// Tương tự path.relative()
|
|
67
|
+
static relative(from, to) {
|
|
68
|
+
const fromParts = this.normalizeSlashes(from).split("/").filter(Boolean);
|
|
69
|
+
const toParts = this.normalizeSlashes(to).split("/").filter(Boolean);
|
|
70
|
+
// Tìm điểm chung
|
|
71
|
+
let i = 0;
|
|
72
|
+
while (i < fromParts.length &&
|
|
73
|
+
i < toParts.length &&
|
|
74
|
+
fromParts[i] === toParts[i]) {
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
// Tính số bước đi lên
|
|
78
|
+
const upCount = fromParts.length - i;
|
|
79
|
+
const up = Array(upCount).fill("..");
|
|
80
|
+
const remaining = toParts.slice(i);
|
|
81
|
+
return [...up, ...remaining].join("/") || ".";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.default = Path;
|