alpe-temp 1.0.0
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/.env.example +13 -0
- package/backend-project/README.md +133 -0
- package/backend-project/package-lock.json +2559 -0
- package/backend-project/package.json +25 -0
- package/backend-project/server.js +28 -0
- package/backend-project/src/app.js +84 -0
- package/backend-project/src/config/app.config.js +72 -0
- package/backend-project/src/config/db.js +20 -0
- package/backend-project/src/config/env.js +19 -0
- package/backend-project/src/middleware/auth.middleware.js +33 -0
- package/backend-project/src/middleware/error.middleware.js +19 -0
- package/backend-project/src/modules/_example/example.controller.js +82 -0
- package/backend-project/src/modules/_example/example.model.js +47 -0
- package/backend-project/src/modules/_example/example.routes.js +43 -0
- package/backend-project/src/modules/_example/example.service.js +58 -0
- package/backend-project/src/modules/auth/auth.controller.js +47 -0
- package/backend-project/src/modules/auth/auth.routes.js +16 -0
- package/backend-project/src/modules/auth/auth.service.js +57 -0
- package/backend-project/src/modules/auth/user.model.js +41 -0
- package/backend-project/src/modules/department/department.controller.js +54 -0
- package/backend-project/src/modules/department/department.model.js +10 -0
- package/backend-project/src/modules/department/department.routes.js +15 -0
- package/backend-project/src/modules/department/department.service.js +29 -0
- package/backend-project/src/modules/employee/employee.controller.js +63 -0
- package/backend-project/src/modules/employee/employee.model.js +15 -0
- package/backend-project/src/modules/employee/employee.routes.js +16 -0
- package/backend-project/src/modules/employee/employee.service.js +30 -0
- package/backend-project/src/modules/excel/excel.controller.js +61 -0
- package/backend-project/src/modules/excel/excel.routes.js +13 -0
- package/backend-project/src/modules/excel/excel.service.js +303 -0
- package/backend-project/src/modules/reports/reports.controller.js +41 -0
- package/backend-project/src/modules/reports/reports.routes.js +10 -0
- package/backend-project/src/modules/salary/salary.controller.js +70 -0
- package/backend-project/src/modules/salary/salary.model.js +23 -0
- package/backend-project/src/modules/salary/salary.routes.js +16 -0
- package/backend-project/src/modules/salary/salary.service.js +44 -0
- package/backend-project/src/seed.js +36 -0
- package/backend-project/src/utils/response.js +35 -0
- package/backend-project/src/utils/token.js +27 -0
- package/bin/epms.js +161 -0
- package/frontend-project/README.md +16 -0
- package/frontend-project/dist/assets/index-B08ICGra.js +20 -0
- package/frontend-project/dist/assets/index-D_cqT2Z6.css +1 -0
- package/frontend-project/dist/car.jfif +0 -0
- package/frontend-project/dist/favicon.svg +1 -0
- package/frontend-project/dist/icons.svg +24 -0
- package/frontend-project/dist/index.html +14 -0
- package/frontend-project/dist/logo.png +0 -0
- package/frontend-project/eslint.config.js +21 -0
- package/frontend-project/index.html +13 -0
- package/frontend-project/package-lock.json +3660 -0
- package/frontend-project/package.json +33 -0
- package/frontend-project/postcss.config.js +6 -0
- package/frontend-project/tailwind.config.js +15 -0
- package/frontend-project/vite.config.js +8 -0
- package/package.json +41 -0
package/bin/epms.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const readline = require('readline');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
8
|
+
const SERVER_ENTRY = path.join(ROOT, 'backend-project', 'server.js');
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
|
|
12
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
13
|
+
console.log(`
|
|
14
|
+
alpe-temp — Employee Payroll Management System (EPMS)
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
npx alpe-temp Start the EPMS server
|
|
18
|
+
npx alpe-temp seed Seed the database with sample data
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
--db <uri> MongoDB connection string (non-interactive)
|
|
22
|
+
|
|
23
|
+
Environment variables (optional):
|
|
24
|
+
PORT Server port (default: 3000)
|
|
25
|
+
MONGODB_URI MongoDB connection string
|
|
26
|
+
JWT_SECRET Secret for JWT signing
|
|
27
|
+
NODE_ENV Environment mode (development/production)
|
|
28
|
+
|
|
29
|
+
Requirements:
|
|
30
|
+
- Node.js >= 18
|
|
31
|
+
- MongoDB (will prompt if not found)
|
|
32
|
+
|
|
33
|
+
Visit http://localhost:3000 after starting.
|
|
34
|
+
`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ─── Config ──────────────────────────────────────────────────────────────────
|
|
39
|
+
const ENV_PATH = path.join(process.cwd(), '.env');
|
|
40
|
+
|
|
41
|
+
function loadEnv() {
|
|
42
|
+
if (!fs.existsSync(ENV_PATH)) return {};
|
|
43
|
+
const env = {};
|
|
44
|
+
for (const line of fs.readFileSync(ENV_PATH, 'utf-8').split('\n')) {
|
|
45
|
+
const trimmed = line.trim();
|
|
46
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
47
|
+
const eq = trimmed.indexOf('=');
|
|
48
|
+
if (eq === -1) continue;
|
|
49
|
+
env[trimmed.slice(0, eq).trim()] = trimmed.slice(eq + 1).trim();
|
|
50
|
+
}
|
|
51
|
+
return env;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function writeEnv(key, value) {
|
|
55
|
+
const existing = fs.existsSync(ENV_PATH) ? fs.readFileSync(ENV_PATH, 'utf-8') : '';
|
|
56
|
+
const re = new RegExp(`^${key}=.*$`, 'm');
|
|
57
|
+
const updated = re.test(existing)
|
|
58
|
+
? existing.replace(re, `${key}=${value}`)
|
|
59
|
+
: (existing ? existing.trimEnd() + '\n' : '') + `${key}=${value}\n`;
|
|
60
|
+
fs.writeFileSync(ENV_PATH, updated, 'utf-8');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function prompt(question, defaultValue) {
|
|
64
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
const hint = defaultValue ? ` (default: ${defaultValue})` : '';
|
|
67
|
+
rl.question(` ${question}${hint}: `, (answer) => {
|
|
68
|
+
rl.close();
|
|
69
|
+
resolve(answer.trim() || defaultValue || '');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function waitForMongo(uri, timeoutMs = 5000) {
|
|
75
|
+
const mongoose = require('mongoose');
|
|
76
|
+
const start = Date.now();
|
|
77
|
+
while (Date.now() - start < timeoutMs) {
|
|
78
|
+
try {
|
|
79
|
+
await mongoose.connect(uri, { serverSelectionTimeoutMS: 2000 });
|
|
80
|
+
await mongoose.disconnect();
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function main() {
|
|
90
|
+
// ─── Seed command ──────────────────────────────────────────────────────
|
|
91
|
+
if (args.includes('seed')) {
|
|
92
|
+
const env = loadEnv();
|
|
93
|
+
if (env.MONGODB_URI) process.env.MONGODB_URI = env.MONGODB_URI;
|
|
94
|
+
console.log('Seeding database...');
|
|
95
|
+
execSync('node ' + path.join(ROOT, 'backend-project', 'src', 'seed.js'), {
|
|
96
|
+
cwd: ROOT,
|
|
97
|
+
stdio: 'inherit',
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ─── Load existing config ──────────────────────────────────────────────
|
|
103
|
+
const env = loadEnv();
|
|
104
|
+
if (env.MONGODB_URI) process.env.MONGODB_URI = env.MONGODB_URI;
|
|
105
|
+
|
|
106
|
+
// ─── --db flag overrides everything ────────────────────────────────────
|
|
107
|
+
const dbIndex = args.indexOf('--db');
|
|
108
|
+
if (dbIndex !== -1 && args[dbIndex + 1]) {
|
|
109
|
+
process.env.MONGODB_URI = args[dbIndex + 1];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ─── Prompt for MongoDB if not configured ──────────────────────────────
|
|
113
|
+
if (!process.env.MONGODB_URI) {
|
|
114
|
+
console.log('\n MongoDB connection not configured.');
|
|
115
|
+
const uri = await prompt(
|
|
116
|
+
'Enter MongoDB URI',
|
|
117
|
+
'mongodb://127.0.0.1:27017/EPMS'
|
|
118
|
+
);
|
|
119
|
+
if (uri) {
|
|
120
|
+
process.env.MONGODB_URI = uri;
|
|
121
|
+
writeEnv('MONGODB_URI', uri);
|
|
122
|
+
console.log(' Saved to .env');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ─── Verify MongoDB is reachable ───────────────────────────────────────
|
|
127
|
+
const uri = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/EPMS';
|
|
128
|
+
process.stdout.write(' Checking MongoDB connection...');
|
|
129
|
+
const reachable = await waitForMongo(uri);
|
|
130
|
+
if (reachable) {
|
|
131
|
+
console.log(' connected');
|
|
132
|
+
} else {
|
|
133
|
+
console.log(' failed');
|
|
134
|
+
console.log(`\n Could not connect to MongoDB at:\n ${uri}\n`);
|
|
135
|
+
const retry = await prompt('Try a different URI', uri);
|
|
136
|
+
if (retry) {
|
|
137
|
+
process.env.MONGODB_URI = retry;
|
|
138
|
+
writeEnv('MONGODB_URI', retry);
|
|
139
|
+
console.log(' Saved to .env');
|
|
140
|
+
process.stdout.write(' Checking MongoDB connection...');
|
|
141
|
+
if (!(await waitForMongo(retry))) {
|
|
142
|
+
console.log(' failed');
|
|
143
|
+
console.error('\n Unable to connect to MongoDB. Please ensure it is running.\n');
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
console.log(' connected');
|
|
147
|
+
} else {
|
|
148
|
+
console.error('\n Unable to connect to MongoDB. Please ensure it is running.\n');
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ─── Start server ──────────────────────────────────────────────────────
|
|
154
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
155
|
+
require(SERVER_ENTRY);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
main().catch((err) => {
|
|
159
|
+
console.error('Failed to start:', err.message);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# React + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
13
|
+
|
|
14
|
+
## Expanding the ESLint configuration
|
|
15
|
+
|
|
16
|
+
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
|