create-ishvexa-app 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/index.js +62 -0
- package/package.json +14 -0
- package/templates/epms-app/.env +7 -0
- package/templates/epms-app/README.md +113 -0
- package/templates/epms-app/backend-mongodb/.env +3 -0
- package/templates/epms-app/backend-mongodb/.env.example +3 -0
- package/templates/epms-app/backend-mongodb/config/db.js +29 -0
- package/templates/epms-app/backend-mongodb/controllers/authController.js +93 -0
- package/templates/epms-app/backend-mongodb/controllers/departmentController.js +24 -0
- package/templates/epms-app/backend-mongodb/controllers/employeeController.js +39 -0
- package/templates/epms-app/backend-mongodb/controllers/reportController.js +57 -0
- package/templates/epms-app/backend-mongodb/controllers/salaryController.js +101 -0
- package/templates/epms-app/backend-mongodb/middleware/auth.js +16 -0
- package/templates/epms-app/backend-mongodb/models/Counter.js +13 -0
- package/templates/epms-app/backend-mongodb/models/Department.js +11 -0
- package/templates/epms-app/backend-mongodb/models/Employee.js +18 -0
- package/templates/epms-app/backend-mongodb/models/Salary.js +19 -0
- package/templates/epms-app/backend-mongodb/models/User.js +9 -0
- package/templates/epms-app/backend-mongodb/package-lock.json +1571 -0
- package/templates/epms-app/backend-mongodb/package.json +22 -0
- package/templates/epms-app/backend-mongodb/routes/authRoutes.js +8 -0
- package/templates/epms-app/backend-mongodb/routes/departmentRoutes.js +6 -0
- package/templates/epms-app/backend-mongodb/routes/employeeRoutes.js +6 -0
- package/templates/epms-app/backend-mongodb/routes/reportRoutes.js +5 -0
- package/templates/epms-app/backend-mongodb/routes/salaryRoutes.js +8 -0
- package/templates/epms-app/backend-mongodb/server.js +39 -0
- package/templates/epms-app/backend-mysql/.env +7 -0
- package/templates/epms-app/backend-mysql/.env.example +7 -0
- package/templates/epms-app/backend-mysql/config/db.js +33 -0
- package/templates/epms-app/backend-mysql/controllers/authController.js +98 -0
- package/templates/epms-app/backend-mysql/controllers/departmentController.js +25 -0
- package/templates/epms-app/backend-mysql/controllers/employeeController.js +39 -0
- package/templates/epms-app/backend-mysql/controllers/reportController.js +41 -0
- package/templates/epms-app/backend-mysql/controllers/salaryController.js +93 -0
- package/templates/epms-app/backend-mysql/database/schema.sql +7 -0
- package/templates/epms-app/backend-mysql/middleware/auth.js +16 -0
- package/templates/epms-app/backend-mysql/package-lock.json +1486 -0
- package/templates/epms-app/backend-mysql/package.json +23 -0
- package/templates/epms-app/backend-mysql/routes/authRoutes.js +8 -0
- package/templates/epms-app/backend-mysql/routes/departmentRoutes.js +6 -0
- package/templates/epms-app/backend-mysql/routes/employeeRoutes.js +6 -0
- package/templates/epms-app/backend-mysql/routes/reportRoutes.js +5 -0
- package/templates/epms-app/backend-mysql/routes/salaryRoutes.js +8 -0
- package/templates/epms-app/backend-mysql/server.js +39 -0
- package/templates/epms-app/frontend/README.md +16 -0
- package/templates/epms-app/frontend/eslint.config.js +21 -0
- package/templates/epms-app/frontend/index.html +12 -0
- package/templates/epms-app/frontend/package-lock.json +3033 -0
- package/templates/epms-app/frontend/package.json +23 -0
- package/templates/epms-app/frontend/public/favicon.svg +1 -0
- package/templates/epms-app/frontend/public/icons.svg +24 -0
- package/templates/epms-app/frontend/src/App.css +184 -0
- package/templates/epms-app/frontend/src/App.jsx +31 -0
- package/templates/epms-app/frontend/src/api/authApi.js +7 -0
- package/templates/epms-app/frontend/src/api/client.js +11 -0
- package/templates/epms-app/frontend/src/api/departmentApi.js +5 -0
- package/templates/epms-app/frontend/src/api/employeeApi.js +4 -0
- package/templates/epms-app/frontend/src/api/reportApi.js +4 -0
- package/templates/epms-app/frontend/src/api/salaryApi.js +6 -0
- package/templates/epms-app/frontend/src/api/sparePartsApi.js +3 -0
- package/templates/epms-app/frontend/src/api/usersApi.js +4 -0
- package/templates/epms-app/frontend/src/assets/hero.png +0 -0
- package/templates/epms-app/frontend/src/assets/react.svg +1 -0
- package/templates/epms-app/frontend/src/assets/vite.svg +1 -0
- package/templates/epms-app/frontend/src/components/AppLayout.jsx +49 -0
- package/templates/epms-app/frontend/src/context/AuthContext.jsx +41 -0
- package/templates/epms-app/frontend/src/hooks/.gitkeep +0 -0
- package/templates/epms-app/frontend/src/index.css +2 -0
- package/templates/epms-app/frontend/src/main.jsx +16 -0
- package/templates/epms-app/frontend/src/pages/DepartmentPage.jsx +165 -0
- package/templates/epms-app/frontend/src/pages/DepartmentsPage.jsx +119 -0
- package/templates/epms-app/frontend/src/pages/EmployeePage.jsx +212 -0
- package/templates/epms-app/frontend/src/pages/EmployeesPage.jsx +217 -0
- package/templates/epms-app/frontend/src/pages/ForgotPassword.jsx +103 -0
- package/templates/epms-app/frontend/src/pages/LoginPage.jsx +105 -0
- package/templates/epms-app/frontend/src/pages/RegisterPage.jsx +84 -0
- package/templates/epms-app/frontend/src/pages/ReportsPage.jsx +192 -0
- package/templates/epms-app/frontend/src/pages/ResetPasswordPage.jsx +83 -0
- package/templates/epms-app/frontend/src/pages/SalariesPage.jsx +274 -0
- package/templates/epms-app/frontend/src/pages/SalaryPage.jsx +254 -0
- package/templates/epms-app/frontend/vite.config.js +8 -0
- package/templates/lms-app/.env +9 -0
- package/templates/lms-app/README.md +89 -0
- package/templates/lms-app/backend-mongodb/.env +5 -0
- package/templates/lms-app/backend-mongodb/.env.example +5 -0
- package/templates/lms-app/backend-mongodb/package-lock.json +1583 -0
- package/templates/lms-app/backend-mongodb/package.json +26 -0
- package/templates/lms-app/backend-mongodb/src/config/db.js +10 -0
- package/templates/lms-app/backend-mongodb/src/config/env.js +28 -0
- package/templates/lms-app/backend-mongodb/src/controllers/authController.js +86 -0
- package/templates/lms-app/backend-mongodb/src/controllers/bookController.js +101 -0
- package/templates/lms-app/backend-mongodb/src/controllers/borrowController.js +106 -0
- package/templates/lms-app/backend-mongodb/src/controllers/dashboardController.js +40 -0
- package/templates/lms-app/backend-mongodb/src/controllers/reportController.js +47 -0
- package/templates/lms-app/backend-mongodb/src/controllers/studentController.js +92 -0
- package/templates/lms-app/backend-mongodb/src/ensureSeedData.js +72 -0
- package/templates/lms-app/backend-mongodb/src/middleware/auth.js +29 -0
- package/templates/lms-app/backend-mongodb/src/models/Book.js +14 -0
- package/templates/lms-app/backend-mongodb/src/models/Borrow.js +16 -0
- package/templates/lms-app/backend-mongodb/src/models/Student.js +14 -0
- package/templates/lms-app/backend-mongodb/src/models/User.js +13 -0
- package/templates/lms-app/backend-mongodb/src/routes/authRoutes.js +12 -0
- package/templates/lms-app/backend-mongodb/src/routes/bookRoutes.js +13 -0
- package/templates/lms-app/backend-mongodb/src/routes/borrowRoutes.js +11 -0
- package/templates/lms-app/backend-mongodb/src/routes/dashboardRoutes.js +9 -0
- package/templates/lms-app/backend-mongodb/src/routes/reportRoutes.js +12 -0
- package/templates/lms-app/backend-mongodb/src/routes/studentRoutes.js +13 -0
- package/templates/lms-app/backend-mongodb/src/seed.js +16 -0
- package/templates/lms-app/backend-mongodb/src/server.js +66 -0
- package/templates/lms-app/backend-mysql/.env +9 -0
- package/templates/lms-app/backend-mysql/.env.example +9 -0
- package/templates/lms-app/backend-mysql/database/schema.sql +45 -0
- package/templates/lms-app/backend-mysql/package-lock.json +1462 -0
- package/templates/lms-app/backend-mysql/package.json +23 -0
- package/templates/lms-app/backend-mysql/src/config/db.js +33 -0
- package/templates/lms-app/backend-mysql/src/config/env.js +21 -0
- package/templates/lms-app/backend-mysql/src/controllers/authController.js +87 -0
- package/templates/lms-app/backend-mysql/src/controllers/bookController.js +106 -0
- package/templates/lms-app/backend-mysql/src/controllers/borrowController.js +113 -0
- package/templates/lms-app/backend-mysql/src/controllers/dashboardController.js +33 -0
- package/templates/lms-app/backend-mysql/src/controllers/reportController.js +40 -0
- package/templates/lms-app/backend-mysql/src/controllers/studentController.js +95 -0
- package/templates/lms-app/backend-mysql/src/ensureSeedData.js +54 -0
- package/templates/lms-app/backend-mysql/src/middleware/auth.js +28 -0
- package/templates/lms-app/backend-mysql/src/routes/authRoutes.js +12 -0
- package/templates/lms-app/backend-mysql/src/routes/bookRoutes.js +13 -0
- package/templates/lms-app/backend-mysql/src/routes/borrowRoutes.js +11 -0
- package/templates/lms-app/backend-mysql/src/routes/dashboardRoutes.js +9 -0
- package/templates/lms-app/backend-mysql/src/routes/reportRoutes.js +12 -0
- package/templates/lms-app/backend-mysql/src/routes/studentRoutes.js +13 -0
- package/templates/lms-app/backend-mysql/src/server.js +69 -0
- package/templates/lms-app/backend-mysql/src/utils/mappers.js +73 -0
- package/templates/lms-app/frontend/.env.example +5 -0
- package/templates/lms-app/frontend/index.html +13 -0
- package/templates/lms-app/frontend/package-lock.json +1592 -0
- package/templates/lms-app/frontend/package.json +23 -0
- package/templates/lms-app/frontend/public/favicon.svg +4 -0
- package/templates/lms-app/frontend/src/App.jsx +107 -0
- package/templates/lms-app/frontend/src/api/authApi.js +5 -0
- package/templates/lms-app/frontend/src/api/booksApi.js +6 -0
- package/templates/lms-app/frontend/src/api/borrowsApi.js +5 -0
- package/templates/lms-app/frontend/src/api/client.js +8 -0
- package/templates/lms-app/frontend/src/api/dashboardApi.js +3 -0
- package/templates/lms-app/frontend/src/api/reportsApi.js +6 -0
- package/templates/lms-app/frontend/src/api/studentsApi.js +6 -0
- package/templates/lms-app/frontend/src/components/AppLayout.jsx +63 -0
- package/templates/lms-app/frontend/src/index.css +34 -0
- package/templates/lms-app/frontend/src/main.jsx +13 -0
- package/templates/lms-app/frontend/src/pages/BooksPage.jsx +206 -0
- package/templates/lms-app/frontend/src/pages/BorrowPage.jsx +134 -0
- package/templates/lms-app/frontend/src/pages/DashboardPage.jsx +42 -0
- package/templates/lms-app/frontend/src/pages/ForgotPassword.jsx +112 -0
- package/templates/lms-app/frontend/src/pages/LoginPage.jsx +71 -0
- package/templates/lms-app/frontend/src/pages/ReportsPage.jsx +176 -0
- package/templates/lms-app/frontend/src/pages/ReturnPage.jsx +75 -0
- package/templates/lms-app/frontend/src/pages/SearchPage.jsx +156 -0
- package/templates/lms-app/frontend/src/pages/StudentsPage.jsx +204 -0
- package/templates/lms-app/frontend/vite.config.js +26 -0
- package/templates/scms-app/.env +7 -0
- package/templates/scms-app/README.md +80 -0
- package/templates/scms-app/backend-mongodb/.env +3 -0
- package/templates/scms-app/backend-mongodb/.env.example +3 -0
- package/templates/scms-app/backend-mongodb/config/db.js +29 -0
- package/templates/scms-app/backend-mongodb/controllers/authController.js +93 -0
- package/templates/scms-app/backend-mongodb/controllers/deliveryController.js +65 -0
- package/templates/scms-app/backend-mongodb/controllers/reportController.js +51 -0
- package/templates/scms-app/backend-mongodb/controllers/shipmentController.js +65 -0
- package/templates/scms-app/backend-mongodb/controllers/supplierController.js +27 -0
- package/templates/scms-app/backend-mongodb/middleware/auth.js +16 -0
- package/templates/scms-app/backend-mongodb/models/Delivery.js +14 -0
- package/templates/scms-app/backend-mongodb/models/Shipment.js +14 -0
- package/templates/scms-app/backend-mongodb/models/Supplier.js +14 -0
- package/templates/scms-app/backend-mongodb/models/User.js +9 -0
- package/templates/scms-app/backend-mongodb/package-lock.json +1571 -0
- package/templates/scms-app/backend-mongodb/package.json +22 -0
- package/templates/scms-app/backend-mongodb/routes/authRoutes.js +8 -0
- package/templates/scms-app/backend-mongodb/routes/deliveryRoutes.js +8 -0
- package/templates/scms-app/backend-mongodb/routes/reportRoutes.js +5 -0
- package/templates/scms-app/backend-mongodb/routes/shipmentRoutes.js +8 -0
- package/templates/scms-app/backend-mongodb/routes/supplierRoutes.js +6 -0
- package/templates/scms-app/backend-mongodb/server.js +39 -0
- package/templates/scms-app/backend-mysql/.env +7 -0
- package/templates/scms-app/backend-mysql/.env.example +7 -0
- package/templates/scms-app/backend-mysql/config/db.js +33 -0
- package/templates/scms-app/backend-mysql/controllers/authController.js +98 -0
- package/templates/scms-app/backend-mysql/controllers/deliveryController.js +62 -0
- package/templates/scms-app/backend-mysql/controllers/reportController.js +39 -0
- package/templates/scms-app/backend-mysql/controllers/shipmentController.js +62 -0
- package/templates/scms-app/backend-mysql/controllers/supplierController.js +28 -0
- package/templates/scms-app/backend-mysql/database/schema.sql +7 -0
- package/templates/scms-app/backend-mysql/middleware/auth.js +16 -0
- package/templates/scms-app/backend-mysql/package-lock.json +1486 -0
- package/templates/scms-app/backend-mysql/package.json +23 -0
- package/templates/scms-app/backend-mysql/routes/authRoutes.js +8 -0
- package/templates/scms-app/backend-mysql/routes/deliveryRoutes.js +8 -0
- package/templates/scms-app/backend-mysql/routes/reportRoutes.js +5 -0
- package/templates/scms-app/backend-mysql/routes/shipmentRoutes.js +8 -0
- package/templates/scms-app/backend-mysql/routes/supplierRoutes.js +6 -0
- package/templates/scms-app/backend-mysql/server.js +39 -0
- package/templates/scms-app/frontend/index.html +12 -0
- package/templates/scms-app/frontend/package-lock.json +1634 -0
- package/templates/scms-app/frontend/package.json +23 -0
- package/templates/scms-app/frontend/src/App.jsx +31 -0
- package/templates/scms-app/frontend/src/api/client.js +11 -0
- package/templates/scms-app/frontend/src/components/AppLayout.jsx +49 -0
- package/templates/scms-app/frontend/src/context/AuthContext.jsx +41 -0
- package/templates/scms-app/frontend/src/hooks/.gitkeep +0 -0
- package/templates/scms-app/frontend/src/index.css +2 -0
- package/templates/scms-app/frontend/src/main.jsx +16 -0
- package/templates/scms-app/frontend/src/pages/DeliveriesPage.jsx +265 -0
- package/templates/scms-app/frontend/src/pages/ForgotPassword.jsx +103 -0
- package/templates/scms-app/frontend/src/pages/LoginPage.jsx +105 -0
- package/templates/scms-app/frontend/src/pages/ReportsPage.jsx +192 -0
- package/templates/scms-app/frontend/src/pages/ShipmentsPage.jsx +259 -0
- package/templates/scms-app/frontend/src/pages/SuppliersPage.jsx +168 -0
- package/templates/scms-app/frontend/vite.config.js +8 -0
- package/templates/sfms-app/.env +7 -0
- package/templates/sfms-app/README.md +72 -0
- package/templates/sfms-app/backend-mongodb/.env +3 -0
- package/templates/sfms-app/backend-mongodb/.env.example +3 -0
- package/templates/sfms-app/backend-mongodb/package-lock.json +1580 -0
- package/templates/sfms-app/backend-mongodb/package.json +23 -0
- package/templates/sfms-app/backend-mongodb/src/config/database.js +7 -0
- package/templates/sfms-app/backend-mongodb/src/config/env.js +35 -0
- package/templates/sfms-app/backend-mongodb/src/middleware/authMiddleware.js +32 -0
- package/templates/sfms-app/backend-mongodb/src/models/Payment.js +12 -0
- package/templates/sfms-app/backend-mongodb/src/models/Student.js +12 -0
- package/templates/sfms-app/backend-mongodb/src/models/User.js +14 -0
- package/templates/sfms-app/backend-mongodb/src/routes/authRoutes.js +140 -0
- package/templates/sfms-app/backend-mongodb/src/routes/paymentRoutes.js +117 -0
- package/templates/sfms-app/backend-mongodb/src/routes/reportRoutes.js +59 -0
- package/templates/sfms-app/backend-mongodb/src/routes/studentRoutes.js +79 -0
- package/templates/sfms-app/backend-mongodb/src/server.js +34 -0
- package/templates/sfms-app/backend-mysql/.env +7 -0
- package/templates/sfms-app/backend-mysql/.env.example +7 -0
- package/templates/sfms-app/backend-mysql/database/schema.sql +29 -0
- package/templates/sfms-app/backend-mysql/package-lock.json +1467 -0
- package/templates/sfms-app/backend-mysql/package.json +24 -0
- package/templates/sfms-app/backend-mysql/src/config/.gitkeep +0 -0
- package/templates/sfms-app/backend-mysql/src/config/db.js +31 -0
- package/templates/sfms-app/backend-mysql/src/config/env.js +20 -0
- package/templates/sfms-app/backend-mysql/src/middleware/.gitkeep +0 -0
- package/templates/sfms-app/backend-mysql/src/middleware/authMiddleware.js +26 -0
- package/templates/sfms-app/backend-mysql/src/models/.gitkeep +0 -0
- package/templates/sfms-app/backend-mysql/src/routes/.gitkeep +0 -0
- package/templates/sfms-app/backend-mysql/src/routes/authRoutes.js +131 -0
- package/templates/sfms-app/backend-mysql/src/routes/paymentRoutes.js +92 -0
- package/templates/sfms-app/backend-mysql/src/routes/reportRoutes.js +41 -0
- package/templates/sfms-app/backend-mysql/src/routes/studentRoutes.js +75 -0
- package/templates/sfms-app/backend-mysql/src/server.js +39 -0
- package/templates/sfms-app/backend-mysql/src/utils/mappers.js +43 -0
- package/templates/sfms-app/frontend/.env.example +9 -0
- package/templates/sfms-app/frontend/index.html +19 -0
- package/templates/sfms-app/frontend/package-lock.json +2667 -0
- package/templates/sfms-app/frontend/package.json +23 -0
- package/templates/sfms-app/frontend/postcss.config.js +6 -0
- package/templates/sfms-app/frontend/public/favicon.svg +4 -0
- package/templates/sfms-app/frontend/src/App.jsx +38 -0
- package/templates/sfms-app/frontend/src/api/apiClient.js +54 -0
- package/templates/sfms-app/frontend/src/components/AppLayout.jsx +61 -0
- package/templates/sfms-app/frontend/src/context/AuthContext.jsx +87 -0
- package/templates/sfms-app/frontend/src/index.css +7 -0
- package/templates/sfms-app/frontend/src/main.jsx +16 -0
- package/templates/sfms-app/frontend/src/pages/DashboardPage.jsx +78 -0
- package/templates/sfms-app/frontend/src/pages/ForgotPassword.jsx +114 -0
- package/templates/sfms-app/frontend/src/pages/LoginPage.jsx +141 -0
- package/templates/sfms-app/frontend/src/pages/PaymentsPage.jsx +309 -0
- package/templates/sfms-app/frontend/src/pages/ReportsPage.jsx +123 -0
- package/templates/sfms-app/frontend/src/pages/StudentsPage.jsx +281 -0
- package/templates/sfms-app/frontend/tailwind.config.js +21 -0
- package/templates/sfms-app/frontend/vite.config.js +61 -0
- package/templates/sims-app/README.md +138 -0
- package/templates/sims-app/backend/.env +4 -0
- package/templates/sims-app/backend/.env.example +4 -0
- package/templates/sims-app/backend/package.json +22 -0
- package/templates/sims-app/backend/src/config/db.js +9 -0
- package/templates/sims-app/backend/src/controllers/authController.js +115 -0
- package/templates/sims-app/backend/src/controllers/simsReportController.js +94 -0
- package/templates/sims-app/backend/src/controllers/sparePartController.js +41 -0
- package/templates/sims-app/backend/src/controllers/stockInController.js +45 -0
- package/templates/sims-app/backend/src/controllers/stockOutController.js +123 -0
- package/templates/sims-app/backend/src/middleware/auth.js +8 -0
- package/templates/sims-app/backend/src/models/SparePart.js +17 -0
- package/templates/sims-app/backend/src/models/StockIn.js +16 -0
- package/templates/sims-app/backend/src/models/StockOut.js +18 -0
- package/templates/sims-app/backend/src/models/User.js +12 -0
- package/templates/sims-app/backend/src/routes/authRoutes.js +12 -0
- package/templates/sims-app/backend/src/routes/simsReportRoutes.js +8 -0
- package/templates/sims-app/backend/src/routes/sparePartRoutes.js +8 -0
- package/templates/sims-app/backend/src/routes/stockInRoutes.js +8 -0
- package/templates/sims-app/backend/src/routes/stockOutRoutes.js +10 -0
- package/templates/sims-app/backend/src/server.js +62 -0
- package/templates/sims-app/backend/src/utils/passwordPolicy.js +10 -0
- package/templates/sims-app/backend/src/utils/sparePartHelpers.js +5 -0
- package/templates/sims-app/frontend/index.html +13 -0
- package/templates/sims-app/frontend/package.json +31 -0
- package/templates/sims-app/frontend/src/App.jsx +110 -0
- package/templates/sims-app/frontend/src/api/authApi.js +7 -0
- package/templates/sims-app/frontend/src/api/client.js +8 -0
- package/templates/sims-app/frontend/src/api/simsReportApi.js +5 -0
- package/templates/sims-app/frontend/src/api/sparePartsApi.js +4 -0
- package/templates/sims-app/frontend/src/api/stockInApi.js +4 -0
- package/templates/sims-app/frontend/src/api/stockOutApi.js +6 -0
- package/templates/sims-app/frontend/src/api/usersApi.js +3 -0
- package/templates/sims-app/frontend/src/components/AppLayout.jsx +47 -0
- package/templates/sims-app/frontend/src/index.css +7 -0
- package/templates/sims-app/frontend/src/main.jsx +13 -0
- package/templates/sims-app/frontend/src/pages/ForgotPassword.jsx +111 -0
- package/templates/sims-app/frontend/src/pages/LoginPage.jsx +71 -0
- package/templates/sims-app/frontend/src/pages/RegisterPage.jsx +99 -0
- package/templates/sims-app/frontend/src/pages/ReportsPage.jsx +120 -0
- package/templates/sims-app/frontend/src/pages/SparePartPage.jsx +148 -0
- package/templates/sims-app/frontend/src/pages/StockInPage.jsx +122 -0
- package/templates/sims-app/frontend/src/pages/StockOutPage.jsx +252 -0
- package/templates/sims-app/frontend/src/utils/passwordPolicy.js +8 -0
- package/templates/sims-app/frontend/vite.config.js +8 -0
- package/templates/smartshop-app/README.md +61 -0
- package/templates/smartshop-app/backend/.env +7 -0
- package/templates/smartshop-app/backend/.env.example +7 -0
- package/templates/smartshop-app/backend/database/schema.sql +46 -0
- package/templates/smartshop-app/backend/package-lock.json +1487 -0
- package/templates/smartshop-app/backend/package.json +26 -0
- package/templates/smartshop-app/backend/src/app.js +57 -0
- package/templates/smartshop-app/backend/src/config/db.js +52 -0
- package/templates/smartshop-app/backend/src/controllers/authController.js +98 -0
- package/templates/smartshop-app/backend/src/controllers/customerController.js +26 -0
- package/templates/smartshop-app/backend/src/controllers/productController.js +21 -0
- package/templates/smartshop-app/backend/src/controllers/reportController.js +29 -0
- package/templates/smartshop-app/backend/src/controllers/saleController.js +11 -0
- package/templates/smartshop-app/backend/src/middleware/authMiddleware.js +22 -0
- package/templates/smartshop-app/backend/src/models/authModel.js +24 -0
- package/templates/smartshop-app/backend/src/models/customerModel.js +43 -0
- package/templates/smartshop-app/backend/src/models/productModel.js +37 -0
- package/templates/smartshop-app/backend/src/models/reportModel.js +56 -0
- package/templates/smartshop-app/backend/src/models/saleModel.js +54 -0
- package/templates/smartshop-app/backend/src/routes/authRoutes.js +10 -0
- package/templates/smartshop-app/backend/src/routes/customerRoutes.js +16 -0
- package/templates/smartshop-app/backend/src/routes/productRoutes.js +16 -0
- package/templates/smartshop-app/backend/src/routes/reportRoutes.js +18 -0
- package/templates/smartshop-app/backend/src/routes/saleRoutes.js +9 -0
- package/templates/smartshop-app/backend/src/server.js +19 -0
- package/templates/smartshop-app/frontend/README.md +18 -0
- package/templates/smartshop-app/frontend/eslint.config.js +21 -0
- package/templates/smartshop-app/frontend/index.html +13 -0
- package/templates/smartshop-app/frontend/package-lock.json +3415 -0
- package/templates/smartshop-app/frontend/package.json +34 -0
- package/templates/smartshop-app/frontend/public/favicon.svg +1 -0
- package/templates/smartshop-app/frontend/public/icons.svg +24 -0
- package/templates/smartshop-app/frontend/src/App.css +184 -0
- package/templates/smartshop-app/frontend/src/App.jsx +41 -0
- package/templates/smartshop-app/frontend/src/assets/hero.png +0 -0
- package/templates/smartshop-app/frontend/src/assets/react.svg +1 -0
- package/templates/smartshop-app/frontend/src/assets/vite.svg +1 -0
- package/templates/smartshop-app/frontend/src/components/AppLayout.jsx +71 -0
- package/templates/smartshop-app/frontend/src/components/FormCard.jsx +12 -0
- package/templates/smartshop-app/frontend/src/components/StatCard.jsx +10 -0
- package/templates/smartshop-app/frontend/src/index.css +28 -0
- package/templates/smartshop-app/frontend/src/main.jsx +13 -0
- package/templates/smartshop-app/frontend/src/pages/CustomersPage.jsx +175 -0
- package/templates/smartshop-app/frontend/src/pages/DashboardPage.jsx +30 -0
- package/templates/smartshop-app/frontend/src/pages/ForgotPassword.jsx +102 -0
- package/templates/smartshop-app/frontend/src/pages/LoginPage.jsx +142 -0
- package/templates/smartshop-app/frontend/src/pages/ProductsPage.jsx +165 -0
- package/templates/smartshop-app/frontend/src/pages/ReportsPage.jsx +204 -0
- package/templates/smartshop-app/frontend/src/pages/SalesPage.jsx +153 -0
- package/templates/smartshop-app/frontend/src/services/api.js +15 -0
- package/templates/smartshop-app/frontend/vite.config.js +13 -0
- package/templates/srms-app/.env +7 -0
- package/templates/srms-app/README.md +82 -0
- package/templates/srms-app/backend-mongodb/.env +3 -0
- package/templates/srms-app/backend-mongodb/.env.example +3 -0
- package/templates/srms-app/backend-mongodb/config/db.js +29 -0
- package/templates/srms-app/backend-mongodb/controllers/authController.js +93 -0
- package/templates/srms-app/backend-mongodb/controllers/customerController.js +27 -0
- package/templates/srms-app/backend-mongodb/controllers/productController.js +26 -0
- package/templates/srms-app/backend-mongodb/controllers/reportController.js +44 -0
- package/templates/srms-app/backend-mongodb/controllers/saleController.js +72 -0
- package/templates/srms-app/backend-mongodb/middleware/auth.js +16 -0
- package/templates/srms-app/backend-mongodb/models/Customer.js +14 -0
- package/templates/srms-app/backend-mongodb/models/Product.js +13 -0
- package/templates/srms-app/backend-mongodb/models/Sale.js +15 -0
- package/templates/srms-app/backend-mongodb/models/User.js +9 -0
- package/templates/srms-app/backend-mongodb/package-lock.json +1571 -0
- package/templates/srms-app/backend-mongodb/package.json +22 -0
- package/templates/srms-app/backend-mongodb/routes/authRoutes.js +8 -0
- package/templates/srms-app/backend-mongodb/routes/customerRoutes.js +6 -0
- package/templates/srms-app/backend-mongodb/routes/productRoutes.js +6 -0
- package/templates/srms-app/backend-mongodb/routes/reportRoutes.js +5 -0
- package/templates/srms-app/backend-mongodb/routes/saleRoutes.js +8 -0
- package/templates/srms-app/backend-mongodb/server.js +39 -0
- package/templates/srms-app/backend-mysql/.env +7 -0
- package/templates/srms-app/backend-mysql/.env.example +7 -0
- package/templates/srms-app/backend-mysql/config/db.js +33 -0
- package/templates/srms-app/backend-mysql/controllers/authController.js +98 -0
- package/templates/srms-app/backend-mysql/controllers/customerController.js +28 -0
- package/templates/srms-app/backend-mysql/controllers/productController.js +27 -0
- package/templates/srms-app/backend-mysql/controllers/reportController.js +29 -0
- package/templates/srms-app/backend-mysql/controllers/saleController.js +68 -0
- package/templates/srms-app/backend-mysql/database/schema.sql +7 -0
- package/templates/srms-app/backend-mysql/middleware/auth.js +16 -0
- package/templates/srms-app/backend-mysql/package-lock.json +1486 -0
- package/templates/srms-app/backend-mysql/package.json +23 -0
- package/templates/srms-app/backend-mysql/routes/authRoutes.js +8 -0
- package/templates/srms-app/backend-mysql/routes/customerRoutes.js +6 -0
- package/templates/srms-app/backend-mysql/routes/productRoutes.js +6 -0
- package/templates/srms-app/backend-mysql/routes/reportRoutes.js +5 -0
- package/templates/srms-app/backend-mysql/routes/saleRoutes.js +8 -0
- package/templates/srms-app/backend-mysql/server.js +39 -0
- package/templates/srms-app/frontend/index.html +12 -0
- package/templates/srms-app/frontend/package-lock.json +1634 -0
- package/templates/srms-app/frontend/package.json +23 -0
- package/templates/srms-app/frontend/src/App.jsx +31 -0
- package/templates/srms-app/frontend/src/api/client.js +11 -0
- package/templates/srms-app/frontend/src/components/AppLayout.jsx +40 -0
- package/templates/srms-app/frontend/src/context/AuthContext.jsx +41 -0
- package/templates/srms-app/frontend/src/hooks/.gitkeep +0 -0
- package/templates/srms-app/frontend/src/index.css +2 -0
- package/templates/srms-app/frontend/src/main.jsx +16 -0
- package/templates/srms-app/frontend/src/pages/CustomersPage.jsx +160 -0
- package/templates/srms-app/frontend/src/pages/ForgotPassword.jsx +103 -0
- package/templates/srms-app/frontend/src/pages/LoginPage.jsx +105 -0
- package/templates/srms-app/frontend/src/pages/ProductsPage.jsx +158 -0
- package/templates/srms-app/frontend/src/pages/ReportsPage.jsx +192 -0
- package/templates/srms-app/frontend/src/pages/SalesPage.jsx +310 -0
- package/templates/srms-app/frontend/vite.config.js +8 -0
- package/templates/stockhub-sms-app/.env +7 -0
- package/templates/stockhub-sms-app/README.md +82 -0
- package/templates/stockhub-sms-app/backend-mongodb/.env +3 -0
- package/templates/stockhub-sms-app/backend-mongodb/.env.example +3 -0
- package/templates/stockhub-sms-app/backend-mongodb/config/db.js +29 -0
- package/templates/stockhub-sms-app/backend-mongodb/controllers/authController.js +93 -0
- package/templates/stockhub-sms-app/backend-mongodb/controllers/productController.js +29 -0
- package/templates/stockhub-sms-app/backend-mongodb/controllers/reportController.js +53 -0
- package/templates/stockhub-sms-app/backend-mongodb/controllers/transactionController.js +74 -0
- package/templates/stockhub-sms-app/backend-mongodb/controllers/warehouseController.js +25 -0
- package/templates/stockhub-sms-app/backend-mongodb/middleware/auth.js +16 -0
- package/templates/stockhub-sms-app/backend-mongodb/models/Counter.js +13 -0
- package/templates/stockhub-sms-app/backend-mongodb/models/Product.js +16 -0
- package/templates/stockhub-sms-app/backend-mongodb/models/StockTransaction.js +19 -0
- package/templates/stockhub-sms-app/backend-mongodb/models/User.js +9 -0
- package/templates/stockhub-sms-app/backend-mongodb/models/Warehouse.js +12 -0
- package/templates/stockhub-sms-app/backend-mongodb/package-lock.json +1571 -0
- package/templates/stockhub-sms-app/backend-mongodb/package.json +22 -0
- package/templates/stockhub-sms-app/backend-mongodb/routes/authRoutes.js +8 -0
- package/templates/stockhub-sms-app/backend-mongodb/routes/productRoutes.js +6 -0
- package/templates/stockhub-sms-app/backend-mongodb/routes/reportRoutes.js +5 -0
- package/templates/stockhub-sms-app/backend-mongodb/routes/transactionRoutes.js +8 -0
- package/templates/stockhub-sms-app/backend-mongodb/routes/warehouseRoutes.js +6 -0
- package/templates/stockhub-sms-app/backend-mongodb/server.js +39 -0
- package/templates/stockhub-sms-app/backend-mysql/.env +7 -0
- package/templates/stockhub-sms-app/backend-mysql/.env.example +7 -0
- package/templates/stockhub-sms-app/backend-mysql/config/db.js +33 -0
- package/templates/stockhub-sms-app/backend-mysql/controllers/authController.js +98 -0
- package/templates/stockhub-sms-app/backend-mysql/controllers/productController.js +30 -0
- package/templates/stockhub-sms-app/backend-mysql/controllers/reportController.js +53 -0
- package/templates/stockhub-sms-app/backend-mysql/controllers/transactionController.js +70 -0
- package/templates/stockhub-sms-app/backend-mysql/controllers/warehouseController.js +26 -0
- package/templates/stockhub-sms-app/backend-mysql/database/schema.sql +40 -0
- package/templates/stockhub-sms-app/backend-mysql/middleware/auth.js +16 -0
- package/templates/stockhub-sms-app/backend-mysql/package-lock.json +1486 -0
- package/templates/stockhub-sms-app/backend-mysql/package.json +23 -0
- package/templates/stockhub-sms-app/backend-mysql/routes/authRoutes.js +8 -0
- package/templates/stockhub-sms-app/backend-mysql/routes/productRoutes.js +6 -0
- package/templates/stockhub-sms-app/backend-mysql/routes/reportRoutes.js +5 -0
- package/templates/stockhub-sms-app/backend-mysql/routes/transactionRoutes.js +8 -0
- package/templates/stockhub-sms-app/backend-mysql/routes/warehouseRoutes.js +6 -0
- package/templates/stockhub-sms-app/backend-mysql/server.js +39 -0
- package/templates/stockhub-sms-app/frontend/index.html +12 -0
- package/templates/stockhub-sms-app/frontend/package-lock.json +1634 -0
- package/templates/stockhub-sms-app/frontend/package.json +23 -0
- package/templates/stockhub-sms-app/frontend/src/App.jsx +31 -0
- package/templates/stockhub-sms-app/frontend/src/api/client.js +11 -0
- package/templates/stockhub-sms-app/frontend/src/components/AppLayout.jsx +40 -0
- package/templates/stockhub-sms-app/frontend/src/context/AuthContext.jsx +41 -0
- package/templates/stockhub-sms-app/frontend/src/hooks/.gitkeep +0 -0
- package/templates/stockhub-sms-app/frontend/src/index.css +13 -0
- package/templates/stockhub-sms-app/frontend/src/main.jsx +16 -0
- package/templates/stockhub-sms-app/frontend/src/pages/ForgotPassword.jsx +103 -0
- package/templates/stockhub-sms-app/frontend/src/pages/LoginPage.jsx +105 -0
- package/templates/stockhub-sms-app/frontend/src/pages/ProductsPage.jsx +132 -0
- package/templates/stockhub-sms-app/frontend/src/pages/ReportsPage.jsx +177 -0
- package/templates/stockhub-sms-app/frontend/src/pages/TransactionsPage.jsx +270 -0
- package/templates/stockhub-sms-app/frontend/src/pages/WarehousesPage.jsx +116 -0
- package/templates/stockhub-sms-app/frontend/vite.config.js +8 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lms-backend-mongodb",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Library Management System API — Express + MongoDB (EPMS-style layout)",
|
|
5
|
+
"main": "src/server.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "nodemon src/server.js",
|
|
8
|
+
"start": "node src/server.js",
|
|
9
|
+
"seed": "node src/seed.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"bcryptjs": "^3.0.3",
|
|
16
|
+
"connect-mongo": "^6.0.0",
|
|
17
|
+
"cors": "^2.8.6",
|
|
18
|
+
"dotenv": "^17.4.2",
|
|
19
|
+
"express": "^5.2.1",
|
|
20
|
+
"express-session": "^1.19.0",
|
|
21
|
+
"mongoose": "^9.5.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"nodemon": "^3.1.14"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { getEnv } = require("./env");
|
|
3
|
+
|
|
4
|
+
async function connectDatabase() {
|
|
5
|
+
const { mongoUri } = getEnv();
|
|
6
|
+
await mongoose.connect(mongoUri);
|
|
7
|
+
console.log("Database Connected Successfully");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = connectDatabase;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function parsePort(raw, fallback) {
|
|
2
|
+
const n = Number(String(raw || "").trim());
|
|
3
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function getEnv() {
|
|
7
|
+
const mongoUri =
|
|
8
|
+
process.env.MONGO_URI?.trim() ||
|
|
9
|
+
process.env.MONGODB_URI?.trim() ||
|
|
10
|
+
process.env.DATABASE_URL?.trim() ||
|
|
11
|
+
"mongodb://127.0.0.1:27017/lms";
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
port: parsePort(process.env.PORT || process.env.LMS_BACKEND_PORT, 5827),
|
|
15
|
+
mongoUri,
|
|
16
|
+
sessionSecret:
|
|
17
|
+
process.env.SESSION_SECRET?.trim() ||
|
|
18
|
+
process.env.LMS_SESSION_SECRET?.trim() ||
|
|
19
|
+
"lms-dev-session-secret-change-in-production",
|
|
20
|
+
frontendUrl:
|
|
21
|
+
process.env.FRONTEND_URL?.trim() ||
|
|
22
|
+
process.env.LMS_FRONTEND_URL?.trim() ||
|
|
23
|
+
"http://localhost:5828",
|
|
24
|
+
nodeEnv: process.env.NODE_ENV || "development",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { getEnv };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const bcrypt = require("bcryptjs");
|
|
2
|
+
const User = require("../models/User");
|
|
3
|
+
|
|
4
|
+
const normalize = (value) => String(value || "").trim().toLowerCase();
|
|
5
|
+
const normalizeEmail = (email) => String(email || "").trim().toLowerCase();
|
|
6
|
+
|
|
7
|
+
const login = async (req, res) => {
|
|
8
|
+
try {
|
|
9
|
+
const username = normalize(req.body.username);
|
|
10
|
+
const password = String(req.body.password || "");
|
|
11
|
+
if (!username || !password) {
|
|
12
|
+
return res.status(400).json({ message: "Username and password are required" });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const user = await User.findOne({ username });
|
|
16
|
+
if (!user) {
|
|
17
|
+
return res.status(401).json({ message: "Invalid credentials" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ok = await bcrypt.compare(password, user.passwordHash);
|
|
21
|
+
if (!ok) {
|
|
22
|
+
return res.status(401).json({ message: "Invalid credentials" });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
req.session.userId = String(user._id);
|
|
26
|
+
req.session.username = user.username;
|
|
27
|
+
req.session.role = user.role;
|
|
28
|
+
return res.json({
|
|
29
|
+
message: "Login successful",
|
|
30
|
+
username: user.username,
|
|
31
|
+
role: user.role,
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return res.status(500).json({ message: error.message });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const forgotPassword = async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const { email, newPassword, confirmPassword } = req.body;
|
|
41
|
+
if (!email) {
|
|
42
|
+
return res.status(400).json({ success: false, message: "Email is required." });
|
|
43
|
+
}
|
|
44
|
+
if (!newPassword) {
|
|
45
|
+
return res.status(400).json({ success: false, message: "New password is required." });
|
|
46
|
+
}
|
|
47
|
+
if (!confirmPassword) {
|
|
48
|
+
return res.status(400).json({ success: false, message: "Confirm password is required." });
|
|
49
|
+
}
|
|
50
|
+
if (newPassword !== confirmPassword) {
|
|
51
|
+
return res.status(400).json({
|
|
52
|
+
success: false,
|
|
53
|
+
message: "New password and confirm password must match.",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const emailNorm = normalizeEmail(email);
|
|
57
|
+
const user = await User.findOne({ email: emailNorm });
|
|
58
|
+
if (!user) {
|
|
59
|
+
return res.status(404).json({ success: false, message: "User not found" });
|
|
60
|
+
}
|
|
61
|
+
user.passwordHash = await bcrypt.hash(newPassword, 10);
|
|
62
|
+
await user.save();
|
|
63
|
+
return res.json({ success: true, message: "Password reset successfully" });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return res.status(500).json({ success: false, message: error.message });
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const me = (req, res) => {
|
|
70
|
+
if (!req.session.userId) {
|
|
71
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
72
|
+
}
|
|
73
|
+
return res.json({
|
|
74
|
+
username: req.session.username,
|
|
75
|
+
role: req.session.role,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const logout = (req, res) => {
|
|
80
|
+
req.session.destroy(() => {
|
|
81
|
+
res.clearCookie("connect.sid");
|
|
82
|
+
res.json({ message: "Logged out" });
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports = { login, forgotPassword, me, logout };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const Book = require("../models/Book");
|
|
2
|
+
|
|
3
|
+
const listBooks = async (req, res) => {
|
|
4
|
+
try {
|
|
5
|
+
const q = String(req.query.title || "").trim();
|
|
6
|
+
const filter = q ? { title: new RegExp(q.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i") } : {};
|
|
7
|
+
const books = await Book.find(filter).sort({ title: 1 });
|
|
8
|
+
return res.json(books);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return res.status(500).json({ message: error.message });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getBook = async (req, res) => {
|
|
15
|
+
try {
|
|
16
|
+
const book = await Book.findById(req.params.id);
|
|
17
|
+
if (!book) return res.status(404).json({ message: "Book not found" });
|
|
18
|
+
return res.json(book);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return res.status(500).json({ message: error.message });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const createBook = async (req, res) => {
|
|
25
|
+
try {
|
|
26
|
+
const { title, author, category, quantity, publishedYear } = req.body;
|
|
27
|
+
if (!title || !author || !category || quantity === undefined || !publishedYear) {
|
|
28
|
+
return res.status(400).json({ message: "All fields are required" });
|
|
29
|
+
}
|
|
30
|
+
const qty = Number(quantity);
|
|
31
|
+
if (!Number.isFinite(qty) || qty < 0) {
|
|
32
|
+
return res.status(400).json({ message: "Quantity must be a non-negative number" });
|
|
33
|
+
}
|
|
34
|
+
const year = Number(publishedYear);
|
|
35
|
+
if (!Number.isFinite(year) || year < 1000 || year > 9999) {
|
|
36
|
+
return res.status(400).json({ message: "Invalid published year" });
|
|
37
|
+
}
|
|
38
|
+
const book = await Book.create({
|
|
39
|
+
title: String(title).trim(),
|
|
40
|
+
author: String(author).trim(),
|
|
41
|
+
category: String(category).trim(),
|
|
42
|
+
quantity: qty,
|
|
43
|
+
publishedYear: year,
|
|
44
|
+
});
|
|
45
|
+
return res.status(201).json(book);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return res.status(500).json({ message: error.message });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const updateBook = async (req, res) => {
|
|
52
|
+
try {
|
|
53
|
+
const { title, author, category, quantity, publishedYear } = req.body;
|
|
54
|
+
const book = await Book.findById(req.params.id);
|
|
55
|
+
if (!book) return res.status(404).json({ message: "Book not found" });
|
|
56
|
+
if (title !== undefined) book.title = String(title).trim();
|
|
57
|
+
if (author !== undefined) book.author = String(author).trim();
|
|
58
|
+
if (category !== undefined) book.category = String(category).trim();
|
|
59
|
+
if (quantity !== undefined) {
|
|
60
|
+
const qty = Number(quantity);
|
|
61
|
+
if (!Number.isFinite(qty) || qty < 0) {
|
|
62
|
+
return res.status(400).json({ message: "Invalid quantity" });
|
|
63
|
+
}
|
|
64
|
+
book.quantity = qty;
|
|
65
|
+
}
|
|
66
|
+
if (publishedYear !== undefined) {
|
|
67
|
+
const year = Number(publishedYear);
|
|
68
|
+
if (!Number.isFinite(year) || year < 1000 || year > 9999) {
|
|
69
|
+
return res.status(400).json({ message: "Invalid published year" });
|
|
70
|
+
}
|
|
71
|
+
book.publishedYear = year;
|
|
72
|
+
}
|
|
73
|
+
await book.save();
|
|
74
|
+
return res.json(book);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return res.status(500).json({ message: error.message });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const deleteBook = async (req, res) => {
|
|
81
|
+
try {
|
|
82
|
+
const Borrow = require("../models/Borrow");
|
|
83
|
+
const active = await Borrow.exists({ book: req.params.id, returnedAt: null });
|
|
84
|
+
if (active) {
|
|
85
|
+
return res.status(409).json({ message: "Book has active borrows" });
|
|
86
|
+
}
|
|
87
|
+
const book = await Book.findByIdAndDelete(req.params.id);
|
|
88
|
+
if (!book) return res.status(404).json({ message: "Book not found" });
|
|
89
|
+
return res.json({ message: "Deleted" });
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return res.status(500).json({ message: error.message });
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
listBooks,
|
|
97
|
+
getBook,
|
|
98
|
+
createBook,
|
|
99
|
+
updateBook,
|
|
100
|
+
deleteBook,
|
|
101
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const Borrow = require("../models/Borrow");
|
|
2
|
+
const Book = require("../models/Book");
|
|
3
|
+
const Student = require("../models/Student");
|
|
4
|
+
|
|
5
|
+
const startOfDay = (d) => {
|
|
6
|
+
const x = new Date(d);
|
|
7
|
+
x.setHours(0, 0, 0, 0);
|
|
8
|
+
return x;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const listBorrows = async (req, res) => {
|
|
12
|
+
try {
|
|
13
|
+
const status = String(req.query.status || "all").toLowerCase();
|
|
14
|
+
const dateFrom = req.query.dateFrom ? startOfDay(req.query.dateFrom) : null;
|
|
15
|
+
const dateTo = req.query.dateTo ? startOfDay(req.query.dateTo) : null;
|
|
16
|
+
if (dateTo) dateTo.setHours(23, 59, 59, 999);
|
|
17
|
+
|
|
18
|
+
const filter = {};
|
|
19
|
+
if (status === "active") filter.returnedAt = null;
|
|
20
|
+
else if (status === "returned") filter.returnedAt = { $ne: null };
|
|
21
|
+
|
|
22
|
+
if (dateFrom || dateTo) {
|
|
23
|
+
filter.borrowDate = {};
|
|
24
|
+
if (dateFrom) filter.borrowDate.$gte = dateFrom;
|
|
25
|
+
if (dateTo) filter.borrowDate.$lte = dateTo;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const rows = await Borrow.find(filter)
|
|
29
|
+
.populate("student", "fullName className email phone")
|
|
30
|
+
.populate("book", "title author category quantity publishedYear")
|
|
31
|
+
.sort({ borrowDate: -1 });
|
|
32
|
+
return res.json(rows);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return res.status(500).json({ message: error.message });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createBorrow = async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const { studentId, bookId, borrowDate, returnDueDate } = req.body;
|
|
41
|
+
if (!studentId || !bookId || !borrowDate || !returnDueDate) {
|
|
42
|
+
return res.status(400).json({ message: "Student, book, borrow date and return date are required" });
|
|
43
|
+
}
|
|
44
|
+
const bd = new Date(borrowDate);
|
|
45
|
+
const rd = new Date(returnDueDate);
|
|
46
|
+
if (Number.isNaN(bd.getTime()) || Number.isNaN(rd.getTime())) {
|
|
47
|
+
return res.status(400).json({ message: "Invalid dates" });
|
|
48
|
+
}
|
|
49
|
+
if (rd < bd) {
|
|
50
|
+
return res.status(400).json({ message: "Return date must be on or after borrow date" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const student = await Student.findById(studentId);
|
|
54
|
+
if (!student) return res.status(404).json({ message: "Student not found" });
|
|
55
|
+
|
|
56
|
+
const book = await Book.findById(bookId);
|
|
57
|
+
if (!book) return res.status(404).json({ message: "Book not found" });
|
|
58
|
+
if (book.quantity < 1) {
|
|
59
|
+
return res.status(409).json({ message: "No copies available to borrow" });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
book.quantity -= 1;
|
|
63
|
+
await book.save();
|
|
64
|
+
|
|
65
|
+
const borrow = await Borrow.create({
|
|
66
|
+
student: studentId,
|
|
67
|
+
book: bookId,
|
|
68
|
+
borrowDate: bd,
|
|
69
|
+
returnDueDate: rd,
|
|
70
|
+
returnedAt: null,
|
|
71
|
+
});
|
|
72
|
+
const populated = await Borrow.findById(borrow._id)
|
|
73
|
+
.populate("student", "fullName className email phone")
|
|
74
|
+
.populate("book", "title author category quantity publishedYear");
|
|
75
|
+
return res.status(201).json(populated);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return res.status(500).json({ message: error.message });
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const returnBorrow = async (req, res) => {
|
|
82
|
+
try {
|
|
83
|
+
const borrow = await Borrow.findById(req.params.id);
|
|
84
|
+
if (!borrow) return res.status(404).json({ message: "Borrow record not found" });
|
|
85
|
+
if (borrow.returnedAt) {
|
|
86
|
+
return res.status(409).json({ message: "Already returned" });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const book = await Book.findById(borrow.book);
|
|
90
|
+
if (!book) return res.status(500).json({ message: "Book missing" });
|
|
91
|
+
|
|
92
|
+
borrow.returnedAt = new Date();
|
|
93
|
+
await borrow.save();
|
|
94
|
+
book.quantity += 1;
|
|
95
|
+
await book.save();
|
|
96
|
+
|
|
97
|
+
const populated = await Borrow.findById(borrow._id)
|
|
98
|
+
.populate("student", "fullName className email phone")
|
|
99
|
+
.populate("book", "title author category quantity publishedYear");
|
|
100
|
+
return res.json(populated);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return res.status(500).json({ message: error.message });
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports = { listBorrows, createBorrow, returnBorrow };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const Book = require("../models/Book");
|
|
2
|
+
const Student = require("../models/Student");
|
|
3
|
+
const Borrow = require("../models/Borrow");
|
|
4
|
+
|
|
5
|
+
const stats = async (_req, res) => {
|
|
6
|
+
try {
|
|
7
|
+
const totalBooks = await Book.countDocuments();
|
|
8
|
+
const totalStudents = await Student.countDocuments();
|
|
9
|
+
const totalCopies = await Book.aggregate([{ $group: { _id: null, sum: { $sum: "$quantity" } } }]);
|
|
10
|
+
const copiesInLibrary = totalCopies[0]?.sum ?? 0;
|
|
11
|
+
|
|
12
|
+
const borrowedActive = await Borrow.countDocuments({ returnedAt: null });
|
|
13
|
+
const returnedCount = await Borrow.countDocuments({ returnedAt: { $ne: null } });
|
|
14
|
+
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const lateReturned = await Borrow.countDocuments({
|
|
17
|
+
returnedAt: { $ne: null },
|
|
18
|
+
$expr: { $gt: ["$returnedAt", "$returnDueDate"] },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const overdueActive = await Borrow.countDocuments({
|
|
22
|
+
returnedAt: null,
|
|
23
|
+
returnDueDate: { $lt: now },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return res.json({
|
|
27
|
+
totalBookTitles: totalBooks,
|
|
28
|
+
totalCopiesInLibrary: copiesInLibrary,
|
|
29
|
+
totalStudents,
|
|
30
|
+
borrowedActive,
|
|
31
|
+
returnedCount,
|
|
32
|
+
lateReturned,
|
|
33
|
+
overdueActive,
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return res.status(500).json({ message: error.message });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = { stats };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const Student = require("../models/Student");
|
|
2
|
+
const Book = require("../models/Book");
|
|
3
|
+
const Borrow = require("../models/Borrow");
|
|
4
|
+
|
|
5
|
+
const allStudents = async (_req, res) => {
|
|
6
|
+
try {
|
|
7
|
+
const rows = await Student.find().sort({ fullName: 1 });
|
|
8
|
+
return res.json({ generatedAt: new Date().toISOString(), rows });
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return res.status(500).json({ message: error.message });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const allBooks = async (_req, res) => {
|
|
15
|
+
try {
|
|
16
|
+
const rows = await Book.find().sort({ title: 1 });
|
|
17
|
+
return res.json({ generatedAt: new Date().toISOString(), rows });
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return res.status(500).json({ message: error.message });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const borrowedReport = async (_req, res) => {
|
|
24
|
+
try {
|
|
25
|
+
const rows = await Borrow.find({ returnedAt: null })
|
|
26
|
+
.populate("student", "fullName className email phone gender")
|
|
27
|
+
.populate("book", "title author category publishedYear")
|
|
28
|
+
.sort({ borrowDate: -1 });
|
|
29
|
+
return res.json({ generatedAt: new Date().toISOString(), rows });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return res.status(500).json({ message: error.message });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const returnedReport = async (_req, res) => {
|
|
36
|
+
try {
|
|
37
|
+
const rows = await Borrow.find({ returnedAt: { $ne: null } })
|
|
38
|
+
.populate("student", "fullName className email phone gender")
|
|
39
|
+
.populate("book", "title author category publishedYear")
|
|
40
|
+
.sort({ returnedAt: -1 });
|
|
41
|
+
return res.json({ generatedAt: new Date().toISOString(), rows });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return res.status(500).json({ message: error.message });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = { allStudents, allBooks, borrowedReport, returnedReport };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const Student = require("../models/Student");
|
|
2
|
+
|
|
3
|
+
const listStudents = async (req, res) => {
|
|
4
|
+
try {
|
|
5
|
+
const q = String(req.query.name || "").trim();
|
|
6
|
+
const filter = q ? { fullName: new RegExp(q.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i") } : {};
|
|
7
|
+
const students = await Student.find(filter).sort({ fullName: 1 });
|
|
8
|
+
return res.json(students);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return res.status(500).json({ message: error.message });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getStudent = async (req, res) => {
|
|
15
|
+
try {
|
|
16
|
+
const student = await Student.findById(req.params.id);
|
|
17
|
+
if (!student) return res.status(404).json({ message: "Student not found" });
|
|
18
|
+
return res.json(student);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return res.status(500).json({ message: error.message });
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const createStudent = async (req, res) => {
|
|
25
|
+
try {
|
|
26
|
+
const { fullName, gender, className, phone, email } = req.body;
|
|
27
|
+
if (!fullName || !gender || !className || !phone || !email) {
|
|
28
|
+
return res.status(400).json({ message: "All fields are required" });
|
|
29
|
+
}
|
|
30
|
+
if (!["Male", "Female", "Other"].includes(gender)) {
|
|
31
|
+
return res.status(400).json({ message: "Invalid gender" });
|
|
32
|
+
}
|
|
33
|
+
const student = await Student.create({
|
|
34
|
+
fullName: String(fullName).trim(),
|
|
35
|
+
gender,
|
|
36
|
+
className: String(className).trim(),
|
|
37
|
+
phone: String(phone).trim(),
|
|
38
|
+
email: String(email).trim().toLowerCase(),
|
|
39
|
+
});
|
|
40
|
+
return res.status(201).json(student);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error.code === 11000) {
|
|
43
|
+
return res.status(409).json({ message: "Duplicate email" });
|
|
44
|
+
}
|
|
45
|
+
return res.status(500).json({ message: error.message });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const updateStudent = async (req, res) => {
|
|
50
|
+
try {
|
|
51
|
+
const { fullName, gender, className, phone, email } = req.body;
|
|
52
|
+
const student = await Student.findById(req.params.id);
|
|
53
|
+
if (!student) return res.status(404).json({ message: "Student not found" });
|
|
54
|
+
if (fullName !== undefined) student.fullName = String(fullName).trim();
|
|
55
|
+
if (gender !== undefined) {
|
|
56
|
+
if (!["Male", "Female", "Other"].includes(gender)) {
|
|
57
|
+
return res.status(400).json({ message: "Invalid gender" });
|
|
58
|
+
}
|
|
59
|
+
student.gender = gender;
|
|
60
|
+
}
|
|
61
|
+
if (className !== undefined) student.className = String(className).trim();
|
|
62
|
+
if (phone !== undefined) student.phone = String(phone).trim();
|
|
63
|
+
if (email !== undefined) student.email = String(email).trim().toLowerCase();
|
|
64
|
+
await student.save();
|
|
65
|
+
return res.json(student);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return res.status(500).json({ message: error.message });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const deleteStudent = async (req, res) => {
|
|
72
|
+
try {
|
|
73
|
+
const Borrow = require("../models/Borrow");
|
|
74
|
+
const active = await Borrow.exists({ student: req.params.id, returnedAt: null });
|
|
75
|
+
if (active) {
|
|
76
|
+
return res.status(409).json({ message: "Student has active borrows; return books first" });
|
|
77
|
+
}
|
|
78
|
+
const student = await Student.findByIdAndDelete(req.params.id);
|
|
79
|
+
if (!student) return res.status(404).json({ message: "Student not found" });
|
|
80
|
+
return res.json({ message: "Deleted" });
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return res.status(500).json({ message: error.message });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
listStudents,
|
|
88
|
+
getStudent,
|
|
89
|
+
createStudent,
|
|
90
|
+
updateStudent,
|
|
91
|
+
deleteStudent,
|
|
92
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const bcrypt = require("bcryptjs");
|
|
2
|
+
const User = require("./models/User");
|
|
3
|
+
const Student = require("./models/Student");
|
|
4
|
+
const Book = require("./models/Book");
|
|
5
|
+
|
|
6
|
+
async function ensureSeedData() {
|
|
7
|
+
let log = [];
|
|
8
|
+
|
|
9
|
+
const userPairs = [
|
|
10
|
+
{ username: "admin", email: "admin@exam.local", password: "admin123", role: "admin" },
|
|
11
|
+
{ username: "librarian", email: "librarian@exam.local", password: "librarian123", role: "librarian" },
|
|
12
|
+
];
|
|
13
|
+
let usersCreated = 0;
|
|
14
|
+
for (const { username, email, password, role } of userPairs) {
|
|
15
|
+
const exists = await User.findOne({ username });
|
|
16
|
+
if (exists) continue;
|
|
17
|
+
await User.create({
|
|
18
|
+
username,
|
|
19
|
+
email,
|
|
20
|
+
passwordHash: await bcrypt.hash(password, 10),
|
|
21
|
+
role,
|
|
22
|
+
});
|
|
23
|
+
usersCreated += 1;
|
|
24
|
+
}
|
|
25
|
+
if (usersCreated) log.push(`${usersCreated} user(s)`);
|
|
26
|
+
|
|
27
|
+
if ((await Student.countDocuments()) === 0) {
|
|
28
|
+
await Student.create([
|
|
29
|
+
{
|
|
30
|
+
fullName: "Marie Uwase",
|
|
31
|
+
gender: "Female",
|
|
32
|
+
className: "Senior 3",
|
|
33
|
+
phone: "+250788100001",
|
|
34
|
+
email: "marie.demo@school.test",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
fullName: "David Nkurunziza",
|
|
38
|
+
gender: "Male",
|
|
39
|
+
className: "Senior 2",
|
|
40
|
+
phone: "+250788100002",
|
|
41
|
+
email: "david.demo@school.test",
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
log.push("2 students");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if ((await Book.countDocuments()) === 0) {
|
|
48
|
+
await Book.create([
|
|
49
|
+
{
|
|
50
|
+
title: "Computer Science Basics",
|
|
51
|
+
author: "Teaching Team",
|
|
52
|
+
category: "Textbook",
|
|
53
|
+
quantity: 5,
|
|
54
|
+
publishedYear: 2021,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "Stories for Young Readers",
|
|
58
|
+
author: "A. Mukamana",
|
|
59
|
+
category: "Literature",
|
|
60
|
+
quantity: 8,
|
|
61
|
+
publishedYear: 2019,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
log.push("2 books");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (log.length) {
|
|
68
|
+
console.log(`LMS seed: created ${log.join(", ")}.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = ensureSeedData;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const requireAuth = (req, res, next) => {
|
|
2
|
+
if (!req.session.userId) {
|
|
3
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
4
|
+
}
|
|
5
|
+
return next();
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const requireAdmin = (req, res, next) => {
|
|
9
|
+
if (!req.session.userId) {
|
|
10
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
11
|
+
}
|
|
12
|
+
if (req.session.role !== "admin") {
|
|
13
|
+
return res.status(403).json({ message: "Admin only" });
|
|
14
|
+
}
|
|
15
|
+
return next();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const requireLibrarian = (req, res, next) => {
|
|
20
|
+
if (!req.session.userId) {
|
|
21
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
22
|
+
}
|
|
23
|
+
if (req.session.role !== "librarian" && req.session.role !== "admin") {
|
|
24
|
+
return res.status(403).json({ message: "Librarian or admin required" });
|
|
25
|
+
}
|
|
26
|
+
return next();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports = { requireAuth, requireAdmin, requireLibrarian };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const bookSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
title: { type: String, required: true, trim: true },
|
|
6
|
+
author: { type: String, required: true, trim: true },
|
|
7
|
+
category: { type: String, required: true, trim: true },
|
|
8
|
+
quantity: { type: Number, required: true, min: 0, default: 0 },
|
|
9
|
+
publishedYear: { type: Number, required: true, min: 1000, max: 9999 },
|
|
10
|
+
},
|
|
11
|
+
{ timestamps: true }
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
module.exports = mongoose.model("Book", bookSchema);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const borrowSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
student: { type: mongoose.Schema.Types.ObjectId, ref: "Student", required: true },
|
|
6
|
+
book: { type: mongoose.Schema.Types.ObjectId, ref: "Book", required: true },
|
|
7
|
+
borrowDate: { type: Date, required: true },
|
|
8
|
+
returnDueDate: { type: Date, required: true },
|
|
9
|
+
returnedAt: { type: Date, default: null },
|
|
10
|
+
},
|
|
11
|
+
{ timestamps: true }
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
borrowSchema.index({ student: 1, book: 1, returnedAt: 1 });
|
|
15
|
+
|
|
16
|
+
module.exports = mongoose.model("Borrow", borrowSchema);
|