create-myexam-app 1.0.25 → 1.0.27

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.
Files changed (152) hide show
  1. package/index.js +29 -28
  2. package/package.json +1 -1
  3. package/projects/EPMS/backend/.env +1 -1
  4. package/projects/EPMS/backend/config/db.js +1 -1
  5. package/projects/EPMS/backend/controllers/authController.js +1 -1
  6. package/projects/EPMS/backend/middleware/auth.js +2 -6
  7. package/projects/EPMS/backend/server.js +2 -1
  8. package/projects/Elysee File/# Full-Stack [SUBJECT] Management (edited).txt +214 -0
  9. package/projects/SCMS/backend/.env +1 -1
  10. package/projects/SCMS/backend/config/db.js +1 -1
  11. package/projects/SCMS/backend/controllers/authController.js +1 -1
  12. package/projects/SCMS/backend/middleware/auth.js +2 -6
  13. package/projects/SCMS/backend/server.js +3 -7
  14. package/projects/SCMS/frontend/src/App.jsx +1 -2
  15. package/projects/SMS/backend-project/config/db.js +12 -0
  16. package/projects/SMS/backend-project/controllers/authController.js +90 -0
  17. package/projects/{SCMS/backend → SMS/backend-project}/controllers/productController.js +27 -26
  18. package/projects/SMS/backend-project/controllers/reportController.js +63 -0
  19. package/projects/SMS/backend-project/controllers/salesController.js +124 -0
  20. package/projects/SMS/backend-project/controllers/supplierController.js +66 -0
  21. package/projects/SMS/backend-project/controllers/warehouseController.js +56 -0
  22. package/projects/SMS/backend-project/middleware/auth.js +32 -0
  23. package/projects/SMS/backend-project/models/StockTransaction.js +32 -0
  24. package/projects/SMS/backend-project/models/User.js +28 -0
  25. package/projects/SMS/backend-project/models/Warehouse.js +24 -0
  26. package/projects/{SCMS/backend → SMS/backend-project}/models/product.js +16 -16
  27. package/projects/SMS/backend-project/models/supplier.js +25 -0
  28. package/projects/{SMS- → SMS}/backend-project/package-lock.json +2190 -1568
  29. package/projects/SMS/backend-project/package.json +23 -0
  30. package/projects/SMS/backend-project/routes/SupplierRoutes.js +15 -0
  31. package/projects/SMS/backend-project/routes/authRoutes.js +11 -0
  32. package/projects/SMS/backend-project/routes/protectedRoutes.js +18 -0
  33. package/projects/SMS/backend-project/routes/reportRoutes.js +9 -0
  34. package/projects/SMS/backend-project/routes/salesRoutes.js +14 -0
  35. package/projects/SMS/backend-project/routes/warehouseRoutes.js +20 -0
  36. package/projects/SMS/backend-project/server.js +33 -0
  37. package/projects/{SMS- → SMS}/frontend-project/index.html +1 -1
  38. package/projects/{SMS- → SMS}/frontend-project/package-lock.json +19 -19
  39. package/projects/{SMS- → SMS}/frontend-project/package.json +2 -2
  40. package/projects/SMS/frontend-project/src/App.jsx +61 -0
  41. package/projects/SMS/frontend-project/src/components/AppLayout.jsx +97 -0
  42. package/projects/SMS/frontend-project/src/components/Dashboard.jsx +34 -0
  43. package/projects/SMS/frontend-project/src/components/ProtectedRoute.jsx +13 -0
  44. package/projects/SMS/frontend-project/src/index.css +47 -0
  45. package/projects/SMS/frontend-project/src/pages/Login.jsx +81 -0
  46. package/projects/SMS/frontend-project/src/pages/Product.jsx +122 -0
  47. package/projects/SMS/frontend-project/src/pages/Profile.jsx +64 -0
  48. package/projects/SMS/frontend-project/src/pages/Register.jsx +110 -0
  49. package/projects/SMS/frontend-project/src/pages/Reports.jsx +88 -0
  50. package/projects/SMS/frontend-project/src/pages/Sales.jsx +224 -0
  51. package/projects/SMS/frontend-project/src/pages/Warehouse.jsx +82 -0
  52. package/projects/{SMS- → SMS}/frontend-project/vite.config.js +1 -4
  53. package/projects/SRMS/backend/.env +3 -3
  54. package/projects/SRMS/backend/config/db.js +12 -0
  55. package/projects/SRMS/backend/controllers/authController.js +90 -0
  56. package/projects/SRMS/backend/controllers/customerController.js +45 -0
  57. package/projects/SRMS/backend/controllers/productController.js +44 -0
  58. package/projects/SRMS/backend/controllers/reportsController.js +44 -0
  59. package/projects/SRMS/backend/controllers/salesController.js +88 -0
  60. package/projects/SRMS/backend/middleware/auth.js +24 -13
  61. package/projects/SRMS/backend/models/User.js +26 -6
  62. package/projects/SRMS/backend/models/customer.js +36 -0
  63. package/projects/SRMS/backend/models/product.js +30 -0
  64. package/projects/SRMS/backend/models/sales.js +44 -0
  65. package/projects/SRMS/backend/package-lock.json +2190 -1568
  66. package/projects/SRMS/backend/package.json +23 -23
  67. package/projects/SRMS/backend/routes/authRoutes.js +11 -0
  68. package/projects/SRMS/backend/routes/customerRoutes.js +12 -0
  69. package/projects/SRMS/backend/routes/productRoutes.js +12 -0
  70. package/projects/SRMS/backend/routes/reportsRoutes.js +10 -0
  71. package/projects/SRMS/backend/routes/salesRoutes.js +15 -0
  72. package/projects/SRMS/backend/server.js +22 -17
  73. package/projects/SRMS/frontend/index.html +1 -1
  74. package/projects/SRMS/frontend/package-lock.json +24 -24
  75. package/projects/SRMS/frontend/package.json +1 -1
  76. package/projects/SRMS/frontend/src/App.jsx +27 -32
  77. package/projects/SRMS/frontend/src/components/Dashboard.jsx +32 -0
  78. package/projects/SRMS/frontend/src/components/Layout.jsx +104 -0
  79. package/projects/SRMS/frontend/src/index.css +57 -1
  80. package/projects/SRMS/frontend/src/pages/Customer.jsx +127 -104
  81. package/projects/SRMS/frontend/src/pages/Login.jsx +76 -52
  82. package/projects/SRMS/frontend/src/pages/Product.jsx +116 -95
  83. package/projects/SRMS/frontend/src/pages/Profile.jsx +69 -0
  84. package/projects/SRMS/frontend/src/pages/Register.jsx +111 -56
  85. package/projects/SRMS/frontend/src/pages/Reports.jsx +72 -229
  86. package/projects/SRMS/frontend/src/pages/Sales.jsx +269 -0
  87. package/projects/SRMS/frontend/vite.config.js +1 -4
  88. package/projects/sims/backend/middleware/auth.js +1 -5
  89. package/projects/user/Seed.js +29 -0
  90. package/projects/{SMS-/backend-project/middlware → user}/auth.js +2 -1
  91. package/projects/{SRMS/frontend/App.jsx → user/h.jsx} +1 -1
  92. package/projects/SCMS/backend/routes/protectedRoutes.js +0 -10
  93. package/projects/SCMS/frontend/src/components/ProtectedRoute.jsx +0 -30
  94. package/projects/SMS-/backend-project/.env +0 -3
  95. package/projects/SMS-/backend-project/controllers/ProductController.js +0 -19
  96. package/projects/SMS-/backend-project/controllers/StockTransactionController.js +0 -46
  97. package/projects/SMS-/backend-project/controllers/UserController.js +0 -35
  98. package/projects/SMS-/backend-project/controllers/WarehouseController.js +0 -19
  99. package/projects/SMS-/backend-project/db/connectDB.js +0 -11
  100. package/projects/SMS-/backend-project/models/Product.js +0 -13
  101. package/projects/SMS-/backend-project/models/StockTransaction.js +0 -9
  102. package/projects/SMS-/backend-project/models/User.js +0 -8
  103. package/projects/SMS-/backend-project/models/Warehouse.js +0 -9
  104. package/projects/SMS-/backend-project/package.json +0 -23
  105. package/projects/SMS-/backend-project/routes/ProductRoutes.js +0 -11
  106. package/projects/SMS-/backend-project/routes/StockTransactionRoutes.js +0 -14
  107. package/projects/SMS-/backend-project/routes/UserRoutes.js +0 -10
  108. package/projects/SMS-/backend-project/routes/WarehouseRoutes.js +0 -10
  109. package/projects/SMS-/backend-project/server.js +0 -24
  110. package/projects/SMS-/frontend-project/public/icons.svg +0 -24
  111. package/projects/SMS-/frontend-project/src/App.css +0 -184
  112. package/projects/SMS-/frontend-project/src/App.jsx +0 -41
  113. package/projects/SMS-/frontend-project/src/assets/hero.png +0 -0
  114. package/projects/SMS-/frontend-project/src/assets/react.svg +0 -1
  115. package/projects/SMS-/frontend-project/src/assets/vite.svg +0 -1
  116. package/projects/SMS-/frontend-project/src/components/Navbar.jsx +0 -37
  117. package/projects/SMS-/frontend-project/src/index.css +0 -1
  118. package/projects/SMS-/frontend-project/src/pages/Dashboard.jsx +0 -31
  119. package/projects/SMS-/frontend-project/src/pages/Login.jsx +0 -79
  120. package/projects/SMS-/frontend-project/src/pages/Product.jsx +0 -135
  121. package/projects/SMS-/frontend-project/src/pages/Register.jsx +0 -72
  122. package/projects/SMS-/frontend-project/src/pages/Reports.jsx +0 -302
  123. package/projects/SMS-/frontend-project/src/pages/StockTransaction.jsx +0 -185
  124. package/projects/SMS-/frontend-project/src/pages/Warehouse.jsx +0 -125
  125. package/projects/SRMS/backend/controllers/CustomerControllers.js +0 -29
  126. package/projects/SRMS/backend/controllers/ProductControllers.js +0 -31
  127. package/projects/SRMS/backend/controllers/SaleControllers.js +0 -49
  128. package/projects/SRMS/backend/controllers/UserControllers.js +0 -40
  129. package/projects/SRMS/backend/db/connectDB.js +0 -11
  130. package/projects/SRMS/backend/models/Customer.js +0 -13
  131. package/projects/SRMS/backend/models/Product.js +0 -9
  132. package/projects/SRMS/backend/models/Sale.js +0 -12
  133. package/projects/SRMS/backend/routes/CustomerRoutes.js +0 -11
  134. package/projects/SRMS/backend/routes/ProductRoutes.js +0 -11
  135. package/projects/SRMS/backend/routes/SaleRoutes.js +0 -13
  136. package/projects/SRMS/backend/routes/UserRoutes.js +0 -11
  137. package/projects/SRMS/frontend/README.md +0 -16
  138. package/projects/SRMS/frontend/public/icons.svg +0 -24
  139. package/projects/SRMS/frontend/src/App.css +0 -184
  140. package/projects/SRMS/frontend/src/assets/hero.png +0 -0
  141. package/projects/SRMS/frontend/src/assets/react.svg +0 -1
  142. package/projects/SRMS/frontend/src/assets/vite.svg +0 -1
  143. package/projects/SRMS/frontend/src/axiosInstance.js +0 -11
  144. package/projects/SRMS/frontend/src/components/Navbar.jsx +0 -30
  145. package/projects/SRMS/frontend/src/pages/Dashboard.jsx +0 -31
  146. package/projects/SRMS/frontend/src/pages/Sale.jsx +0 -228
  147. /package/projects/{SCMS/backend → SMS/backend-project}/routes/productRoutes.js +0 -0
  148. /package/projects/{SMS- → SMS}/frontend-project/README.md +0 -0
  149. /package/projects/{SMS- → SMS}/frontend-project/eslint.config.js +0 -0
  150. /package/projects/{SMS- → SMS}/frontend-project/public/favicon.svg +0 -0
  151. /package/projects/{SMS- → SMS}/frontend-project/src/main.jsx +0 -0
  152. /package/projects/{SMS-/frontend-project/src → user}/axiosInstance.js +0 -0
