moahmedwafy commited on
Commit
8e95ccf
Β·
unverified Β·
2 Parent(s): 8e97867 2003362

Merge pull request #10 from Modarb-Ai-Trainer/refactor

Browse files
Files changed (26) hide show
  1. package-lock.json +89 -51
  2. package.json +1 -1
  3. src/configs/app.ts +0 -17
  4. src/configs/config.ts +17 -0
  5. src/configs/database.ts +6 -18
  6. src/configs/env.ts +25 -0
  7. src/index.route.ts +14 -32
  8. src/index.ts +24 -6
  9. src/modules/common/{Template/models/templet.model.ts β†’ templates/models/template.model.ts} +0 -0
  10. src/modules/common/{User β†’ users}/models/user.model.ts +0 -0
  11. src/modules/common/{User/services/user.base.service.ts β†’ users/services/users.base.service.ts} +1 -1
  12. src/modules/common/{User β†’ users}/validation/user.baseValidation.ts +0 -0
  13. src/modules/console/User/services/user.service.ts +0 -8
  14. src/modules/console/{Admin/controllers/admin.controller.ts β†’ admins/controllers/admins.controller.ts} +0 -0
  15. src/modules/console/{Admin β†’ admins}/models/admin.model.ts +0 -0
  16. src/modules/console/{Admin/services/admin.service.ts β†’ admins/services/admins.service.ts} +1 -1
  17. src/modules/console/index.route.ts +6 -6
  18. src/modules/console/{User/controllers/user.controller.ts β†’ users/controllers/users.controller.ts} +3 -3
  19. src/modules/console/{User/routes/admin.userRoute.ts β†’ users/routes/admin-users.route.ts} +2 -2
  20. src/modules/console/users/services/users.service.ts +3 -0
  21. src/modules/console/{User β†’ users}/validation/admin.userValidation.ts +1 -2
  22. src/modules/user/index.route.ts +1 -1
  23. src/modules/user/{User β†’ users}/controllers/auth.controller.ts +3 -3
  24. src/modules/user/{User β†’ users}/routes/auth.route.ts +0 -0
  25. src/modules/user/{User/services/user.service.ts β†’ users/services/users.service.ts} +4 -4
  26. src/modules/user/{User β†’ users}/validation/user.Validation.ts +1 -1
package-lock.json CHANGED
@@ -10,7 +10,6 @@
10
  "license": "ISC",
11
  "dependencies": {
12
  "bcrypt": "^5.1.1",
13
- "body-parser": "^1.20.2",
14
  "cors": "^2.8.5",
15
  "dotenv": "^16.3.1",
16
  "express": "^4.18.2",
@@ -21,6 +20,7 @@
21
  "path": "^0.12.7"
22
  },
23
  "devDependencies": {
 
24
  "nodemon": "^3.0.2",
25
  "ts-node": "^10.9.2",
26
  "typescript": "^5.3.3"
@@ -159,6 +159,61 @@
159
  "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
160
  "dev": true
161
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  "node_modules/@types/node": {
163
  "version": "20.10.4",
164
  "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz",
@@ -167,6 +222,39 @@
167
  "undici-types": "~5.26.4"
168
  }
169
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  "node_modules/@types/webidl-conversions": {
171
  "version": "7.0.3",
172
  "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
@@ -306,42 +394,6 @@
306
  "node": ">=8"
307
  }
308
  },
309
- "node_modules/body-parser": {
310
- "version": "1.20.2",
311
- "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
312
- "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
313
- "dependencies": {
314
- "bytes": "3.1.2",
315
- "content-type": "~1.0.5",
316
- "debug": "2.6.9",
317
- "depd": "2.0.0",
318
- "destroy": "1.2.0",
319
- "http-errors": "2.0.0",
320
- "iconv-lite": "0.4.24",
321
- "on-finished": "2.4.1",
322
- "qs": "6.11.0",
323
- "raw-body": "2.5.2",
324
- "type-is": "~1.6.18",
325
- "unpipe": "1.0.0"
326
- },
327
- "engines": {
328
- "node": ">= 0.8",
329
- "npm": "1.2.8000 || >= 1.4.16"
330
- }
331
- },
332
- "node_modules/body-parser/node_modules/debug": {
333
- "version": "2.6.9",
334
- "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
335
- "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
336
- "dependencies": {
337
- "ms": "2.0.0"
338
- }
339
- },
340
- "node_modules/body-parser/node_modules/ms": {
341
- "version": "2.0.0",
342
- "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
343
- "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
344
- },
345
  "node_modules/brace-expansion": {
346
  "version": "1.1.11",
347
  "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@@ -1664,20 +1716,6 @@
1664
  "node": ">= 0.6"
1665
  }