package/index.js CHANGED
@@ -10,41 +10,42 @@ const rl = readline.createInterface({
10
10
  output: process.stdout
11
11
  })
12
12
  console.log('\n[1] Car Repair Parking Managemnt System')
13
- console.log('[2]Employee Payroll Management System')
14
- console.log('[3]Employee Payroll Management System Elysee')
15
- console.log('[4]middleware')
16
- console.log('[5] Parking Management System')
17
- console.log('[6]Supply Chain Managemnt System')
18
- console.log('[7]Supply Chain Management System Elysee')
19
- console.log('[8] School fee Management System')
20
- console.log('[9]Stock Hub Management System')
21
- console.log('[10]Stock Invetory Management System')
22
- console.log('[11]Stock Management System')
23
- console.log('[12]Sales Record Management System')
24
- console.log('[13]Sales Record Management System Elysee')
25
- console.log('[14]userController.js')
13
+ console.log('[2]Elysee File Prompt')
14
+ console.log('[3]Employee Payroll Management System')
15
+ console.log('[4]Employee Payroll Management System Elysee')
16
+ console.log('[5]middleware')
17
+ console.log('[6] Parking Management System')
18
+ console.log('[7]Supply Chain Managemnt System')
19
+ console.log('[8]Supply Chain Management System Elysee')
20
+ console.log('[9] School fee Management System')
21
+ console.log('[10]Stock Hub Management System')
22
+ console.log('[11]Stock Invetory Management System')
23
+ console.log('[12]Stock Management System')
24
+ console.log('[13]Sales Record Management System')
25
+ console.log('[14]Sales Record Management System Elysee')
26
+ console.log('[15]userController.js')
26
27
 