1666
  },
1667
- "node_modules/raw-body": {
1668
- "version": "2.5.2",
1669
- "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
1670
- "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
1671
- "dependencies": {
1672
- "bytes": "3.1.2",
1673
- "http-errors": "2.0.0",
1674
- "iconv-lite": "0.4.24",
1675
- "unpipe": "1.0.0"
1676
- },
1677
- "engines": {
1678
- "node": ">= 0.8"
1679
- }
1680
- },
1681
  "node_modules/readable-stream": {
1682
  "version": "3.6.2",
1683
  "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
 
10
  "license": "ISC",
11
  "dependencies": {
12
  "bcrypt": "^5.1.1",
 
13
  "cors": "^2.8.5",
14
  "dotenv": "^16.3.1",
15
  "express": "^4.18.2",
 
20
  "path": "^0.12.7"
21
  },
22
  "devDependencies": {
23
+ "@types/express": "^4.17.21",
24
  "nodemon": "^3.0.2",
25
  "ts-node": "^10.9.2",
26
  "typescript": "^5.3.3"
 
159
  "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
160
  "dev": true
161
  },
162
+ "node_modules/@types/body-parser": {
163
+ "version": "1.19.5",
164
+ "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz",
165
+ "integrity": "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==",
166
+ "dev": true,
167
+ "dependencies": {
168
+ "@types/connect": "*",
169
+ "@types/node": "*"
170
+ }
171
+ },
172
+ "node_modules/@types/connect": {
173
+ "version": "3.4.38",
174
+ "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz",
175
+ "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==",
176
+ "dev": true,
177
+ "dependencies": {
178
+ "@types/node": "*"
179
+ }
180
+ },
181
+ "node_modules/@types/express": {
182
+ "version": "4.17.21",
183
+ "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz",
184
+ "integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==",
185
+ "dev": true,
186
+ "dependencies": {
187
+ "@types/body-parser": "*",
188
+ "@types/express-serve-static-core": "^4.17.33",
189
+ "@types/qs": "*",
190
+ "@types/serve-static": "*"
191
+ }
192
+ },
193
+ "node_modules/@types/express-serve-static-core": {
194
+ "version": "4.17.41",
195
+ "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.41.tgz",
196
+ "integrity": "sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA==",
197
+ "dev": true,
198
+ "dependencies": {
199
+ "@types/node": "*",
200
+ "@types/qs": "*",
201
+ "@types/range-parser": "*",
202
+ "@types/send": "*"
203
+ }
204
+ },
205
+ "node_modules/@types/http-errors": {
206
+ "version": "2.0.4",
207
+ "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz",
208
+ "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==",
209
+ "dev": true
210
+ },
211
+ "node_modules/@types/mime": {
212
+ "version": "1.3.5",
213
+ "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
214
+ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
215
+ "dev": true
216
+ },
217
  "node_modules/@types/node": {
218
  "version": "20.10.4",
219
  "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz",
 
222
  "undici-types": "~5.26.4"
223
  }
224
  },
225
+ "node_modules/@types/qs": {
226
+ "version": "6.9.11",
227
+ "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.11.tgz",
228
+ "integrity": "sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==",
229
+ "dev": true
230
+ },
231
+ "node_modules/@types/range-parser": {
232
+ "version": "1.2.7",
233
+ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz",
234
+ "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
235
+ "dev": true
236
+ },
237
+ "node_modules/@types/send": {
238
+ "version": "0.17.4",
239
+ "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",
240
+ "integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==",
241
+ "dev": true,
242
+ "dependencies": {
243
+ "@types/mime": "^1",
244
+ "@types/node": "*"
245
+ }
246
+ },
247
+ "node_modules/@types/serve-static": {
248
+ "version": "1.15.5",
249
+ "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.5.tgz",
250
+ "integrity": "sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==",
251
+ "dev": true,
252
+ "dependencies": {
253
+ "@types/http-errors": "*",
254
+ "@types/mime": "*",
255
+ "@types/node": "*"
256
+ }
257
+ },
258
  "node_modules/@types/webidl-conversions": {
259
  "version": "7.0.3",
260
  "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
 
394
  "node": ">=8"
395
  }