27
28
 
28
29
 
29
30
 
30
- rl.question('Pick (1-14): ', (answer) => {
31
+ rl.question('Pick (1-15): ', (answer) => {
31
32
 
32
33
  const projects = {
33
34
  '1':'crpms',
34
- '2':'EPMS',
35
- '3':'EPMS(Ely)',
36
- '4':'middleware',
37
- '5': 'parking managementt system',
38
- '6':'SCMS',
39
-
40
- '7':'SCMS(Ely)',
41
- '8': 'sfms-app',
42
- '9':'SHMS(Ely)',
43
- '10':'sims',
44
- '11': 'SMS-',
45
- '12':'SRMS',
46
- '13':'SRMS(Ely)',
47
- '14':'user',
35
+ '2':'Elysee File',
36
+ '3':'EPMS',
37
+ '4':'EPMS(Ely)',
38
+ '5':'middleware',
39
+ '6': 'parking managementt system',
40
+ '7':'SCMS',
41
+ '8':'SCMS(Ely)',
42
+ '9': 'sfms-app',
43
+ '10':'SHMS(Ely)',
44
+ '11':'sims',
45
+ '12': 'SMS',
46
+ '13':'SRMS',
47
+ '14':'SRMS(Ely)',
48
+ '15':'user',
48
49
 
49
50
 
50
51
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "name": "create-myexam-app",
4
4
 
5
- "version": "1.0.25",
5
+ "version": "1.0.27",
6
6
 
7
7
  "description": "My exam projects",
8
8
 
@@ -1,4 +1,4 @@
1
- PORT=5000
1
+ PORT=5001
2
2
 
3
3
  MONGO_URI=mongodb://localhost:27017/EPMS
4
4
 
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
2
2
 
3
3
  const connectDB = async () => {
4
4
  try {
5
- await mongoose.connect('mongodb://localhost:27017/EPMS');
5
+ await mongoose.connect(process.env.MONGO_URI);
6
6
  console.log('MongoDB connected');
7
7
  } catch (error) {
8
8
  console.error('MongoDB connection error:', error);
@@ -1,7 +1,7 @@
1
1
  const bcrypt = require('bcrypt');
2
2
  const jwt = require('jsonwebtoken');
3
3
  const User = require('../models/User');
4
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
4
+ const JWT_SECRET = process.env.JWT_SECRET;
5
5
 
6
6
 
7
7
 
@@ -1,12 +1,8 @@
1
- // this middleware is helping us to protect our routes so that only authenticated users can access the routes
2
- //it is checking if the user is authenticated by checking the token in the header(the header is the part of the request that contains the token)
3
- //if the user is not authenticated, it will return a 401 status code and a message that the user is not authorized
4
- //if the user is authenticated, it will return the user object
5
- //and the user object is the user that is authenticated
1
+
6
2
 
7
3
  const jwt = require('jsonwebtoken');
8
4
  const User = require('../models/User');
9
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
5
+ const JWT_SECRET = process.env.JWT_SECRET;
10
6
 
11
7
  exports.protect = async (req, res, next) => {
12
8
  try {
@@ -1,3 +1,4 @@
1
+ require('dotenv').config();
1
2
  const express = require('express');
2
3
  const cors = require('cors');
3
4
 
@@ -21,7 +22,7 @@ app.use('/api/employees', employeeRoutes);
21
22
  app.use('/api/salaries', salaryRoutes);
22
23
  app.use('/api/protected', protectedRoutes);
23
24
 
24
- const PORT = 5001;
25
+ const PORT = process.env.PORT || 5001
25
26
  app.listen(PORT, () => {
26
27
  console.log(`Server running on http://localhost:${PORT}`);
27
28
  });
@@ -0,0 +1,214 @@
1
+ # OPENCODE EXECUTION RULES
2
+
3
+ IMPORTANT
4
+
5
+ Follow the original project specification exactly as provided.
6
+
7
+ Do not remove, simplify, replace, or ignore any requirement from the original specification.
8
+
9
+ These instructions are additional rules that must be followed during project generation.
10
+
11
+ ---
12
+
13
+ ## STRICT IMPLEMENTATION POLICY
14
+
15
+ * Follow the specification exactly.
16
+ * Do not invent new business requirements.
17
+ * Do not add features that are not requested.
18
+ * Only add improvements listed in the "Project Improvements" section below.
19
+ * If any requirement is unclear, ask before implementing.
20
+ * Avoid introducing additional frameworks, libraries, architectures, or technologies that were not requested.
21
+ * Keep the project maintainable, professional, and suitable for academic practical examination purposes.
22
+
23
+ ---
24
+
25
+ ## ISOLATED DEVELOPMENT WORKSPACE
26
+
27
+ Create a dedicated workspace named:
28
+
29
+ .cache
30
+
31
+ This workspace will be used for all generated code, planning, temporary files, logs, documentation, and experimentation.
32
+
33
+ All generated content must remain inside:
34
+
35
+ .cache/
36
+
37
+ Example structure:
38
+
39
+ .cache/
40
+ ├── backend-project/
41
+ ├── frontend-project/
42
+ ├── docs/
43
+ ├── logs/
44
+ ├── temp/
45
+ ├── PROJECT_SUMMARY.md
46
+ └── SETUP.md
47
+
48
+ Never generate project files outside this workspace.
49
+
50
+ ---
51
+
52
+ ## WORKSPACE ALIAS SYSTEM
53
+
54
+ The user may use navigation aliases.
55
+
56
+ Alias Mapping:
57
+
58
+ 1 = Main Project Workspace
59
+
60
+ 10 = .cache Workspace
61
+
62
+ These aliases are navigation shortcuts only.
63
+
64
+ Do NOT create actual folders named:
65
+
66
+ * 1
67
+ * 10
68
+ * project10
69
+ * generated10
70
+
71
+ The actual folder name must remain:
72
+
73
+ .cache
74
+
75
+ Examples:
76
+
77
+ * "Open 1 controllers" → Open controllers in the main project.
78
+ * "Open 10 routes" → Open routes inside .cache.
79
+ * "Add controller in 10" → Create or modify files only inside .cache.
80
+ * "Return to 1" → Return to the main project.
81
+
82
+ ---
83
+
84
+ ## PROJECT GENERATION
85
+
86
+ Generate the complete full-stack application described in the original specification.
87
+
88
+ Generate all required:
89
+
90
+ * Backend files
91
+ * Frontend files
92
+ * Models
93
+ * Controllers
94
+ * Routes
95
+ * Middleware
96
+ * Authentication
97
+ * Dashboard
98
+ * Reports
99
+ * Styling
100
+ * Configuration
101
+ * Documentation
102
+
103
+ Do not skip required components.
104
+
105
+ Do not leave placeholders where implementation is expected.
106
+
107
+ ---
108
+
109
+ ## PROJECT IMPROVEMENTS
110
+
111
+ While preserving the original specification, include the following improvements:
112
+
113
+ * createdAt timestamps
114
+ * updatedAt timestamps
115
+ * reusable validation helpers
116
+ * reusable utility modules
117
+ * centralized API error handling
118
+ * activity logging
119
+ * search functionality
120
+ * filtering functionality
121
+ * loading states
122
+ * error states
123
+ * role support for users
124
+
125
+ Invoice numbering must be generated automatically.
126
+
127
+ Format:
128
+
129
+ INV-YYYY-0001
130
+
131
+ Examples:
132
+
133
+ INV-2026-0001
134
+
135
+ INV-2026-0002
136
+
137
+ INV-2026-0003
138
+
139
+ ---
140
+
141
+ ## SAFETY RULES
142
+
143
+ Workspace 1 (Main Project) is protected.
144
+
145
+ Never:
146
+
147
+ * Modify files in Workspace 1.
148
+ * Delete files in Workspace 1.
149
+ * Rename files in Workspace 1.
150
+ * Move files in Workspace 1.
151
+ * Install dependencies in Workspace 1.
152
+ * Generate files in Workspace 1.
153
+ * Overwrite user files.
154
+ * Alter the existing project structure.
155
+
156
+ Treat Workspace 1 as read-only.
157
+
158
+ Treat Workspace 10 (.cache) as the active development workspace.
159
+
160
+ ---
161
+
162
+ ## FILE OPERATION VALIDATION
163
+
164
+ Before creating, editing, moving, renaming, or deleting any file:
165
+
166
+ Verify that the target path begins with:
167
+
168
+ .cache/
169
+
170
+ If the target path is outside:
171
+
172
+ .cache/
173
+
174
+ Cancel the operation and notify the user.
175
+
176
+ ---
177
+
178
+ ## COMPLETION REQUIREMENTS
179
+
180
+ When generation is complete:
181
+
182
+ 1. Display the complete generated folder tree.
183
+ 2. Display all generated backend files.
184
+ 3. Display all generated frontend files.
185
+ 4. Display all generated models.
186
+ 5. Display all generated controllers.
187
+ 6. Display all generated routes.
188
+ 7. Generate PROJECT_SUMMARY.md.
189
+ 8. Generate SETUP.md.
190
+ 9. Show required environment variables.
191
+ 10. Show startup commands.
192
+ 11. Show the exact location of the generated project.
193
+
194
+ ---
195
+
196
+ ## FINAL BEHAVIOR
197
+
198
+ Work only inside:
199
+
200
+ .cache
201
+
202
+ Do not start servers automatically.
203
+
204
+ Do not run npm install automatically.
205
+
206
+ Do not modify the user's existing implementation.
207
+
208
+ Do not merge generated files into the main project.
209
+
210
+ Do not copy generated files into the main project automatically.
211
+
212
+ Wait for user approval before performing any action outside .cache.
213
+
214
+ All generated artifacts, documentation, logs, helper files, temporary files, and project resources must remain isolated inside .cache until the user explicitly decides otherwise.
@@ -1,4 +1,4 @@
1
- PORT=5000
1
+ PORT = 5001
2
2
 
3
3
  MONGO_URI=mongodb://localhost:27017/SCMS
4
4
 
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
2
2
 
3
3
  const connectDB = async () => {
4
4
  try {
5
- await mongoose.connect('mongodb://localhost:27017/SCMS');
5
+ await mongoose.connect(process.env.MONGO_URI);
6
6
  console.log('MongoDB connected');
7
7
  } catch (error) {
8
8
  console.error('MongoDB connection error:', error);
@@ -1,7 +1,7 @@
1
1
  const bcrypt = require('bcrypt');
2
2
  const jwt = require('jsonwebtoken');
3
3
  const User = require('../models/User');
4
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
4
+ const JWT_SECRET =process.env.JWT_SECRET;
5
5
 
6
6
 
7
7
 
@@ -1,12 +1,8 @@
1
- // this middleware is helping us to protect our routes so that only authenticated users can access the routes
2
- //it is checking if the user is authenticated by checking the token in the header(the header is the part of the request that contains the token)
3
- //if the user is not authenticated, it will return a 401 status code and a message that the user is not authorized
4
- //if the user is authenticated, it will return the user object
5
- //and the user object is the user that is authenticated
1
+
6
2
 
7
3
  const jwt = require('jsonwebtoken');
8
4
  const User = require('../models/User');
9
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
5
+ const JWT_SECRET = process.env.JWT_SECRET;
10
6
 
11
7
  exports.protect = async (req, res, next) => {
12
8
  try {
@@ -1,16 +1,14 @@
1
+ require ('dotenv'). config();
1
2
  const express = require('express');
2
3
  const cors = require('cors');
3
4
 
4
5
  const connectDB = require('./config/db');
5
6
 
6
7
  const authRoutes = require('./routes/authRoutes');
7
-
8
- const productRoutes = require('./routes/productRoutes');
9
8
  const SupplierRoutes = require('./routes/SupplierRoutes');
10
9
  const shipmentRoutes = require('./routes/shipmentRoutes');
11
10
  const deliveryRoutes = require('./routes/deliveryRoutes');
12
11
  const reportsRoutes = require('./routes/reportsRoutes');
13
- const protectedRoutes = require('./routes/protectedRoutes');
14
12
 
15
13
  const app = express();
16
14
 
@@ -18,16 +16,14 @@ app.use(cors());
18
16
  app.use(express.json());
19
17
  connectDB();
20
18
 
21
- app.use('/api/product', productRoutes);
19
+
22
20
  app.use('/api/supplier', SupplierRoutes);
23
21
  app.use('/api/auth', authRoutes);
24
-
25
22
  app.use('/api/shipment', shipmentRoutes);
26
23
  app.use('/api/delivery', deliveryRoutes);
27
24
  app.use('/api/reports', reportsRoutes);
28
- app.use('/api/protected', protectedRoutes);
29
25
 
30
- const PORT = 5001;
26
+ const PORT = process.env.PORT || 5001
31
27
  app.listen(PORT, () => {
32
28
  console.log(`Server running on http://localhost:${PORT}`);
33
29
  });
@@ -8,7 +8,6 @@ import Supplier from './pages/Supplier';
8
8
  import Shipment from './pages/Shipment';
9
9
  import Delivery from './pages/Delivery';
10
10
  import Reports from './pages/Reports';
11
- import ProtectedRoute from './components/ProtectedRoute';
12
11
 
13
12
  function App() {
14
13
  return (
@@ -17,7 +16,7 @@ function App() {
17
16
  <Route path="/login" element={<Login />} />
18
17
  <Route path="/register" element={<Register />} />
19
18
 
20
- <Route path="/dashboard" element={<ProtectedRoute><DashboardLayout /></ProtectedRoute>}>
19
+ <Route path="/dashboard" element={<DashboardLayout />}>
21
20
  <Route index element={<DashboardHome />} />
22
21
  <Route path="supplier" element={<Supplier />} />
23
22
  <Route path="shipment" element={<Shipment />} />
@@ -0,0 +1,12 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const connectDB = async () => {
4
+ try {
5
+ await mongoose.connect('mongodb://localhost:27017/SMS');
6
+ console.log('MongoDB connected');
7
+ } catch (error) {
8
+ console.error('MongoDB connection error:', error);
9
+ }
10
+ };
11
+
12
+ module.exports = connectDB;
@@ -0,0 +1,90 @@
1
+ const bcrypt = require('bcrypt');
2
+ const jwt = require('jsonwebtoken');
3
+ const User = require('../models/User');
4
+ const JWT_SECRET = 'change_this_to_a_long_random_secret';
5
+
6
+
7
+
8
+ function createToken(userId) {
9
+ return jwt.sign({ userId },JWT_SECRET, { expiresIn: '7d' });
10
+ }
11
+
12
+ function formatUser(user) {
13
+ return {
14
+ id: user._id,
15
+ name: user.name,
16
+ email: user.email,
17
+ };
18
+ }
19
+
20
+ exports.register = async (req, res) => {
21
+ try {
22
+ const { name, email, password } = req.body;
23
+
24
+ if (!name || !email || !password) {
25
+ return res.status(400).json({ message: 'Name, email, and password are required' });
26
+ }
27
+
28
+ if (password.length < 6) {
29
+ return res.status(400).json({ message: 'Password must be at least 6 characters' });
30
+ }
31
+
32
+ const existing = await User.findOne({ email: email.toLowerCase() });
33
+ if (existing) {
34
+ return res.status(409).json({ message: 'Email already registered' });
35
+ }
36
+
37
+ const hashedPassword = await bcrypt.hash(password, 10);
38
+ const user = await User.create({
39
+ name,
40
+ email: email.toLowerCase(),//to ensure the email is always lowercase
41
+ password: hashedPassword,
42
+ });
43
+
44
+ const token = createToken(user._id);
45
+
46
+ res.status(201).json({
47
+ token,
48
+ user: formatUser(user),
49
+ });
50
+ } catch (err) {
51
+ res.status(500).json({ message: err.message });
52
+ }
53
+ }
54
+
55
+ exports.login = async (req, res) => {
56
+ try {
57
+ const { email, password } = req.body;
58
+
59
+ if (!email || !password) {
60
+ return res.status(400).json({ message: 'Email and password are required' });
61
+ }
62
+
63
+ const user = await User.findOne({ email: email.toLowerCase() });
64
+ if (!user) {
65
+ return res.status(401).json({ message: 'Invalid email or password' });
66
+ }
67
+
68
+ const match = await bcrypt.compare(password, user.password);
69
+ if (!match) {
70
+ return res.status(401).json({ message: 'Invalid email or password' });
71
+ }
72
+
73
+ const token = createToken(user._id);
74
+
75
+ res.json({
76
+ token,
77
+ user: formatUser(user),
78
+ });
79
+ } catch (err) {
80
+ res.status(500).json({ message: err.message });
81
+ }
82
+ }
83
+
84
+ exports.getMe = async (req, res) => {
85
+ try {
86
+ res.json({ user: formatUser(req.user) });
87
+ } catch (err) {
88
+ res.status(500).json({ message: err.message });
89
+ }
90
+ };
@@ -1,21 +1,17 @@
1
- const Product = require('../models/Product');
2
-
1
+ const Product = require('../models/product');
3
2
 
4
3
  exports.getproduct = async (req, res) => {
5
4
  try {
6
- const products = await Product.find().populate('Supplier');
7
- if (!products) {
8
- return res.status(404).json({ message: 'Products not found' });
9
- }
5
+ const products = await Product.find();
10
6
  res.json(products);
11
7
  } catch (err) {
12
8
  res.status(500).json({ message: err.message });
13
9
  }
14
- }
10
+ };
15
11
 
16
12
  exports.getproductbyid = async (req, res) => {
17
13
  try {
18
- const productById = await Product.findById(req.params.id).populate('Supplier');
14
+ const productById = await Product.findById(req.params.id);
19
15
  if (!productById) {
20
16
  return res.status(404).json({ message: 'Product not found' });
21
17
  }
@@ -27,48 +23,53 @@ exports.getproductbyid = async (req, res) => {
27
23
 
28
24
  exports.addproduct = async (req, res) => {
29
25
  try {
30
- const { productCode, productName, category, unitPrice, quantity, expiryDate } = req.body
26
+ const {
27
+ productCode,
28
+ productName,
29
+ category,
30
+ unitPrice,
31
+ quantityInStock,
32
+ supplierName,
33
+ dateReceived,
34
+ } = req.body;
35
+
31
36
  const newproduct = await Product.create({
32
37
  productCode,
33
38
  productName,
34
39
  category,
35
40
  unitPrice,
36
- quantity,
37
- expiryDate,
38
- Supplier: req.user._id
41
+ quantityInStock,
42
+ supplierName,
43
+ dateReceived,
39
44
  });
40
45
 
41
46
  res.status(201).json(newproduct);
42
47
  } catch (err) {
43
48
  res.status(500).json({ message: err.message });
44
49
  }
45
- }
50
+ };
46
51
 
47
52
  exports.updateproduct = async (req, res) => {
48
53
  try {
49
- const updateproducts = await Product.findByIdAndUpdate(
50
- req.params.id,
51
- req.body,
52
- { new: true }
53
- );
54
- if (!updateproducts) return res.status(404).json({ msg: " product not found" })
54
+ const updateproducts = await Product.findByIdAndUpdate(req.params.id, req.body, {
55
+ new: true,
56
+ });
57
+ if (!updateproducts) return res.status(404).json({ msg: 'Product not found' });
55
58
 
56
- res.json({ msg: "Products updated Syccessfully", data: updateproducts });
59
+ res.json({ msg: 'Product updated successfully', data: updateproducts });
57
60
  } catch (err) {
58
61
  res.status(500).json({ message: err.message });
59
62
  }
60
- }
63
+ };
61
64
 
62
65
  exports.deleteproduct = async (req, res) => {
63
66
  try {
64
- const deleteproduct = await Product.findByIdAndDelete(
65
- req.params.id
66
- );
67
+ const deleteproduct = await Product.findByIdAndDelete(req.params.id);
67
68
  if (!deleteproduct) {
68
- return res.status(404).json({ message: 'product not found' });
69
+ return res.status(404).json({ message: 'Product not found' });
69
70
  }
70
71
  res.json({ message: 'Product deleted successfully' });
71
72
  } catch (err) {
72
73
  res.status(500).json({ message: err.message });
73
74
  }
74
- }
75
+ };