396
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  "node_modules/brace-expansion": {
398
  "version": "1.1.11",
399
  "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
 
1716
  "node": ">= 0.6"
1717
  }
1718
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1719
  "node_modules/readable-stream": {
1720
  "version": "3.6.2",
1721
  "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
package.json CHANGED
@@ -12,13 +12,13 @@
12
  "author": "",
13
  "license": "ISC",
14
  "devDependencies": {
 
15
  "nodemon": "^3.0.2",
16
  "ts-node": "^10.9.2",
17
  "typescript": "^5.3.3"
18
  },
19
  "dependencies": {
20
  "bcrypt": "^5.1.1",
21
- "body-parser": "^1.20.2",
22
  "cors": "^2.8.5",
23
  "dotenv": "^16.3.1",
24
  "express": "^4.18.2",
 
12
  "author": "",
13
  "license": "ISC",
14
  "devDependencies": {
15
+ "@types/express": "^4.17.21",
16
  "nodemon": "^3.0.2",
17
  "ts-node": "^10.9.2",
18
  "typescript": "^5.3.3"
19
  },
20
  "dependencies": {
21
  "bcrypt": "^5.1.1",
 
22
  "cors": "^2.8.5",
23
  "dotenv": "^16.3.1",
24
  "express": "^4.18.2",
src/configs/app.ts DELETED
@@ -1,17 +0,0 @@
1
- import dotenv from "dotenv";
2
- dotenv.config();
3
- import express from "express";
4
- import bodyParser from "body-parser";
5
- import cors from "cors";
6
- import path from 'path';
7
- import { routes } from "../index.route";
8
- import { connection as databaseConnection } from "./database";
9
-
10
- databaseConnection();
11
- export const app = express();
12
- app.use(cors());
13
- app.use(express.json());
14
- app.use(routes);
15
- app.use(bodyParser.json());
16
-
17
- app.use(bodyParser.urlencoded({ extended: false }));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/configs/config.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Env } from "./env";
2
+ import dotenv from "dotenv";
3
+ dotenv.config();
4
+
5
+ export interface Config {
6
+ port: number;
7
+ db: {
8
+ uri: string;
9
+ };
10
+ }
11
+
12
+ export const config: Config = {
13
+ port: Env.get("PORT", 4000).toNumber(),
14
+ db: {
15
+ uri: Env.get("DB_URI").toString(),
16
+ },
17
+ };
src/configs/database.ts CHANGED
@@ -1,20 +1,8 @@
1
- import mongoose from 'mongoose';
 
2
 
3
- const uriMap = {
4
- local: process.env.LOCAL_DB_CONNECTION_STRING,
5
- development: process.env.DEV_DB_CONNECTION_STRING,
 
6
  };
7
-
8
- console.log("CURRENT_ENV", process.env.CURRENT_ENV);
9
- const selectedEnv = process.env.CURRENT_ENV || 'development';
10
- let uri = uriMap[selectedEnv];
11
- console.log(uri);
12
-
13
- export const connection = async () => {
14
- return mongoose.connect(uri)
15
- .then(() => {
16
- console.log(`Connected to MongoDB database successfully on ${selectedEnv} environment!`);
17
- }).catch((err) => {
18
- console.log("MongoDB Error: ", err);
19
- })
20
- }
 
1
+ import mongoose from "mongoose";
2
+ import { config } from "./config";
3
 
4
+ export const connectDatabase = async () => {
5
+ return mongoose.connect(config.db.uri).then(() => {
6
+ console.log(`Connected to MongoDB database successfully!`);
7
+ });
8
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/configs/env.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class EnvValue {
2
+ constructor(public value: string | number | boolean) {}
3
+
4
+ toString(): string {
5
+ return String(this.value);
6
+ }
7
+ toNumber(): number {
8
+ return Number(this.value);
9
+ }
10
+ toBoolean(): boolean {
11
+ return this.value === "true";
12
+ }
13
+ }
14
+
15
+ export class Env {
16
+ static get(key: string, defaultValue?: string | number | boolean): EnvValue {
17
+ const value = process.env[key] || defaultValue;
18
+
19
+ if (!value) {
20
+ throw new Error(`Environment variable ${key} not found`);
21
+ }
22
+
23
+ return new EnvValue(value);
24
+ }
25
+ }
src/index.route.ts CHANGED
@@ -1,38 +1,20 @@
1
- import express from 'express';
2
- const app = express.Router();
3
 
4
- import { userRoutes } from './modules/user/index.route';
5
- import { adminRoutes } from './modules/console/index.route';
6
 
7
- app.use("/api/v1/user", userRoutes);
8
- app.use("/api/v1/admin", adminRoutes);
9
 
 
 
10
 
11
- app.get("/", (req: any, res: any) => {
12
- res.status(200).json({ success: true, message: 'Welcome Message', code: 200 })
13
- })
14
 
15
- app.get("*", (req: any, res: any) => {
16
- res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
17
- })
 
18
 
19
- app.post("*", (req: any, res: any) => {
20
- res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
21
- })
22
-
23
- app.put("*", (req: any, res: any) => {
24
- res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
25
- })
26
-
27
- app.delete("*", (req: any, res: any) => {
28
- res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
29
- })
30
-
31
-
32
- app.patch("*", (req: any, res: any) => {
33
- res.status(404).json({ success: false, message: "Invalid URL!", code: 404 })
34
- })
35
-
36
-
37
-
38
- export { app as routes };
 
1
+ import express from "express";
 
2
 
3
+ import { userRoutes } from "./modules/user/index.route";
4
+ import { adminRouter } from "./modules/console/index.route";
5
 
6
+ const mainRouter = express.Router();
 
7
 
8
+ mainRouter.use("/user", userRoutes);
9
+ mainRouter.use("/admin", adminRouter);
10
 
11
+ mainRouter.get("/health", (_req: any, res: any) => {
12
+ res.status(200).json({ success: true, message: "Server is up!", code: 200 });
13
+ });
14
 
15
+ // catch non existing routes
16
+ mainRouter.all("*", (_req: any, res: any) => {
17
+ res.status(404).json({ success: false, message: "Invalid URL!", code: 404 });
18
+ });
19
 
20
+ export { mainRouter };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/index.ts CHANGED
@@ -1,10 +1,28 @@
1
- import { app } from "./configs/app"
2
- import http from 'http';
 
 
 
3
 
4
- const server = http.createServer(app);
 
 
5
 
6
- server.listen(process.env.PORT || 4000, () => {
7
- console.log(`Server is up and runing on port ${process.env.PORT}!`)
8
- })
9
 
 
 
 
 
10
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from "express";
2
+ import cors from "cors";
3
+ import { connectDatabase } from "./configs/database";
4
+ import { config } from "./configs/config";
5
+ import { mainRouter } from "./index.route";
6
 
7
+ const main = async () => {
8
+ // set up database connection
9
+ await connectDatabase();
10
 
11
+ // set up express server
12
+ const app = express();
 
13
 
14
+ // set up middlewares
15
+ app.use(cors());
16
+ app.use(express.urlencoded({ extended: true }));
17
+ app.use(express.json());
18
 
19
+ // set up routes
20
+ app.use("/api/v1", mainRouter);
21
+
22
+ // start server
23
+ app.listen(config.port, () => {
24
+ console.log(`Server is up and running on port ${config.port}!`);
25
+ });
26
+ };
27
+
28
+ main();
src/modules/common/{Template/models/templet.model.ts β†’ templates/models/template.model.ts} RENAMED
File without changes
src/modules/common/{User β†’ users}/models/user.model.ts RENAMED
File without changes
src/modules/common/{User/services/user.base.service.ts β†’ users/services/users.base.service.ts} RENAMED
@@ -1,7 +1,7 @@
1
  import { userModel, } from '../models/user.model'
2
 
3
 
4
- export class UserBaseService {
5
  static async find(filterObject) {
6
  try {
7
  const resultObject = await userModel.findOne(filterObject).lean();
 
1
  import { userModel, } from '../models/user.model'
2
 
3
 
4
+ export class UsersBaseService {
5
  static async find(filterObject) {
6
  try {
7
  const resultObject = await userModel.findOne(filterObject).lean();
src/modules/common/{User β†’ users}/validation/user.baseValidation.ts RENAMED
File without changes
src/modules/console/User/services/user.service.ts DELETED
@@ -1,8 +0,0 @@
1
- import { UserBaseService } from "../../../common/User/services/user.base.service";
2
-
3
- export class userService extends UserBaseService {
4
-
5
- }
6
-
7
-
8
-
 
 
 
 
 
 
 
 
 
src/modules/console/{Admin/controllers/admin.controller.ts β†’ admins/controllers/admins.controller.ts} RENAMED
File without changes
src/modules/console/{Admin β†’ admins}/models/admin.model.ts RENAMED
File without changes
src/modules/console/{Admin/services/admin.service.ts β†’ admins/services/admins.service.ts} RENAMED
@@ -2,7 +2,7 @@ import bcrypt from "bcrypt";
2
  import { adminModel, saltrounds } from '../models/admin.model'
3
 
4
 
5
- export class AdminService {
6
  static async find(filterObject) {
7
  try {
8
  const resultObject = await adminModel.findOne(filterObject).lean();
 
2
  import { adminModel, saltrounds } from '../models/admin.model'
3
 
4
 
5
+ export class AdminsService {
6
  static async find(filterObject) {
7
  try {
8
  const resultObject = await adminModel.findOne(filterObject).lean();
src/modules/console/index.route.ts CHANGED
@@ -1,11 +1,11 @@
1
- import express from 'express';
2
- const app = express();
3
 
4
- import { jwtHelper } from '../../helpers/jwt.helper';
5
  const allowedRoles = ["superAdmin", "admin"];
6
 
7
- import { adminUserRoutes } from './User/routes/admin.userRoute';
8
 
9
- app.use("/users", jwtHelper.verifyToken(allowedRoles), adminUserRoutes);
10
 
11
- export { app as adminRoutes };
 
1
+ import express from "express";
2
+ const adminRouter = express.Router();
3
 
4
+ import { jwtHelper } from "../../helpers/jwt.helper";
5
  const allowedRoles = ["superAdmin", "admin"];
6
 
7
+ import { adminUserRoutes } from "./users/routes/admin-users.route";
8
 
9
+ adminRouter.use("/users", jwtHelper.verifyToken(allowedRoles), adminUserRoutes);
10
 
11
+ export { adminRouter };
src/modules/console/{User/controllers/user.controller.ts β†’ users/controllers/users.controller.ts} RENAMED
@@ -1,10 +1,10 @@
1
- import { userService } from "../services/user.service";
2
 
3
- export class adminUserController {
4
 
5
  static async create(req, res) {
6
  try {
7
- let result = await userService.create(req.body);
8
  return res.status(result.code).json(result);
9
  } catch (err) {
10
  console.log(`err.message`, err.message);
 
1
+ import { usersService } from "../services/users.service";
2
 
3
+ export class adminUsersController {
4
 
5
  static async create(req, res) {
6
  try {
7
+ let result = await usersService.create(req.body);
8
  return res.status(result.code).json(result);
9
  } catch (err) {
10
  console.log(`err.message`, err.message);
src/modules/console/{User/routes/admin.userRoute.ts β†’ users/routes/admin-users.route.ts} RENAMED
@@ -1,11 +1,11 @@
1
  import express from "express";
2
- import { adminUserController } from "../controllers/user.controller";
3
  import { adminUserValidation } from "../validation/admin.userValidation";
4
  import { validator } from "../../../../helpers/validation.helper";
5
 
6
  const app = express.Router();
7
 
8
- app.post("/create", validator(adminUserValidation.createValidation), adminUserController.create);
9
 
10
  export { app as adminUserRoutes };
11
 
 
1
  import express from "express";
2
+ import { adminUsersController } from "../controllers/users.controller";
3
  import { adminUserValidation } from "../validation/admin.userValidation";
4
  import { validator } from "../../../../helpers/validation.helper";
5
 
6
  const app = express.Router();
7
 
8
+ app.post("/create", validator(adminUserValidation.createValidation), adminUsersController.create);
9
 
10
  export { app as adminUserRoutes };
11
 
src/modules/console/users/services/users.service.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ import { UsersBaseService } from "../../../common/users/services/users.base.service";
2
+
3
+ export class usersService extends UsersBaseService {}
src/modules/console/{User β†’ users}/validation/admin.userValidation.ts RENAMED
@@ -1,5 +1,4 @@
1
- import joi from 'joi';
2
- import { userBaseValidation } from '../../../common/User/validation/user.baseValidation';
3
 
4
  export class adminUserValidation extends userBaseValidation {
5
 
 
1
+ import { userBaseValidation } from '../../../common/users/validation/user.baseValidation';
 
2
 
3
  export class adminUserValidation extends userBaseValidation {
4
 
src/modules/user/index.route.ts CHANGED
@@ -4,7 +4,7 @@ const app = express();
4
  import { jwtHelper } from '../../helpers/jwt.helper';
5
  const allowedRoles = ["user"];
6
 
7
- import { authRoutes } from './User/routes/auth.route';
8
 
9
  app.use(authRoutes);
10
 
 
4
  import { jwtHelper } from '../../helpers/jwt.helper';
5
  const allowedRoles = ["user"];
6
 
7
+ import { authRoutes } from './users/routes/auth.route';
8
 
9
  app.use(authRoutes);
10
 
src/modules/user/{User β†’ users}/controllers/auth.controller.ts RENAMED
@@ -1,11 +1,11 @@
1
- import { userService } from "../services/user.service";
2
  import { jwtHelper } from "../../../../helpers/jwt.helper";
3
 
4
  export class authController {
5
 
6
  static async register(req, res) {
7
  try {
8
- let result = await userService.create(req.body);
9
  return res.status(result.code).json(result);
10
  } catch (err) {
11
  console.log(`err.message`, err.message);
@@ -20,7 +20,7 @@ export class authController {
20
  static async login(req, res) {
21
  try {
22
  const { email, password } = req.body;
23
- let result: { success: boolean; code: number; record?: any; message?: string } = await userService.comparePassword(email, password);
24
  if (!result.success) return res.status(result.code).json(result);
25
  let payload = {
26
  _id: result.record?._id, name: result.record?.name,
 
1
+ import { usersService } from "../services/users.service";
2
  import { jwtHelper } from "../../../../helpers/jwt.helper";
3
 
4
  export class authController {
5
 
6
  static async register(req, res) {
7
  try {
8
+ let result = await usersService.create(req.body);
9
  return res.status(result.code).json(result);
10
  } catch (err) {
11
  console.log(`err.message`, err.message);
 
20
  static async login(req, res) {
21
  try {
22
  const { email, password } = req.body;
23
+ let result: { success: boolean; code: number; record?: any; message?: string } = await usersService.comparePassword(email, password);
24
  if (!result.success) return res.status(result.code).json(result);
25
  let payload = {
26
  _id: result.record?._id, name: result.record?.name,
src/modules/user/{User β†’ users}/routes/auth.route.ts RENAMED
File without changes
src/modules/user/{User/services/user.service.ts β†’ users/services/users.service.ts} RENAMED
@@ -1,15 +1,15 @@
1
- import { UserBaseService } from "../../../common/User/services/user.base.service";
2
- import { userModel, } from "../../../common/User/models/user.model";
3
  import bcrypt from "bcrypt";
4
 
5
- export class userService extends UserBaseService {
6
 
7
  static async comparePassword(email: string, password: string) {
8
  try {
9
  if (email != undefined) {
10
  email = email.toLowerCase();
11
  }
12
- let result = await UserBaseService.find({ email })
13
  if (!result.success) return result;
14
 
15
  let match = await bcrypt.compare(password, result.record.password)
 
1
+ import { UsersBaseService } from "../../../common/users/services/users.base.service";
2
+ import { userModel, } from "../../../common/users/models/user.model";
3
  import bcrypt from "bcrypt";
4
 
5
+ export class usersService extends UsersBaseService {
6
 
7
  static async comparePassword(email: string, password: string) {
8
  try {
9
  if (email != undefined) {
10
  email = email.toLowerCase();
11
  }
12
+ let result = await UsersBaseService.find({ email })
13
  if (!result.success) return result;
14
 
15
  let match = await bcrypt.compare(password, result.record.password)
src/modules/user/{User β†’ users}/validation/user.Validation.ts RENAMED
@@ -1,5 +1,5 @@
1
  import joi from 'joi';
2
- import { userBaseValidation } from '../../../common/User/validation/user.baseValidation';
3
 
4
  export class userValidation extends userBaseValidation {
5
  static loginValidation = {
 
1
  import joi from 'joi';
2
+ import { userBaseValidation } from '../../../common/users/validation/user.baseValidation';
3
 
4
  export class userValidation extends userBaseValidation {
5
  static loginValidation = {