From 6c0dc184cbcf8d2970bccd464ed84ba065e3d1b2 Mon Sep 17 00:00:00 2001 From: m7338ohd-debug Date: Wed, 8 Jul 2026 11:38:24 +0530 Subject: [PATCH] new feautres implemnted --- ...883ce1217f62a49f94203b42caa131d-audit.json | 30 ----- ...8c8046075bb4cb64c11b1f8d919853c-audit.json | 30 ----- package-lock.json | 7 - package.json | 2 + .../authentication/access/role.routes.js | 126 ++++++++++++++++++ .../authentication/users/user.routes.js | 96 +++++++++++++ src/features/index.js | 18 --- src/features/integrations/index.js | 8 -- .../integrations/integrations/index.js | 5 - .../integrations/integration.controller.js | 50 ------- .../integrations/integration.model.js | 38 ------ .../integrations/integration.repository.js | 30 ----- .../integrations/integration.routes.js | 126 ------------------ .../integrations/integration.service.js | 75 ----------- .../integrations/integration.validation.js | 32 ----- src/features/inventory/index.js | 8 -- src/features/inventory/inventory/index.js | 5 - .../inventory/inventory.controller.js | 50 ------- .../inventory/inventory/inventory.model.js | 38 ------ .../inventory/inventory.repository.js | 30 ----- .../inventory/inventory/inventory.routes.js | 126 ------------------ .../inventory/inventory/inventory.service.js | 76 ----------- .../inventory/inventory.validation.js | 32 ----- src/features/localization/index.js | 8 -- .../localization/localization/index.js | 5 - .../localization/localization.controller.js | 50 ------- .../localization/localization.model.js | 38 ------ .../localization/localization.repository.js | 30 ----- .../localization/localization.routes.js | 126 ------------------ .../localization/localization.service.js | 75 ----------- .../localization/localization.validation.js | 32 ----- .../media/assetFamilies/assetFamily.routes.js | 107 +++++++++++++++ .../media/assetTypes/assetType.routes.js | 107 +++++++++++++++ src/features/media/assets/asset.routes.js | 107 +++++++++++++++ src/features/notifications/index.js | 8 -- .../notifications/notifications/index.js | 5 - .../notifications/notification.controller.js | 50 ------- .../notifications/notification.model.js | 38 ------ .../notifications/notification.repository.js | 30 ----- .../notifications/notification.routes.js | 126 ------------------ .../notifications/notification.service.js | 75 ----------- .../notifications/notification.validation.js | 32 ----- .../organization/org/tenant.routes.js | 96 +++++++++++++ src/features/pricing/index.js | 8 -- src/features/pricing/pricing/index.js | 5 - .../pricing/pricing/pricing.controller.js | 50 ------- src/features/pricing/pricing/pricing.model.js | 38 ------ .../pricing/pricing/pricing.repository.js | 30 ----- .../pricing/pricing/pricing.routes.js | 126 ------------------ .../pricing/pricing/pricing.service.js | 75 ----------- .../pricing/pricing/pricing.validation.js | 32 ----- .../products/approvals/approval.controller.js | 50 ------- .../products/approvals/approval.model.js | 38 ------ .../products/approvals/approval.repository.js | 30 ----- .../products/approvals/approval.routes.js | 126 ------------------ .../products/approvals/approval.service.js | 75 ----------- .../products/approvals/approval.validation.js | 32 ----- src/features/products/approvals/index.js | 5 - .../products/bundles/bundle.controller.js | 50 ------- src/features/products/bundles/bundle.model.js | 38 ------ .../products/bundles/bundle.repository.js | 30 ----- .../products/bundles/bundle.routes.js | 126 ------------------ .../products/bundles/bundle.service.js | 75 ----------- .../products/bundles/bundle.validation.js | 32 ----- src/features/products/bundles/index.js | 5 - .../configurableProduct.controller.js | 50 ------- .../configurableProduct.model.js | 38 ------ .../configurableProduct.repository.js | 30 ----- .../configurableProduct.routes.js | 126 ------------------ .../configurableProduct.service.js | 75 ----------- .../configurableProduct.validation.js | 32 ----- .../products/configurableProducts/index.js | 5 - .../digitalProduct.controller.js | 50 ------- .../digitalProducts/digitalProduct.model.js | 38 ------ .../digitalProduct.repository.js | 30 ----- .../digitalProducts/digitalProduct.routes.js | 126 ------------------ .../digitalProducts/digitalProduct.service.js | 75 ----------- .../digitalProduct.validation.js | 32 ----- .../products/digitalProducts/index.js | 5 - .../products/families/family.controller.js | 50 ------- .../products/families/family.model.js | 55 -------- .../products/families/family.repository.js | 34 ----- .../products/families/family.routes.js | 62 --------- .../products/families/family.service.js | 72 ---------- .../products/families/family.validation.js | 36 ----- src/features/products/index.js | 16 --- src/features/products/lifecycle/index.js | 5 - .../lifecycle/lifecycle.controller.js | 50 ------- .../products/lifecycle/lifecycle.model.js | 38 ------ .../lifecycle/lifecycle.repository.js | 30 ----- .../products/lifecycle/lifecycle.routes.js | 126 ------------------ .../products/lifecycle/lifecycle.service.js | 75 ----------- .../lifecycle/lifecycle.validation.js | 32 ----- src/features/products/publishing/index.js | 5 - .../publishing/publishing.controller.js | 50 ------- .../products/publishing/publishing.model.js | 38 ------ .../publishing/publishing.repository.js | 30 ----- .../products/publishing/publishing.routes.js | 126 ------------------ .../products/publishing/publishing.service.js | 75 ----------- .../publishing/publishing.validation.js | 32 ----- src/features/products/variants/index.js | 5 - .../products/variants/variant.controller.js | 50 ------- .../products/variants/variant.model.js | 38 ------ .../products/variants/variant.repository.js | 30 ----- .../products/variants/variant.routes.js | 126 ------------------ .../products/variants/variant.service.js | 75 ----------- .../products/variants/variant.validation.js | 32 ----- src/features/reports/index.js | 8 -- src/features/reports/reports/index.js | 5 - .../reports/reports/report.controller.js | 50 ------- src/features/reports/reports/report.model.js | 38 ------ .../reports/reports/report.repository.js | 30 ----- src/features/reports/reports/report.routes.js | 126 ------------------ .../reports/reports/report.service.js | 75 ----------- .../reports/reports/report.validation.js | 32 ----- src/features/suppliers/index.js | 8 -- src/features/suppliers/suppliers/index.js | 5 - .../suppliers/supplier.controller.js | 50 ------- .../suppliers/suppliers/supplier.model.js | 38 ------ .../suppliers/supplier.repository.js | 30 ----- .../suppliers/suppliers/supplier.routes.js | 126 ------------------ .../suppliers/suppliers/supplier.service.js | 75 ----------- .../suppliers/supplier.validation.js | 32 ----- src/features/units/index.js | 8 -- src/features/units/units/unit.controller.js | 50 ------- src/features/units/units/unit.model.js | 29 ---- src/features/units/units/unit.repository.js | 32 ----- src/features/units/units/unit.routes.js | 14 -- src/features/units/units/unit.service.js | 72 ---------- src/features/workflows/index.js | 8 -- src/features/workflows/workflows/index.js | 5 - .../workflows/workflow.controller.js | 50 ------- .../workflows/workflows/workflow.model.js | 38 ------ .../workflows/workflow.repository.js | 30 ----- .../workflows/workflows/workflow.routes.js | 126 ------------------ .../workflows/workflows/workflow.service.js | 75 ----------- .../workflows/workflow.validation.js | 32 ----- src/shared/database/connection.js | 8 +- src/shared/database/models.js | 41 ------ src/shared/utils/logger.js | 29 ++-- 140 files changed, 650 insertions(+), 6089 deletions(-) delete mode 100644 logs/.3fa4d5e91883ce1217f62a49f94203b42caa131d-audit.json delete mode 100644 logs/.944c2a6e38c8046075bb4cb64c11b1f8d919853c-audit.json delete mode 100644 src/features/integrations/index.js delete mode 100644 src/features/integrations/integrations/index.js delete mode 100644 src/features/integrations/integrations/integration.controller.js delete mode 100644 src/features/integrations/integrations/integration.model.js delete mode 100644 src/features/integrations/integrations/integration.repository.js delete mode 100644 src/features/integrations/integrations/integration.routes.js delete mode 100644 src/features/integrations/integrations/integration.service.js delete mode 100644 src/features/integrations/integrations/integration.validation.js delete mode 100644 src/features/inventory/index.js delete mode 100644 src/features/inventory/inventory/index.js delete mode 100644 src/features/inventory/inventory/inventory.controller.js delete mode 100644 src/features/inventory/inventory/inventory.model.js delete mode 100644 src/features/inventory/inventory/inventory.repository.js delete mode 100644 src/features/inventory/inventory/inventory.routes.js delete mode 100644 src/features/inventory/inventory/inventory.service.js delete mode 100644 src/features/inventory/inventory/inventory.validation.js delete mode 100644 src/features/localization/index.js delete mode 100644 src/features/localization/localization/index.js delete mode 100644 src/features/localization/localization/localization.controller.js delete mode 100644 src/features/localization/localization/localization.model.js delete mode 100644 src/features/localization/localization/localization.repository.js delete mode 100644 src/features/localization/localization/localization.routes.js delete mode 100644 src/features/localization/localization/localization.service.js delete mode 100644 src/features/localization/localization/localization.validation.js delete mode 100644 src/features/notifications/index.js delete mode 100644 src/features/notifications/notifications/index.js delete mode 100644 src/features/notifications/notifications/notification.controller.js delete mode 100644 src/features/notifications/notifications/notification.model.js delete mode 100644 src/features/notifications/notifications/notification.repository.js delete mode 100644 src/features/notifications/notifications/notification.routes.js delete mode 100644 src/features/notifications/notifications/notification.service.js delete mode 100644 src/features/notifications/notifications/notification.validation.js delete mode 100644 src/features/pricing/index.js delete mode 100644 src/features/pricing/pricing/index.js delete mode 100644 src/features/pricing/pricing/pricing.controller.js delete mode 100644 src/features/pricing/pricing/pricing.model.js delete mode 100644 src/features/pricing/pricing/pricing.repository.js delete mode 100644 src/features/pricing/pricing/pricing.routes.js delete mode 100644 src/features/pricing/pricing/pricing.service.js delete mode 100644 src/features/pricing/pricing/pricing.validation.js delete mode 100644 src/features/products/approvals/approval.controller.js delete mode 100644 src/features/products/approvals/approval.model.js delete mode 100644 src/features/products/approvals/approval.repository.js delete mode 100644 src/features/products/approvals/approval.routes.js delete mode 100644 src/features/products/approvals/approval.service.js delete mode 100644 src/features/products/approvals/approval.validation.js delete mode 100644 src/features/products/approvals/index.js delete mode 100644 src/features/products/bundles/bundle.controller.js delete mode 100644 src/features/products/bundles/bundle.model.js delete mode 100644 src/features/products/bundles/bundle.repository.js delete mode 100644 src/features/products/bundles/bundle.routes.js delete mode 100644 src/features/products/bundles/bundle.service.js delete mode 100644 src/features/products/bundles/bundle.validation.js delete mode 100644 src/features/products/bundles/index.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.controller.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.model.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.repository.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.routes.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.service.js delete mode 100644 src/features/products/configurableProducts/configurableProduct.validation.js delete mode 100644 src/features/products/configurableProducts/index.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.controller.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.model.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.repository.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.routes.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.service.js delete mode 100644 src/features/products/digitalProducts/digitalProduct.validation.js delete mode 100644 src/features/products/digitalProducts/index.js delete mode 100644 src/features/products/families/family.controller.js delete mode 100644 src/features/products/families/family.model.js delete mode 100644 src/features/products/families/family.repository.js delete mode 100644 src/features/products/families/family.routes.js delete mode 100644 src/features/products/families/family.service.js delete mode 100644 src/features/products/families/family.validation.js delete mode 100644 src/features/products/lifecycle/index.js delete mode 100644 src/features/products/lifecycle/lifecycle.controller.js delete mode 100644 src/features/products/lifecycle/lifecycle.model.js delete mode 100644 src/features/products/lifecycle/lifecycle.repository.js delete mode 100644 src/features/products/lifecycle/lifecycle.routes.js delete mode 100644 src/features/products/lifecycle/lifecycle.service.js delete mode 100644 src/features/products/lifecycle/lifecycle.validation.js delete mode 100644 src/features/products/publishing/index.js delete mode 100644 src/features/products/publishing/publishing.controller.js delete mode 100644 src/features/products/publishing/publishing.model.js delete mode 100644 src/features/products/publishing/publishing.repository.js delete mode 100644 src/features/products/publishing/publishing.routes.js delete mode 100644 src/features/products/publishing/publishing.service.js delete mode 100644 src/features/products/publishing/publishing.validation.js delete mode 100644 src/features/products/variants/index.js delete mode 100644 src/features/products/variants/variant.controller.js delete mode 100644 src/features/products/variants/variant.model.js delete mode 100644 src/features/products/variants/variant.repository.js delete mode 100644 src/features/products/variants/variant.routes.js delete mode 100644 src/features/products/variants/variant.service.js delete mode 100644 src/features/products/variants/variant.validation.js delete mode 100644 src/features/reports/index.js delete mode 100644 src/features/reports/reports/index.js delete mode 100644 src/features/reports/reports/report.controller.js delete mode 100644 src/features/reports/reports/report.model.js delete mode 100644 src/features/reports/reports/report.repository.js delete mode 100644 src/features/reports/reports/report.routes.js delete mode 100644 src/features/reports/reports/report.service.js delete mode 100644 src/features/reports/reports/report.validation.js delete mode 100644 src/features/suppliers/index.js delete mode 100644 src/features/suppliers/suppliers/index.js delete mode 100644 src/features/suppliers/suppliers/supplier.controller.js delete mode 100644 src/features/suppliers/suppliers/supplier.model.js delete mode 100644 src/features/suppliers/suppliers/supplier.repository.js delete mode 100644 src/features/suppliers/suppliers/supplier.routes.js delete mode 100644 src/features/suppliers/suppliers/supplier.service.js delete mode 100644 src/features/suppliers/suppliers/supplier.validation.js delete mode 100644 src/features/units/index.js delete mode 100644 src/features/units/units/unit.controller.js delete mode 100644 src/features/units/units/unit.model.js delete mode 100644 src/features/units/units/unit.repository.js delete mode 100644 src/features/units/units/unit.routes.js delete mode 100644 src/features/units/units/unit.service.js delete mode 100644 src/features/workflows/index.js delete mode 100644 src/features/workflows/workflows/index.js delete mode 100644 src/features/workflows/workflows/workflow.controller.js delete mode 100644 src/features/workflows/workflows/workflow.model.js delete mode 100644 src/features/workflows/workflows/workflow.repository.js delete mode 100644 src/features/workflows/workflows/workflow.routes.js delete mode 100644 src/features/workflows/workflows/workflow.service.js delete mode 100644 src/features/workflows/workflows/workflow.validation.js diff --git a/logs/.3fa4d5e91883ce1217f62a49f94203b42caa131d-audit.json b/logs/.3fa4d5e91883ce1217f62a49f94203b42caa131d-audit.json deleted file mode 100644 index e07c2da..0000000 --- a/logs/.3fa4d5e91883ce1217f62a49f94203b42caa131d-audit.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "keep": { - "days": true, - "amount": 14 - }, - "auditLog": "logs\\.3fa4d5e91883ce1217f62a49f94203b42caa131d-audit.json", - "files": [ - { - "date": 1782885016196, - "name": "logs\\combined-2026-07-01.log", - "hash": "62273be471fbf03240935eebb5eaf8487e7a3002b6cced421c983245646bc21a" - }, - { - "date": 1782968983048, - "name": "logs\\combined-2026-07-02.log", - "hash": "10138c0f35436a800870f14a317b542645e7976bcd44030300d436a715a20c36" - }, - { - "date": 1783058300242, - "name": "logs\\combined-2026-07-03.log", - "hash": "a0e79e7be8f5ef13f7e6e8483c8bb663b1c7ddeb1eaa188152cda3f015df5203" - }, - { - "date": 1783142857411, - "name": "logs\\combined-2026-07-04.log", - "hash": "df5726dddf64ecbb358dc871efc7f6fa558f95b33fec683e6eef801c4d9f7e4a" - } - ], - "hashType": "sha256" -} \ No newline at end of file diff --git a/logs/.944c2a6e38c8046075bb4cb64c11b1f8d919853c-audit.json b/logs/.944c2a6e38c8046075bb4cb64c11b1f8d919853c-audit.json deleted file mode 100644 index ce5cf73..0000000 --- a/logs/.944c2a6e38c8046075bb4cb64c11b1f8d919853c-audit.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "keep": { - "days": true, - "amount": 14 - }, - "auditLog": "logs\\.944c2a6e38c8046075bb4cb64c11b1f8d919853c-audit.json", - "files": [ - { - "date": 1782885016194, - "name": "logs\\error-2026-07-01.log", - "hash": "3dc68d8ca2e67e313b2363c163e011da72b07deaf5d0f5736607ec0850b50e9b" - }, - { - "date": 1782968983045, - "name": "logs\\error-2026-07-02.log", - "hash": "bf64fe21cbfba23af08772bef924ee896b52bcbf80bb4e87b6f7c5fb125e38aa" - }, - { - "date": 1783058300224, - "name": "logs\\error-2026-07-03.log", - "hash": "9d7b2b6bae80886841b6c099d2312d2fe37fd6e58d4eb934668e9c62e4e38bc1" - }, - { - "date": 1783142857406, - "name": "logs\\error-2026-07-04.log", - "hash": "7d2caa5cd525a8a119155e3c48baeded2d8741b61d934b266de04b9140095740" - } - ], - "hashType": "sha256" -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bf8e18a..5678e20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2346,13 +2346,6 @@ "fn.name": "1.x.x" } }, - "node_modules/openapi-types": { - "version": "12.1.3", - "resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.1.3.tgz", - "integrity": "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==", - "license": "MIT", - "peer": true - }, "node_modules/package-json-from-dist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", diff --git a/package.json b/package.json index 90ce6f1..f2c7403 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "scripts": { "start": "cross-env NODE_ENV=production node index.js", "dev": "cross-env NODE_ENV=development nodemon index.js", + "test": "cross-env NODE_ENV=test nodemon index.js", + "local": "cross-env NODE_ENV=local nodemon index.js", "start:local": "cross-env NODE_ENV=local nodemon index.js", "db:migrate:local": "cross-env NODE_ENV=local sequelize-cli db:migrate --config src/shared/config/database.config.cjs --migrations-path src/migrations --models-path src/shared/database", "db:seed:local": "cross-env NODE_ENV=local sequelize-cli db:seed:all --config src/shared/config/database.config.cjs --seeders-path src/seeders --models-path src/shared/database", diff --git a/src/features/authentication/access/role.routes.js b/src/features/authentication/access/role.routes.js index 79a4bef..69e3786 100644 --- a/src/features/authentication/access/role.routes.js +++ b/src/features/authentication/access/role.routes.js @@ -5,6 +5,20 @@ import { authorize } from '../../../shared/middleware/permission.middleware.js'; const router = Router(); +/** + * @swagger + * /api/v1/roles: + * get: + * summary: Retrieve all roles + * tags: [Roles] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -12,6 +26,24 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/roles/by-tenant/{tenantId}: + * get: + * summary: Retrieve roles by tenant + * tags: [Roles] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: tenantId + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + */ router.get( '/by-tenant/:tenantId', authenticate, @@ -19,6 +51,18 @@ router.get( controller.getByTenant ); +/** + * @swagger + * /api/v1/roles/permissions: + * get: + * summary: Retrieve all permission nodes + * tags: [Roles] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + */ router.get( '/permissions', authenticate, @@ -26,6 +70,26 @@ router.get( controller.getPermissions ); +/** + * @swagger + * /api/v1/roles/{id}: + * get: + * summary: Retrieve a single role + * tags: [Roles] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -33,6 +97,32 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/roles: + * post: + * summary: Create a new role + * tags: [Roles] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [name] + * properties: + * name: + * type: string + * permissions: + * type: array + * items: + * type: string + * responses: + * 201: + * description: Created + */ router.post( '/', authenticate, @@ -40,6 +130,24 @@ router.post( controller.create ); +/** + * @swagger + * /api/v1/roles/{id}: + * put: + * summary: Update a role + * tags: [Roles] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + */ router.put( '/:id', authenticate, @@ -47,6 +155,24 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/roles/{id}: + * delete: + * summary: Delete a role + * tags: [Roles] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + */ router.delete( '/:id', authenticate, diff --git a/src/features/authentication/users/user.routes.js b/src/features/authentication/users/user.routes.js index a1ca998..550d42f 100644 --- a/src/features/authentication/users/user.routes.js +++ b/src/features/authentication/users/user.routes.js @@ -5,6 +5,20 @@ import { authorize } from '../../../shared/middleware/permission.middleware.js'; const router = Router(); +/** + * @swagger + * /api/v1/users: + * get: + * summary: Retrieve all users + * tags: [Users] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -12,6 +26,26 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/users/{id}: + * get: + * summary: Retrieve a single user + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -19,6 +53,32 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/users/invite: + * post: + * summary: Invite a new user + * tags: [Users] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [email, role_id] + * properties: + * email: + * type: string + * role_id: + * type: string + * responses: + * 201: + * description: Invitation sent + * 400: + * description: Validation Error + */ router.post( '/invite', authenticate, @@ -26,6 +86,24 @@ router.post( controller.invite ); +/** + * @swagger + * /api/v1/users/{id}: + * put: + * summary: Update a user + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + */ router.put( '/:id', authenticate, @@ -33,6 +111,24 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/users/{id}: + * delete: + * summary: Delete a user + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + */ router.delete( '/:id', authenticate, diff --git a/src/features/index.js b/src/features/index.js index e6cd96b..51fce0f 100644 --- a/src/features/index.js +++ b/src/features/index.js @@ -7,20 +7,11 @@ import categoriesRouter from './categories/index.js'; import brandsRouter from './brands/index.js'; import attributesRouter from './attributes/index.js'; import mediaRouter from './media/index.js'; -import pricingRouter from './pricing/index.js'; -import inventoryRouter from './inventory/index.js'; -import suppliersRouter from './suppliers/index.js'; -import localizationRouter from './localization/index.js'; -import workflowsRouter from './workflows/index.js'; -import integrationsRouter from './integrations/index.js'; import channelsRouter from './channels/index.js'; import importsRouter from './imports/index.js'; import exportsRouter from './exports/index.js'; -import notificationsRouter from './notifications/index.js'; -import reportsRouter from './reports/index.js'; import settingsRouter from './settings/index.js'; import auditLogsRouter from './auditLogs/index.js'; -import unitsRouter from './units/index.js'; export default function registerRoutes(app) { app.use('/api/v1', authenticationRouter); @@ -32,18 +23,9 @@ export default function registerRoutes(app) { app.use('/api/v1', brandsRouter); app.use('/api/v1', attributesRouter); app.use('/api/v1', mediaRouter); - app.use('/api/v1', pricingRouter); - app.use('/api/v1', inventoryRouter); - app.use('/api/v1', suppliersRouter); - app.use('/api/v1', localizationRouter); - app.use('/api/v1', workflowsRouter); - app.use('/api/v1', integrationsRouter); app.use('/api/v1', channelsRouter); app.use('/api/v1', importsRouter); app.use('/api/v1', exportsRouter); - app.use('/api/v1', notificationsRouter); - app.use('/api/v1', reportsRouter); app.use('/api/v1', settingsRouter); app.use('/api/v1', auditLogsRouter); - app.use('/api/v1', unitsRouter); } diff --git a/src/features/integrations/index.js b/src/features/integrations/index.js deleted file mode 100644 index 02ad787..0000000 --- a/src/features/integrations/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import integrationsRouter from './integrations/integration.routes.js'; - -const router = Router(); - -router.use('/integrations', integrationsRouter); - -export default router; diff --git a/src/features/integrations/integrations/index.js b/src/features/integrations/integrations/index.js deleted file mode 100644 index ae38ae7..0000000 --- a/src/features/integrations/integrations/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as integrationRoutes } from './integration.routes.js'; -export { default as integrationController } from './integration.controller.js'; -export { default as integrationService } from './integration.service.js'; -export { default as integrationRepository } from './integration.repository.js'; -export { default as integrationModel } from './integration.model.js'; diff --git a/src/features/integrations/integrations/integration.controller.js b/src/features/integrations/integrations/integration.controller.js deleted file mode 100644 index 240af68..0000000 --- a/src/features/integrations/integrations/integration.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './integration.service.js'; - -export class IntegrationController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Integration deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new IntegrationController(); diff --git a/src/features/integrations/integrations/integration.model.js b/src/features/integrations/integrations/integration.model.js deleted file mode 100644 index 4778600..0000000 --- a/src/features/integrations/integrations/integration.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Integration extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Integration.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Integration', - tableName: 'integrations', - timestamps: true, - underscored: true - }); - - return Integration; -}; diff --git a/src/features/integrations/integrations/integration.repository.js b/src/features/integrations/integrations/integration.repository.js deleted file mode 100644 index 1f34fe0..0000000 --- a/src/features/integrations/integrations/integration.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class IntegrationRepository { - async findAll(options = {}) { - return await models.Integration.findAll(options); - } - - async findById(id, options = {}) { - return await models.Integration.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Integration.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new IntegrationRepository(); diff --git a/src/features/integrations/integrations/integration.routes.js b/src/features/integrations/integrations/integration.routes.js deleted file mode 100644 index 8c8351f..0000000 --- a/src/features/integrations/integrations/integration.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './integration.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './integration.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/integrations: - * get: - * summary: Retrieve all integrations - * tags: [Integrations] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:integrations']), - controller.getAll -); - -/** - * @swagger - * /api/v1/integrations/{id}: - * get: - * summary: Retrieve a single integration - * tags: [Integrations] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:integrations']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/integrations: - * post: - * summary: Create a integration - * tags: [Integrations] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:integrations']), - createValidation, - validate, - audit('CREATE_INTEGRATION'), - controller.create -); - -/** - * @swagger - * /api/v1/integrations/{id}: - * put: - * summary: Update a integration - * tags: [Integrations] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:integrations']), - updateValidation, - validate, - audit('UPDATE_INTEGRATION'), - controller.update -); - -/** - * @swagger - * /api/v1/integrations/{id}: - * delete: - * summary: Delete a integration - * tags: [Integrations] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:integrations']), - deleteValidation, - validate, - audit('DELETE_INTEGRATION'), - controller.delete -); - -export default router; diff --git a/src/features/integrations/integrations/integration.service.js b/src/features/integrations/integrations/integration.service.js deleted file mode 100644 index 5c61e20..0000000 --- a/src/features/integrations/integrations/integration.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './integration.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class IntegrationService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Integration not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('integration:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Integration', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Integration not found'); - } - - SocketService.broadcast('integration:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Integration', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Integration not found'); - } - - SocketService.broadcast('integration:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Integration', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new IntegrationService(); diff --git a/src/features/integrations/integrations/integration.validation.js b/src/features/integrations/integrations/integration.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/integrations/integrations/integration.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/inventory/index.js b/src/features/inventory/index.js deleted file mode 100644 index 8718bc8..0000000 --- a/src/features/inventory/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import inventoryRouter from './inventory/inventory.routes.js'; - -const router = Router(); - -router.use('/inventory', inventoryRouter); - -export default router; diff --git a/src/features/inventory/inventory/index.js b/src/features/inventory/inventory/index.js deleted file mode 100644 index e5549d8..0000000 --- a/src/features/inventory/inventory/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as inventoryRoutes } from './inventory.routes.js'; -export { default as inventoryController } from './inventory.controller.js'; -export { default as inventoryService } from './inventory.service.js'; -export { default as inventoryRepository } from './inventory.repository.js'; -export { default as inventoryModel } from './inventory.model.js'; diff --git a/src/features/inventory/inventory/inventory.controller.js b/src/features/inventory/inventory/inventory.controller.js deleted file mode 100644 index 4ab8909..0000000 --- a/src/features/inventory/inventory/inventory.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './inventory.service.js'; - -export class InventoryController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Inventory deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new InventoryController(); diff --git a/src/features/inventory/inventory/inventory.model.js b/src/features/inventory/inventory/inventory.model.js deleted file mode 100644 index b3314a8..0000000 --- a/src/features/inventory/inventory/inventory.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Inventory extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Inventory.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Inventory', - tableName: 'inventorys', - timestamps: true, - underscored: true - }); - - return Inventory; -}; diff --git a/src/features/inventory/inventory/inventory.repository.js b/src/features/inventory/inventory/inventory.repository.js deleted file mode 100644 index eeb8172..0000000 --- a/src/features/inventory/inventory/inventory.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class InventoryRepository { - async findAll(options = {}) { - return await models.Inventory.findAll(options); - } - - async findById(id, options = {}) { - return await models.Inventory.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Inventory.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new InventoryRepository(); diff --git a/src/features/inventory/inventory/inventory.routes.js b/src/features/inventory/inventory/inventory.routes.js deleted file mode 100644 index ee88c4c..0000000 --- a/src/features/inventory/inventory/inventory.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './inventory.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './inventory.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/inventorys: - * get: - * summary: Retrieve all inventorys - * tags: [Inventorys] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:inventorys']), - controller.getAll -); - -/** - * @swagger - * /api/v1/inventorys/{id}: - * get: - * summary: Retrieve a single inventory - * tags: [Inventorys] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:inventorys']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/inventorys: - * post: - * summary: Create a inventory - * tags: [Inventorys] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:inventorys']), - createValidation, - validate, - audit('CREATE_INVENTORY'), - controller.create -); - -/** - * @swagger - * /api/v1/inventorys/{id}: - * put: - * summary: Update a inventory - * tags: [Inventorys] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:inventorys']), - updateValidation, - validate, - audit('UPDATE_INVENTORY'), - controller.update -); - -/** - * @swagger - * /api/v1/inventorys/{id}: - * delete: - * summary: Delete a inventory - * tags: [Inventorys] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:inventorys']), - deleteValidation, - validate, - audit('DELETE_INVENTORY'), - controller.delete -); - -export default router; diff --git a/src/features/inventory/inventory/inventory.service.js b/src/features/inventory/inventory/inventory.service.js deleted file mode 100644 index 518ed63..0000000 --- a/src/features/inventory/inventory/inventory.service.js +++ /dev/null @@ -1,76 +0,0 @@ -import repository from './inventory.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; -import { ApiError } from '../../../utils/helpers/ApiError.utils.js'; - -export class InventoryService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new ApiError(404, 'Inventory not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('inventory:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Inventory', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new ApiError(404, 'Inventory not found'); - } - - SocketService.broadcast('inventory:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Inventory', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new ApiError(404, 'Inventory not found'); - } - - SocketService.broadcast('inventory:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Inventory', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new InventoryService(); diff --git a/src/features/inventory/inventory/inventory.validation.js b/src/features/inventory/inventory/inventory.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/inventory/inventory/inventory.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/localization/index.js b/src/features/localization/index.js deleted file mode 100644 index d000cf0..0000000 --- a/src/features/localization/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import localizationRouter from './localization/localization.routes.js'; - -const router = Router(); - -router.use('/localization', localizationRouter); - -export default router; diff --git a/src/features/localization/localization/index.js b/src/features/localization/localization/index.js deleted file mode 100644 index 4d65153..0000000 --- a/src/features/localization/localization/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as localizationRoutes } from './localization.routes.js'; -export { default as localizationController } from './localization.controller.js'; -export { default as localizationService } from './localization.service.js'; -export { default as localizationRepository } from './localization.repository.js'; -export { default as localizationModel } from './localization.model.js'; diff --git a/src/features/localization/localization/localization.controller.js b/src/features/localization/localization/localization.controller.js deleted file mode 100644 index 6fedec5..0000000 --- a/src/features/localization/localization/localization.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './localization.service.js'; - -export class LocalizationController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Localization deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new LocalizationController(); diff --git a/src/features/localization/localization/localization.model.js b/src/features/localization/localization/localization.model.js deleted file mode 100644 index da3d3ce..0000000 --- a/src/features/localization/localization/localization.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Localization extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Localization.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Localization', - tableName: 'localizations', - timestamps: true, - underscored: true - }); - - return Localization; -}; diff --git a/src/features/localization/localization/localization.repository.js b/src/features/localization/localization/localization.repository.js deleted file mode 100644 index aa65755..0000000 --- a/src/features/localization/localization/localization.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class LocalizationRepository { - async findAll(options = {}) { - return await models.Localization.findAll(options); - } - - async findById(id, options = {}) { - return await models.Localization.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Localization.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new LocalizationRepository(); diff --git a/src/features/localization/localization/localization.routes.js b/src/features/localization/localization/localization.routes.js deleted file mode 100644 index 13c520d..0000000 --- a/src/features/localization/localization/localization.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './localization.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './localization.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/localizations: - * get: - * summary: Retrieve all localizations - * tags: [Localizations] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:localizations']), - controller.getAll -); - -/** - * @swagger - * /api/v1/localizations/{id}: - * get: - * summary: Retrieve a single localization - * tags: [Localizations] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:localizations']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/localizations: - * post: - * summary: Create a localization - * tags: [Localizations] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:localizations']), - createValidation, - validate, - audit('CREATE_LOCALIZATION'), - controller.create -); - -/** - * @swagger - * /api/v1/localizations/{id}: - * put: - * summary: Update a localization - * tags: [Localizations] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:localizations']), - updateValidation, - validate, - audit('UPDATE_LOCALIZATION'), - controller.update -); - -/** - * @swagger - * /api/v1/localizations/{id}: - * delete: - * summary: Delete a localization - * tags: [Localizations] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:localizations']), - deleteValidation, - validate, - audit('DELETE_LOCALIZATION'), - controller.delete -); - -export default router; diff --git a/src/features/localization/localization/localization.service.js b/src/features/localization/localization/localization.service.js deleted file mode 100644 index 75642ff..0000000 --- a/src/features/localization/localization/localization.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './localization.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class LocalizationService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Localization not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('localization:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Localization', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Localization not found'); - } - - SocketService.broadcast('localization:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Localization', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Localization not found'); - } - - SocketService.broadcast('localization:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Localization', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new LocalizationService(); diff --git a/src/features/localization/localization/localization.validation.js b/src/features/localization/localization/localization.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/localization/localization/localization.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/media/assetFamilies/assetFamily.routes.js b/src/features/media/assetFamilies/assetFamily.routes.js index 3bf9c8f..9821cda 100644 --- a/src/features/media/assetFamilies/assetFamily.routes.js +++ b/src/features/media/assetFamilies/assetFamily.routes.js @@ -13,6 +13,20 @@ import { const router = Router(); +/** + * @swagger + * /api/v1/asset-families: + * get: + * summary: Retrieve all asset families + * tags: [Asset Families] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -20,6 +34,26 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/asset-families/{id}: + * get: + * summary: Retrieve a single asset family + * tags: [Asset Families] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -29,6 +63,30 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/asset-families: + * post: + * summary: Create a new asset family + * tags: [Asset Families] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [name] + * properties: + * name: + * type: string + * responses: + * 201: + * description: Created + * 400: + * description: Validation Error + */ router.post( '/', authenticate, @@ -39,6 +97,35 @@ router.post( controller.create ); +/** + * @swagger + * /api/v1/asset-families/{id}: + * put: + * summary: Update an asset family + * tags: [Asset Families] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.put( '/:id', authenticate, @@ -49,6 +136,26 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/asset-families/{id}: + * delete: + * summary: Delete an asset family + * tags: [Asset Families] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + * 404: + * description: Not Found + */ router.delete( '/:id', authenticate, diff --git a/src/features/media/assetTypes/assetType.routes.js b/src/features/media/assetTypes/assetType.routes.js index 78d82ca..7f013c2 100644 --- a/src/features/media/assetTypes/assetType.routes.js +++ b/src/features/media/assetTypes/assetType.routes.js @@ -13,6 +13,20 @@ import { const router = Router(); +/** + * @swagger + * /api/v1/asset-types: + * get: + * summary: Retrieve all asset types + * tags: [Asset Types] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -20,6 +34,26 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/asset-types/{id}: + * get: + * summary: Retrieve a single asset type + * tags: [Asset Types] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -29,6 +63,30 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/asset-types: + * post: + * summary: Create a new asset type + * tags: [Asset Types] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [name] + * properties: + * name: + * type: string + * responses: + * 201: + * description: Created + * 400: + * description: Validation Error + */ router.post( '/', authenticate, @@ -39,6 +97,35 @@ router.post( controller.create ); +/** + * @swagger + * /api/v1/asset-types/{id}: + * put: + * summary: Update an asset type + * tags: [Asset Types] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.put( '/:id', authenticate, @@ -49,6 +136,26 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/asset-types/{id}: + * delete: + * summary: Delete an asset type + * tags: [Asset Types] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + * 404: + * description: Not Found + */ router.delete( '/:id', authenticate, diff --git a/src/features/media/assets/asset.routes.js b/src/features/media/assets/asset.routes.js index 62f8b61..e11f35a 100644 --- a/src/features/media/assets/asset.routes.js +++ b/src/features/media/assets/asset.routes.js @@ -13,6 +13,20 @@ import { const router = Router(); +/** + * @swagger + * /api/v1/assets: + * get: + * summary: Retrieve all assets + * tags: [Assets] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -20,6 +34,26 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/assets/{id}: + * get: + * summary: Retrieve a single asset + * tags: [Assets] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -29,6 +63,30 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/assets: + * post: + * summary: Create a new asset + * tags: [Assets] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [name] + * properties: + * name: + * type: string + * responses: + * 201: + * description: Created + * 400: + * description: Validation Error + */ router.post( '/', authenticate, @@ -39,6 +97,35 @@ router.post( controller.create ); +/** + * @swagger + * /api/v1/assets/{id}: + * put: + * summary: Update an asset + * tags: [Assets] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.put( '/:id', authenticate, @@ -49,6 +136,26 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/assets/{id}: + * delete: + * summary: Delete an asset + * tags: [Assets] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + * 404: + * description: Not Found + */ router.delete( '/:id', authenticate, diff --git a/src/features/notifications/index.js b/src/features/notifications/index.js deleted file mode 100644 index dbfc181..0000000 --- a/src/features/notifications/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import notificationsRouter from './notifications/notification.routes.js'; - -const router = Router(); - -router.use('/notifications', notificationsRouter); - -export default router; diff --git a/src/features/notifications/notifications/index.js b/src/features/notifications/notifications/index.js deleted file mode 100644 index 19ef3f2..0000000 --- a/src/features/notifications/notifications/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as notificationRoutes } from './notification.routes.js'; -export { default as notificationController } from './notification.controller.js'; -export { default as notificationService } from './notification.service.js'; -export { default as notificationRepository } from './notification.repository.js'; -export { default as notificationModel } from './notification.model.js'; diff --git a/src/features/notifications/notifications/notification.controller.js b/src/features/notifications/notifications/notification.controller.js deleted file mode 100644 index 898e458..0000000 --- a/src/features/notifications/notifications/notification.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './notification.service.js'; - -export class NotificationController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Notification deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new NotificationController(); diff --git a/src/features/notifications/notifications/notification.model.js b/src/features/notifications/notifications/notification.model.js deleted file mode 100644 index 03779b0..0000000 --- a/src/features/notifications/notifications/notification.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Notification extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Notification.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Notification', - tableName: 'notifications', - timestamps: true, - underscored: true - }); - - return Notification; -}; diff --git a/src/features/notifications/notifications/notification.repository.js b/src/features/notifications/notifications/notification.repository.js deleted file mode 100644 index 95e9de8..0000000 --- a/src/features/notifications/notifications/notification.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class NotificationRepository { - async findAll(options = {}) { - return await models.Notification.findAll(options); - } - - async findById(id, options = {}) { - return await models.Notification.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Notification.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new NotificationRepository(); diff --git a/src/features/notifications/notifications/notification.routes.js b/src/features/notifications/notifications/notification.routes.js deleted file mode 100644 index 669f189..0000000 --- a/src/features/notifications/notifications/notification.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './notification.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './notification.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/notifications: - * get: - * summary: Retrieve all notifications - * tags: [Notifications] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:notifications']), - controller.getAll -); - -/** - * @swagger - * /api/v1/notifications/{id}: - * get: - * summary: Retrieve a single notification - * tags: [Notifications] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:notifications']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/notifications: - * post: - * summary: Create a notification - * tags: [Notifications] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:notifications']), - createValidation, - validate, - audit('CREATE_NOTIFICATION'), - controller.create -); - -/** - * @swagger - * /api/v1/notifications/{id}: - * put: - * summary: Update a notification - * tags: [Notifications] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:notifications']), - updateValidation, - validate, - audit('UPDATE_NOTIFICATION'), - controller.update -); - -/** - * @swagger - * /api/v1/notifications/{id}: - * delete: - * summary: Delete a notification - * tags: [Notifications] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:notifications']), - deleteValidation, - validate, - audit('DELETE_NOTIFICATION'), - controller.delete -); - -export default router; diff --git a/src/features/notifications/notifications/notification.service.js b/src/features/notifications/notifications/notification.service.js deleted file mode 100644 index b2e60d1..0000000 --- a/src/features/notifications/notifications/notification.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './notification.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class NotificationService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Notification not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('notification:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Notification', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Notification not found'); - } - - SocketService.broadcast('notification:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Notification', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Notification not found'); - } - - SocketService.broadcast('notification:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Notification', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new NotificationService(); diff --git a/src/features/notifications/notifications/notification.validation.js b/src/features/notifications/notifications/notification.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/notifications/notifications/notification.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/organization/org/tenant.routes.js b/src/features/organization/org/tenant.routes.js index 3a57912..f743cfc 100644 --- a/src/features/organization/org/tenant.routes.js +++ b/src/features/organization/org/tenant.routes.js @@ -5,6 +5,20 @@ import { authorize } from '../../../shared/middleware/permission.middleware.js'; const router = Router(); +/** + * @swagger + * /api/v1/tenants: + * get: + * summary: Retrieve all tenants + * tags: [Tenants] + * security: + * - bearerAuth: [] + * responses: + * 200: + * description: Success + * 401: + * description: Unauthorized + */ router.get( '/', authenticate, @@ -12,6 +26,26 @@ router.get( controller.getAll ); +/** + * @swagger + * /api/v1/tenants/{id}: + * get: + * summary: Retrieve a single tenant + * tags: [Tenants] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + * 404: + * description: Not Found + */ router.get( '/:id', authenticate, @@ -19,6 +53,32 @@ router.get( controller.getById ); +/** + * @swagger + * /api/v1/tenants: + * post: + * summary: Create a new tenant + * tags: [Tenants] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: [name, domain] + * properties: + * name: + * type: string + * domain: + * type: string + * responses: + * 201: + * description: Created + * 400: + * description: Validation Error + */ router.post( '/', authenticate, @@ -26,6 +86,24 @@ router.post( controller.create ); +/** + * @swagger + * /api/v1/tenants/{id}: + * put: + * summary: Update a tenant + * tags: [Tenants] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Success + */ router.put( '/:id', authenticate, @@ -33,6 +111,24 @@ router.put( controller.update ); +/** + * @swagger + * /api/v1/tenants/{id}: + * delete: + * summary: Delete a tenant + * tags: [Tenants] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * responses: + * 200: + * description: Deleted + */ router.delete( '/:id', authenticate, diff --git a/src/features/pricing/index.js b/src/features/pricing/index.js deleted file mode 100644 index f4b6dff..0000000 --- a/src/features/pricing/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import pricingRouter from './pricing/pricing.routes.js'; - -const router = Router(); - -router.use('/pricing', pricingRouter); - -export default router; diff --git a/src/features/pricing/pricing/index.js b/src/features/pricing/pricing/index.js deleted file mode 100644 index 73f07db..0000000 --- a/src/features/pricing/pricing/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as pricingRoutes } from './pricing.routes.js'; -export { default as pricingController } from './pricing.controller.js'; -export { default as pricingService } from './pricing.service.js'; -export { default as pricingRepository } from './pricing.repository.js'; -export { default as pricingModel } from './pricing.model.js'; diff --git a/src/features/pricing/pricing/pricing.controller.js b/src/features/pricing/pricing/pricing.controller.js deleted file mode 100644 index c2648ad..0000000 --- a/src/features/pricing/pricing/pricing.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './pricing.service.js'; - -export class PricingController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Pricing deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new PricingController(); diff --git a/src/features/pricing/pricing/pricing.model.js b/src/features/pricing/pricing/pricing.model.js deleted file mode 100644 index 614c93c..0000000 --- a/src/features/pricing/pricing/pricing.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Pricing extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Pricing.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Pricing', - tableName: 'pricings', - timestamps: true, - underscored: true - }); - - return Pricing; -}; diff --git a/src/features/pricing/pricing/pricing.repository.js b/src/features/pricing/pricing/pricing.repository.js deleted file mode 100644 index bc43f1b..0000000 --- a/src/features/pricing/pricing/pricing.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class PricingRepository { - async findAll(options = {}) { - return await models.Pricing.findAll(options); - } - - async findById(id, options = {}) { - return await models.Pricing.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Pricing.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new PricingRepository(); diff --git a/src/features/pricing/pricing/pricing.routes.js b/src/features/pricing/pricing/pricing.routes.js deleted file mode 100644 index 8951a3b..0000000 --- a/src/features/pricing/pricing/pricing.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './pricing.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './pricing.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/pricings: - * get: - * summary: Retrieve all pricings - * tags: [Pricings] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:pricings']), - controller.getAll -); - -/** - * @swagger - * /api/v1/pricings/{id}: - * get: - * summary: Retrieve a single pricing - * tags: [Pricings] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:pricings']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/pricings: - * post: - * summary: Create a pricing - * tags: [Pricings] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:pricings']), - createValidation, - validate, - audit('CREATE_PRICING'), - controller.create -); - -/** - * @swagger - * /api/v1/pricings/{id}: - * put: - * summary: Update a pricing - * tags: [Pricings] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:pricings']), - updateValidation, - validate, - audit('UPDATE_PRICING'), - controller.update -); - -/** - * @swagger - * /api/v1/pricings/{id}: - * delete: - * summary: Delete a pricing - * tags: [Pricings] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:pricings']), - deleteValidation, - validate, - audit('DELETE_PRICING'), - controller.delete -); - -export default router; diff --git a/src/features/pricing/pricing/pricing.service.js b/src/features/pricing/pricing/pricing.service.js deleted file mode 100644 index 81034d2..0000000 --- a/src/features/pricing/pricing/pricing.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './pricing.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class PricingService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Pricing not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('pricing:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Pricing', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Pricing not found'); - } - - SocketService.broadcast('pricing:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Pricing', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Pricing not found'); - } - - SocketService.broadcast('pricing:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Pricing', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new PricingService(); diff --git a/src/features/pricing/pricing/pricing.validation.js b/src/features/pricing/pricing/pricing.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/pricing/pricing/pricing.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/approvals/approval.controller.js b/src/features/products/approvals/approval.controller.js deleted file mode 100644 index 12b6d16..0000000 --- a/src/features/products/approvals/approval.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './approval.service.js'; - -export class ApprovalController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Approval deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new ApprovalController(); diff --git a/src/features/products/approvals/approval.model.js b/src/features/products/approvals/approval.model.js deleted file mode 100644 index d165508..0000000 --- a/src/features/products/approvals/approval.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Approval extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Approval.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Approval', - tableName: 'approvals', - timestamps: true, - underscored: true - }); - - return Approval; -}; diff --git a/src/features/products/approvals/approval.repository.js b/src/features/products/approvals/approval.repository.js deleted file mode 100644 index c1eb9c2..0000000 --- a/src/features/products/approvals/approval.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class ApprovalRepository { - async findAll(options = {}) { - return await models.Approval.findAll(options); - } - - async findById(id, options = {}) { - return await models.Approval.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Approval.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new ApprovalRepository(); diff --git a/src/features/products/approvals/approval.routes.js b/src/features/products/approvals/approval.routes.js deleted file mode 100644 index 52ae856..0000000 --- a/src/features/products/approvals/approval.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './approval.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './approval.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/approvals: - * get: - * summary: Retrieve all approvals - * tags: [Approvals] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:approvals']), - controller.getAll -); - -/** - * @swagger - * /api/v1/approvals/{id}: - * get: - * summary: Retrieve a single approval - * tags: [Approvals] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:approvals']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/approvals: - * post: - * summary: Create a approval - * tags: [Approvals] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:approvals']), - createValidation, - validate, - audit('CREATE_APPROVAL'), - controller.create -); - -/** - * @swagger - * /api/v1/approvals/{id}: - * put: - * summary: Update a approval - * tags: [Approvals] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:approvals']), - updateValidation, - validate, - audit('UPDATE_APPROVAL'), - controller.update -); - -/** - * @swagger - * /api/v1/approvals/{id}: - * delete: - * summary: Delete a approval - * tags: [Approvals] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:approvals']), - deleteValidation, - validate, - audit('DELETE_APPROVAL'), - controller.delete -); - -export default router; diff --git a/src/features/products/approvals/approval.service.js b/src/features/products/approvals/approval.service.js deleted file mode 100644 index 96e7480..0000000 --- a/src/features/products/approvals/approval.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './approval.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class ApprovalService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Approval not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('approval:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Approval', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Approval not found'); - } - - SocketService.broadcast('approval:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Approval', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Approval not found'); - } - - SocketService.broadcast('approval:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Approval', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new ApprovalService(); diff --git a/src/features/products/approvals/approval.validation.js b/src/features/products/approvals/approval.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/approvals/approval.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/approvals/index.js b/src/features/products/approvals/index.js deleted file mode 100644 index 39a81f0..0000000 --- a/src/features/products/approvals/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as approvalRoutes } from './approval.routes.js'; -export { default as approvalController } from './approval.controller.js'; -export { default as approvalService } from './approval.service.js'; -export { default as approvalRepository } from './approval.repository.js'; -export { default as approvalModel } from './approval.model.js'; diff --git a/src/features/products/bundles/bundle.controller.js b/src/features/products/bundles/bundle.controller.js deleted file mode 100644 index ee286ca..0000000 --- a/src/features/products/bundles/bundle.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './bundle.service.js'; - -export class BundleController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Bundle deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new BundleController(); diff --git a/src/features/products/bundles/bundle.model.js b/src/features/products/bundles/bundle.model.js deleted file mode 100644 index 94e3d8c..0000000 --- a/src/features/products/bundles/bundle.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Bundle extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Bundle.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Bundle', - tableName: 'bundles', - timestamps: true, - underscored: true - }); - - return Bundle; -}; diff --git a/src/features/products/bundles/bundle.repository.js b/src/features/products/bundles/bundle.repository.js deleted file mode 100644 index 6abefd6..0000000 --- a/src/features/products/bundles/bundle.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class BundleRepository { - async findAll(options = {}) { - return await models.Bundle.findAll(options); - } - - async findById(id, options = {}) { - return await models.Bundle.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Bundle.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new BundleRepository(); diff --git a/src/features/products/bundles/bundle.routes.js b/src/features/products/bundles/bundle.routes.js deleted file mode 100644 index 2a86698..0000000 --- a/src/features/products/bundles/bundle.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './bundle.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './bundle.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/bundles: - * get: - * summary: Retrieve all bundles - * tags: [Bundles] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:bundles']), - controller.getAll -); - -/** - * @swagger - * /api/v1/bundles/{id}: - * get: - * summary: Retrieve a single bundle - * tags: [Bundles] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:bundles']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/bundles: - * post: - * summary: Create a bundle - * tags: [Bundles] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:bundles']), - createValidation, - validate, - audit('CREATE_BUNDLE'), - controller.create -); - -/** - * @swagger - * /api/v1/bundles/{id}: - * put: - * summary: Update a bundle - * tags: [Bundles] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:bundles']), - updateValidation, - validate, - audit('UPDATE_BUNDLE'), - controller.update -); - -/** - * @swagger - * /api/v1/bundles/{id}: - * delete: - * summary: Delete a bundle - * tags: [Bundles] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:bundles']), - deleteValidation, - validate, - audit('DELETE_BUNDLE'), - controller.delete -); - -export default router; diff --git a/src/features/products/bundles/bundle.service.js b/src/features/products/bundles/bundle.service.js deleted file mode 100644 index 56e970a..0000000 --- a/src/features/products/bundles/bundle.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './bundle.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class BundleService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Bundle not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('bundle:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Bundle', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Bundle not found'); - } - - SocketService.broadcast('bundle:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Bundle', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Bundle not found'); - } - - SocketService.broadcast('bundle:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Bundle', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new BundleService(); diff --git a/src/features/products/bundles/bundle.validation.js b/src/features/products/bundles/bundle.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/bundles/bundle.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/bundles/index.js b/src/features/products/bundles/index.js deleted file mode 100644 index 5828a7f..0000000 --- a/src/features/products/bundles/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as bundleRoutes } from './bundle.routes.js'; -export { default as bundleController } from './bundle.controller.js'; -export { default as bundleService } from './bundle.service.js'; -export { default as bundleRepository } from './bundle.repository.js'; -export { default as bundleModel } from './bundle.model.js'; diff --git a/src/features/products/configurableProducts/configurableProduct.controller.js b/src/features/products/configurableProducts/configurableProduct.controller.js deleted file mode 100644 index 1f5cd36..0000000 --- a/src/features/products/configurableProducts/configurableProduct.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './configurableProduct.service.js'; - -export class ConfigurableProductController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'ConfigurableProduct deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new ConfigurableProductController(); diff --git a/src/features/products/configurableProducts/configurableProduct.model.js b/src/features/products/configurableProducts/configurableProduct.model.js deleted file mode 100644 index b428756..0000000 --- a/src/features/products/configurableProducts/configurableProduct.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class ConfigurableProduct extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - ConfigurableProduct.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'ConfigurableProduct', - tableName: 'configurableproducts', - timestamps: true, - underscored: true - }); - - return ConfigurableProduct; -}; diff --git a/src/features/products/configurableProducts/configurableProduct.repository.js b/src/features/products/configurableProducts/configurableProduct.repository.js deleted file mode 100644 index 7fb40a7..0000000 --- a/src/features/products/configurableProducts/configurableProduct.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class ConfigurableProductRepository { - async findAll(options = {}) { - return await models.ConfigurableProduct.findAll(options); - } - - async findById(id, options = {}) { - return await models.ConfigurableProduct.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.ConfigurableProduct.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new ConfigurableProductRepository(); diff --git a/src/features/products/configurableProducts/configurableProduct.routes.js b/src/features/products/configurableProducts/configurableProduct.routes.js deleted file mode 100644 index f368d8f..0000000 --- a/src/features/products/configurableProducts/configurableProduct.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './configurableProduct.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './configurableProduct.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/configurableProducts: - * get: - * summary: Retrieve all configurableProducts - * tags: [ConfigurableProducts] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:configurableProducts']), - controller.getAll -); - -/** - * @swagger - * /api/v1/configurableProducts/{id}: - * get: - * summary: Retrieve a single configurableProduct - * tags: [ConfigurableProducts] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:configurableProducts']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/configurableProducts: - * post: - * summary: Create a configurableProduct - * tags: [ConfigurableProducts] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:configurableProducts']), - createValidation, - validate, - audit('CREATE_CONFIGURABLEPRODUCT'), - controller.create -); - -/** - * @swagger - * /api/v1/configurableProducts/{id}: - * put: - * summary: Update a configurableProduct - * tags: [ConfigurableProducts] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:configurableProducts']), - updateValidation, - validate, - audit('UPDATE_CONFIGURABLEPRODUCT'), - controller.update -); - -/** - * @swagger - * /api/v1/configurableProducts/{id}: - * delete: - * summary: Delete a configurableProduct - * tags: [ConfigurableProducts] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:configurableProducts']), - deleteValidation, - validate, - audit('DELETE_CONFIGURABLEPRODUCT'), - controller.delete -); - -export default router; diff --git a/src/features/products/configurableProducts/configurableProduct.service.js b/src/features/products/configurableProducts/configurableProduct.service.js deleted file mode 100644 index 030e6c3..0000000 --- a/src/features/products/configurableProducts/configurableProduct.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './configurableProduct.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class ConfigurableProductService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('ConfigurableProduct not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('configurableProduct:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'ConfigurableProduct', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('ConfigurableProduct not found'); - } - - SocketService.broadcast('configurableProduct:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'ConfigurableProduct', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('ConfigurableProduct not found'); - } - - SocketService.broadcast('configurableProduct:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'ConfigurableProduct', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new ConfigurableProductService(); diff --git a/src/features/products/configurableProducts/configurableProduct.validation.js b/src/features/products/configurableProducts/configurableProduct.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/configurableProducts/configurableProduct.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/configurableProducts/index.js b/src/features/products/configurableProducts/index.js deleted file mode 100644 index 760f6d4..0000000 --- a/src/features/products/configurableProducts/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as configurableProductRoutes } from './configurableProduct.routes.js'; -export { default as configurableProductController } from './configurableProduct.controller.js'; -export { default as configurableProductService } from './configurableProduct.service.js'; -export { default as configurableProductRepository } from './configurableProduct.repository.js'; -export { default as configurableProductModel } from './configurableProduct.model.js'; diff --git a/src/features/products/digitalProducts/digitalProduct.controller.js b/src/features/products/digitalProducts/digitalProduct.controller.js deleted file mode 100644 index 7e3df14..0000000 --- a/src/features/products/digitalProducts/digitalProduct.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './digitalProduct.service.js'; - -export class DigitalProductController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'DigitalProduct deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new DigitalProductController(); diff --git a/src/features/products/digitalProducts/digitalProduct.model.js b/src/features/products/digitalProducts/digitalProduct.model.js deleted file mode 100644 index 15f736a..0000000 --- a/src/features/products/digitalProducts/digitalProduct.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class DigitalProduct extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - DigitalProduct.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'DigitalProduct', - tableName: 'digitalproducts', - timestamps: true, - underscored: true - }); - - return DigitalProduct; -}; diff --git a/src/features/products/digitalProducts/digitalProduct.repository.js b/src/features/products/digitalProducts/digitalProduct.repository.js deleted file mode 100644 index 424d392..0000000 --- a/src/features/products/digitalProducts/digitalProduct.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class DigitalProductRepository { - async findAll(options = {}) { - return await models.DigitalProduct.findAll(options); - } - - async findById(id, options = {}) { - return await models.DigitalProduct.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.DigitalProduct.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new DigitalProductRepository(); diff --git a/src/features/products/digitalProducts/digitalProduct.routes.js b/src/features/products/digitalProducts/digitalProduct.routes.js deleted file mode 100644 index 34c15bc..0000000 --- a/src/features/products/digitalProducts/digitalProduct.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './digitalProduct.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './digitalProduct.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/digitalProducts: - * get: - * summary: Retrieve all digitalProducts - * tags: [DigitalProducts] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:digitalProducts']), - controller.getAll -); - -/** - * @swagger - * /api/v1/digitalProducts/{id}: - * get: - * summary: Retrieve a single digitalProduct - * tags: [DigitalProducts] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:digitalProducts']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/digitalProducts: - * post: - * summary: Create a digitalProduct - * tags: [DigitalProducts] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:digitalProducts']), - createValidation, - validate, - audit('CREATE_DIGITALPRODUCT'), - controller.create -); - -/** - * @swagger - * /api/v1/digitalProducts/{id}: - * put: - * summary: Update a digitalProduct - * tags: [DigitalProducts] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:digitalProducts']), - updateValidation, - validate, - audit('UPDATE_DIGITALPRODUCT'), - controller.update -); - -/** - * @swagger - * /api/v1/digitalProducts/{id}: - * delete: - * summary: Delete a digitalProduct - * tags: [DigitalProducts] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:digitalProducts']), - deleteValidation, - validate, - audit('DELETE_DIGITALPRODUCT'), - controller.delete -); - -export default router; diff --git a/src/features/products/digitalProducts/digitalProduct.service.js b/src/features/products/digitalProducts/digitalProduct.service.js deleted file mode 100644 index 36d71a1..0000000 --- a/src/features/products/digitalProducts/digitalProduct.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './digitalProduct.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class DigitalProductService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('DigitalProduct not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('digitalProduct:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'DigitalProduct', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('DigitalProduct not found'); - } - - SocketService.broadcast('digitalProduct:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'DigitalProduct', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('DigitalProduct not found'); - } - - SocketService.broadcast('digitalProduct:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'DigitalProduct', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new DigitalProductService(); diff --git a/src/features/products/digitalProducts/digitalProduct.validation.js b/src/features/products/digitalProducts/digitalProduct.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/digitalProducts/digitalProduct.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/digitalProducts/index.js b/src/features/products/digitalProducts/index.js deleted file mode 100644 index 1727c9e..0000000 --- a/src/features/products/digitalProducts/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as digitalProductRoutes } from './digitalProduct.routes.js'; -export { default as digitalProductController } from './digitalProduct.controller.js'; -export { default as digitalProductService } from './digitalProduct.service.js'; -export { default as digitalProductRepository } from './digitalProduct.repository.js'; -export { default as digitalProductModel } from './digitalProduct.model.js'; diff --git a/src/features/products/families/family.controller.js b/src/features/products/families/family.controller.js deleted file mode 100644 index 5354050..0000000 --- a/src/features/products/families/family.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './family.service.js'; - -export class FamilyController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Family deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new FamilyController(); diff --git a/src/features/products/families/family.model.js b/src/features/products/families/family.model.js deleted file mode 100644 index 9a4da3a..0000000 --- a/src/features/products/families/family.model.js +++ /dev/null @@ -1,55 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Family extends Model { - static associate(models) { - // Define associations here if any - } -} - -export default (sequelize) => { - Family.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - code: { - type: DataTypes.STRING, - allowNull: false, - unique: true - }, - name: { - type: DataTypes.STRING, - allowNull: false - }, - description: { - type: DataTypes.TEXT, - allowNull: true - }, - category: { - type: DataTypes.STRING, - allowNull: true - }, - attributes: { - type: DataTypes.JSONB, - defaultValue: [] - }, - variant_axes: { - type: DataTypes.JSONB, - defaultValue: [] - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - } - }, { - sequelize, - modelName: 'Family', - tableName: 'families', - timestamps: true, - underscored: true - }); - - return Family; -}; diff --git a/src/features/products/families/family.repository.js b/src/features/products/families/family.repository.js deleted file mode 100644 index 08a063a..0000000 --- a/src/features/products/families/family.repository.js +++ /dev/null @@ -1,34 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class FamilyRepository { - async findAll(options = {}) { - return await models.Family.findAll(options); - } - - async findById(id, options = {}) { - return await models.Family.findByPk(id, options); - } - - async findByCode(code, options = {}) { - return await models.Family.findOne({ where: { code }, ...options }); - } - - async create(data, options = {}) { - return await models.Family.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new FamilyRepository(); diff --git a/src/features/products/families/family.routes.js b/src/features/products/families/family.routes.js deleted file mode 100644 index 2f38c5d..0000000 --- a/src/features/products/families/family.routes.js +++ /dev/null @@ -1,62 +0,0 @@ -import { Router } from 'express'; -import controller from './family.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './family.validation.js'; - -const router = Router(); - -router.get( - '/', - authenticate, - authorize(['read:products']), - controller.getAll -); - -router.get( - '/:id', - authenticate, - authorize(['read:products']), - getByIdValidation, - validate, - controller.getById -); - -router.post( - '/', - authenticate, - authorize(['write:products']), - createValidation, - validate, - audit('CREATE_FAMILY'), - controller.create -); - -router.put( - '/:id', - authenticate, - authorize(['write:products']), - updateValidation, - validate, - audit('UPDATE_FAMILY'), - controller.update -); - -router.delete( - '/:id', - authenticate, - authorize(['write:products']), - deleteValidation, - validate, - audit('DELETE_FAMILY'), - controller.delete -); - -export default router; diff --git a/src/features/products/families/family.service.js b/src/features/products/families/family.service.js deleted file mode 100644 index 9a90c05..0000000 --- a/src/features/products/families/family.service.js +++ /dev/null @@ -1,72 +0,0 @@ -import repository from './family.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class FamilyService { - async getAll(query = {}) { - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Family not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - SocketService.broadcast('family:created', record); - - await AuditService.log({ - action: 'CREATE', - resource: 'Family', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Family not found'); - } - - SocketService.broadcast('family:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Family', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Family not found'); - } - - SocketService.broadcast('family:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Family', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new FamilyService(); diff --git a/src/features/products/families/family.validation.js b/src/features/products/families/family.validation.js deleted file mode 100644 index 62a3837..0000000 --- a/src/features/products/families/family.validation.js +++ /dev/null @@ -1,36 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('code') - .isString() - .trim() - .notEmpty() - .withMessage('Code is required'), - body('name') - .isString() - .trim() - .notEmpty() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/index.js b/src/features/products/index.js index ed24a51..d7f898d 100644 --- a/src/features/products/index.js +++ b/src/features/products/index.js @@ -1,24 +1,8 @@ import { Router } from 'express'; import productsRouter from './products/product.routes.js'; -import variantsRouter from './variants/variant.routes.js'; -import bundlesRouter from './bundles/bundle.routes.js'; -import configurableProductsRouter from './configurableProducts/configurableProduct.routes.js'; -import digitalProductsRouter from './digitalProducts/digitalProduct.routes.js'; -import lifecycleRouter from './lifecycle/lifecycle.routes.js'; -import approvalsRouter from './approvals/approval.routes.js'; -import publishingRouter from './publishing/publishing.routes.js'; -import familiesRouter from './families/family.routes.js'; const router = Router(); router.use('/products', productsRouter); -router.use('/variants', variantsRouter); -router.use('/bundles', bundlesRouter); -router.use('/configurableproducts', configurableProductsRouter); -router.use('/digitalproducts', digitalProductsRouter); -router.use('/lifecycle', lifecycleRouter); -router.use('/approvals', approvalsRouter); -router.use('/publishing', publishingRouter); -router.use('/families', familiesRouter); export default router; diff --git a/src/features/products/lifecycle/index.js b/src/features/products/lifecycle/index.js deleted file mode 100644 index 870e762..0000000 --- a/src/features/products/lifecycle/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as lifecycleRoutes } from './lifecycle.routes.js'; -export { default as lifecycleController } from './lifecycle.controller.js'; -export { default as lifecycleService } from './lifecycle.service.js'; -export { default as lifecycleRepository } from './lifecycle.repository.js'; -export { default as lifecycleModel } from './lifecycle.model.js'; diff --git a/src/features/products/lifecycle/lifecycle.controller.js b/src/features/products/lifecycle/lifecycle.controller.js deleted file mode 100644 index 2ef4c07..0000000 --- a/src/features/products/lifecycle/lifecycle.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './lifecycle.service.js'; - -export class LifecycleController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Lifecycle deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new LifecycleController(); diff --git a/src/features/products/lifecycle/lifecycle.model.js b/src/features/products/lifecycle/lifecycle.model.js deleted file mode 100644 index 2ea1798..0000000 --- a/src/features/products/lifecycle/lifecycle.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Lifecycle extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Lifecycle.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Lifecycle', - tableName: 'lifecycles', - timestamps: true, - underscored: true - }); - - return Lifecycle; -}; diff --git a/src/features/products/lifecycle/lifecycle.repository.js b/src/features/products/lifecycle/lifecycle.repository.js deleted file mode 100644 index 4ce7737..0000000 --- a/src/features/products/lifecycle/lifecycle.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class LifecycleRepository { - async findAll(options = {}) { - return await models.Lifecycle.findAll(options); - } - - async findById(id, options = {}) { - return await models.Lifecycle.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Lifecycle.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new LifecycleRepository(); diff --git a/src/features/products/lifecycle/lifecycle.routes.js b/src/features/products/lifecycle/lifecycle.routes.js deleted file mode 100644 index 6d75987..0000000 --- a/src/features/products/lifecycle/lifecycle.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './lifecycle.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './lifecycle.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/lifecycles: - * get: - * summary: Retrieve all lifecycles - * tags: [Lifecycles] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:lifecycles']), - controller.getAll -); - -/** - * @swagger - * /api/v1/lifecycles/{id}: - * get: - * summary: Retrieve a single lifecycle - * tags: [Lifecycles] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:lifecycles']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/lifecycles: - * post: - * summary: Create a lifecycle - * tags: [Lifecycles] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:lifecycles']), - createValidation, - validate, - audit('CREATE_LIFECYCLE'), - controller.create -); - -/** - * @swagger - * /api/v1/lifecycles/{id}: - * put: - * summary: Update a lifecycle - * tags: [Lifecycles] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:lifecycles']), - updateValidation, - validate, - audit('UPDATE_LIFECYCLE'), - controller.update -); - -/** - * @swagger - * /api/v1/lifecycles/{id}: - * delete: - * summary: Delete a lifecycle - * tags: [Lifecycles] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:lifecycles']), - deleteValidation, - validate, - audit('DELETE_LIFECYCLE'), - controller.delete -); - -export default router; diff --git a/src/features/products/lifecycle/lifecycle.service.js b/src/features/products/lifecycle/lifecycle.service.js deleted file mode 100644 index 65cf97b..0000000 --- a/src/features/products/lifecycle/lifecycle.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './lifecycle.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class LifecycleService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Lifecycle not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('lifecycle:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Lifecycle', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Lifecycle not found'); - } - - SocketService.broadcast('lifecycle:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Lifecycle', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Lifecycle not found'); - } - - SocketService.broadcast('lifecycle:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Lifecycle', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new LifecycleService(); diff --git a/src/features/products/lifecycle/lifecycle.validation.js b/src/features/products/lifecycle/lifecycle.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/lifecycle/lifecycle.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/publishing/index.js b/src/features/products/publishing/index.js deleted file mode 100644 index 82600c0..0000000 --- a/src/features/products/publishing/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as publishingRoutes } from './publishing.routes.js'; -export { default as publishingController } from './publishing.controller.js'; -export { default as publishingService } from './publishing.service.js'; -export { default as publishingRepository } from './publishing.repository.js'; -export { default as publishingModel } from './publishing.model.js'; diff --git a/src/features/products/publishing/publishing.controller.js b/src/features/products/publishing/publishing.controller.js deleted file mode 100644 index 23adde1..0000000 --- a/src/features/products/publishing/publishing.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './publishing.service.js'; - -export class PublishingController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Publishing deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new PublishingController(); diff --git a/src/features/products/publishing/publishing.model.js b/src/features/products/publishing/publishing.model.js deleted file mode 100644 index e46afc5..0000000 --- a/src/features/products/publishing/publishing.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Publishing extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Publishing.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Publishing', - tableName: 'publishings', - timestamps: true, - underscored: true - }); - - return Publishing; -}; diff --git a/src/features/products/publishing/publishing.repository.js b/src/features/products/publishing/publishing.repository.js deleted file mode 100644 index 79647bd..0000000 --- a/src/features/products/publishing/publishing.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class PublishingRepository { - async findAll(options = {}) { - return await models.Publishing.findAll(options); - } - - async findById(id, options = {}) { - return await models.Publishing.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Publishing.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new PublishingRepository(); diff --git a/src/features/products/publishing/publishing.routes.js b/src/features/products/publishing/publishing.routes.js deleted file mode 100644 index 4bf2284..0000000 --- a/src/features/products/publishing/publishing.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './publishing.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './publishing.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/publishings: - * get: - * summary: Retrieve all publishings - * tags: [Publishings] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:publishings']), - controller.getAll -); - -/** - * @swagger - * /api/v1/publishings/{id}: - * get: - * summary: Retrieve a single publishing - * tags: [Publishings] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:publishings']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/publishings: - * post: - * summary: Create a publishing - * tags: [Publishings] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:publishings']), - createValidation, - validate, - audit('CREATE_PUBLISHING'), - controller.create -); - -/** - * @swagger - * /api/v1/publishings/{id}: - * put: - * summary: Update a publishing - * tags: [Publishings] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:publishings']), - updateValidation, - validate, - audit('UPDATE_PUBLISHING'), - controller.update -); - -/** - * @swagger - * /api/v1/publishings/{id}: - * delete: - * summary: Delete a publishing - * tags: [Publishings] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:publishings']), - deleteValidation, - validate, - audit('DELETE_PUBLISHING'), - controller.delete -); - -export default router; diff --git a/src/features/products/publishing/publishing.service.js b/src/features/products/publishing/publishing.service.js deleted file mode 100644 index d84d0f6..0000000 --- a/src/features/products/publishing/publishing.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './publishing.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class PublishingService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Publishing not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('publishing:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Publishing', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Publishing not found'); - } - - SocketService.broadcast('publishing:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Publishing', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Publishing not found'); - } - - SocketService.broadcast('publishing:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Publishing', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new PublishingService(); diff --git a/src/features/products/publishing/publishing.validation.js b/src/features/products/publishing/publishing.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/publishing/publishing.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/products/variants/index.js b/src/features/products/variants/index.js deleted file mode 100644 index 8094f32..0000000 --- a/src/features/products/variants/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as variantRoutes } from './variant.routes.js'; -export { default as variantController } from './variant.controller.js'; -export { default as variantService } from './variant.service.js'; -export { default as variantRepository } from './variant.repository.js'; -export { default as variantModel } from './variant.model.js'; diff --git a/src/features/products/variants/variant.controller.js b/src/features/products/variants/variant.controller.js deleted file mode 100644 index 0e4cb47..0000000 --- a/src/features/products/variants/variant.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './variant.service.js'; - -export class VariantController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Variant deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new VariantController(); diff --git a/src/features/products/variants/variant.model.js b/src/features/products/variants/variant.model.js deleted file mode 100644 index 16cfa12..0000000 --- a/src/features/products/variants/variant.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Variant extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Variant.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Variant', - tableName: 'variants', - timestamps: true, - underscored: true - }); - - return Variant; -}; diff --git a/src/features/products/variants/variant.repository.js b/src/features/products/variants/variant.repository.js deleted file mode 100644 index 80f53e3..0000000 --- a/src/features/products/variants/variant.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class VariantRepository { - async findAll(options = {}) { - return await models.Variant.findAll(options); - } - - async findById(id, options = {}) { - return await models.Variant.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Variant.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new VariantRepository(); diff --git a/src/features/products/variants/variant.routes.js b/src/features/products/variants/variant.routes.js deleted file mode 100644 index 4e3b5af..0000000 --- a/src/features/products/variants/variant.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './variant.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './variant.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/variants: - * get: - * summary: Retrieve all variants - * tags: [Variants] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:variants']), - controller.getAll -); - -/** - * @swagger - * /api/v1/variants/{id}: - * get: - * summary: Retrieve a single variant - * tags: [Variants] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:variants']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/variants: - * post: - * summary: Create a variant - * tags: [Variants] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:variants']), - createValidation, - validate, - audit('CREATE_VARIANT'), - controller.create -); - -/** - * @swagger - * /api/v1/variants/{id}: - * put: - * summary: Update a variant - * tags: [Variants] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:variants']), - updateValidation, - validate, - audit('UPDATE_VARIANT'), - controller.update -); - -/** - * @swagger - * /api/v1/variants/{id}: - * delete: - * summary: Delete a variant - * tags: [Variants] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:variants']), - deleteValidation, - validate, - audit('DELETE_VARIANT'), - controller.delete -); - -export default router; diff --git a/src/features/products/variants/variant.service.js b/src/features/products/variants/variant.service.js deleted file mode 100644 index 141a549..0000000 --- a/src/features/products/variants/variant.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './variant.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class VariantService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Variant not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('variant:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Variant', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Variant not found'); - } - - SocketService.broadcast('variant:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Variant', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Variant not found'); - } - - SocketService.broadcast('variant:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Variant', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new VariantService(); diff --git a/src/features/products/variants/variant.validation.js b/src/features/products/variants/variant.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/products/variants/variant.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/reports/index.js b/src/features/reports/index.js deleted file mode 100644 index f139bb0..0000000 --- a/src/features/reports/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import reportsRouter from './reports/report.routes.js'; - -const router = Router(); - -router.use('/reports', reportsRouter); - -export default router; diff --git a/src/features/reports/reports/index.js b/src/features/reports/reports/index.js deleted file mode 100644 index e8b98fb..0000000 --- a/src/features/reports/reports/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as reportRoutes } from './report.routes.js'; -export { default as reportController } from './report.controller.js'; -export { default as reportService } from './report.service.js'; -export { default as reportRepository } from './report.repository.js'; -export { default as reportModel } from './report.model.js'; diff --git a/src/features/reports/reports/report.controller.js b/src/features/reports/reports/report.controller.js deleted file mode 100644 index 61c05de..0000000 --- a/src/features/reports/reports/report.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './report.service.js'; - -export class ReportController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Report deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new ReportController(); diff --git a/src/features/reports/reports/report.model.js b/src/features/reports/reports/report.model.js deleted file mode 100644 index b97a07b..0000000 --- a/src/features/reports/reports/report.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Report extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Report.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Report', - tableName: 'reports', - timestamps: true, - underscored: true - }); - - return Report; -}; diff --git a/src/features/reports/reports/report.repository.js b/src/features/reports/reports/report.repository.js deleted file mode 100644 index eb2fbe3..0000000 --- a/src/features/reports/reports/report.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class ReportRepository { - async findAll(options = {}) { - return await models.Report.findAll(options); - } - - async findById(id, options = {}) { - return await models.Report.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Report.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new ReportRepository(); diff --git a/src/features/reports/reports/report.routes.js b/src/features/reports/reports/report.routes.js deleted file mode 100644 index 1a07b42..0000000 --- a/src/features/reports/reports/report.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './report.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './report.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/reports: - * get: - * summary: Retrieve all reports - * tags: [Reports] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:reports']), - controller.getAll -); - -/** - * @swagger - * /api/v1/reports/{id}: - * get: - * summary: Retrieve a single report - * tags: [Reports] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:reports']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/reports: - * post: - * summary: Create a report - * tags: [Reports] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:reports']), - createValidation, - validate, - audit('CREATE_REPORT'), - controller.create -); - -/** - * @swagger - * /api/v1/reports/{id}: - * put: - * summary: Update a report - * tags: [Reports] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:reports']), - updateValidation, - validate, - audit('UPDATE_REPORT'), - controller.update -); - -/** - * @swagger - * /api/v1/reports/{id}: - * delete: - * summary: Delete a report - * tags: [Reports] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:reports']), - deleteValidation, - validate, - audit('DELETE_REPORT'), - controller.delete -); - -export default router; diff --git a/src/features/reports/reports/report.service.js b/src/features/reports/reports/report.service.js deleted file mode 100644 index a95ef8e..0000000 --- a/src/features/reports/reports/report.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './report.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class ReportService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Report not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('report:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Report', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Report not found'); - } - - SocketService.broadcast('report:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Report', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Report not found'); - } - - SocketService.broadcast('report:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Report', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new ReportService(); diff --git a/src/features/reports/reports/report.validation.js b/src/features/reports/reports/report.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/reports/reports/report.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/suppliers/index.js b/src/features/suppliers/index.js deleted file mode 100644 index 3a0dc23..0000000 --- a/src/features/suppliers/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import suppliersRouter from './suppliers/supplier.routes.js'; - -const router = Router(); - -router.use('/suppliers', suppliersRouter); - -export default router; diff --git a/src/features/suppliers/suppliers/index.js b/src/features/suppliers/suppliers/index.js deleted file mode 100644 index 4548e50..0000000 --- a/src/features/suppliers/suppliers/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as supplierRoutes } from './supplier.routes.js'; -export { default as supplierController } from './supplier.controller.js'; -export { default as supplierService } from './supplier.service.js'; -export { default as supplierRepository } from './supplier.repository.js'; -export { default as supplierModel } from './supplier.model.js'; diff --git a/src/features/suppliers/suppliers/supplier.controller.js b/src/features/suppliers/suppliers/supplier.controller.js deleted file mode 100644 index df5e7cd..0000000 --- a/src/features/suppliers/suppliers/supplier.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './supplier.service.js'; - -export class SupplierController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Supplier deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new SupplierController(); diff --git a/src/features/suppliers/suppliers/supplier.model.js b/src/features/suppliers/suppliers/supplier.model.js deleted file mode 100644 index cdeb3b4..0000000 --- a/src/features/suppliers/suppliers/supplier.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Supplier extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Supplier.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Supplier', - tableName: 'suppliers', - timestamps: true, - underscored: true - }); - - return Supplier; -}; diff --git a/src/features/suppliers/suppliers/supplier.repository.js b/src/features/suppliers/suppliers/supplier.repository.js deleted file mode 100644 index fa56df7..0000000 --- a/src/features/suppliers/suppliers/supplier.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class SupplierRepository { - async findAll(options = {}) { - return await models.Supplier.findAll(options); - } - - async findById(id, options = {}) { - return await models.Supplier.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Supplier.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new SupplierRepository(); diff --git a/src/features/suppliers/suppliers/supplier.routes.js b/src/features/suppliers/suppliers/supplier.routes.js deleted file mode 100644 index 210f500..0000000 --- a/src/features/suppliers/suppliers/supplier.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './supplier.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './supplier.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/suppliers: - * get: - * summary: Retrieve all suppliers - * tags: [Suppliers] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:suppliers']), - controller.getAll -); - -/** - * @swagger - * /api/v1/suppliers/{id}: - * get: - * summary: Retrieve a single supplier - * tags: [Suppliers] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:suppliers']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/suppliers: - * post: - * summary: Create a supplier - * tags: [Suppliers] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:suppliers']), - createValidation, - validate, - audit('CREATE_SUPPLIER'), - controller.create -); - -/** - * @swagger - * /api/v1/suppliers/{id}: - * put: - * summary: Update a supplier - * tags: [Suppliers] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:suppliers']), - updateValidation, - validate, - audit('UPDATE_SUPPLIER'), - controller.update -); - -/** - * @swagger - * /api/v1/suppliers/{id}: - * delete: - * summary: Delete a supplier - * tags: [Suppliers] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:suppliers']), - deleteValidation, - validate, - audit('DELETE_SUPPLIER'), - controller.delete -); - -export default router; diff --git a/src/features/suppliers/suppliers/supplier.service.js b/src/features/suppliers/suppliers/supplier.service.js deleted file mode 100644 index 3eacdd4..0000000 --- a/src/features/suppliers/suppliers/supplier.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './supplier.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class SupplierService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Supplier not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('supplier:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Supplier', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Supplier not found'); - } - - SocketService.broadcast('supplier:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Supplier', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Supplier not found'); - } - - SocketService.broadcast('supplier:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Supplier', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new SupplierService(); diff --git a/src/features/suppliers/suppliers/supplier.validation.js b/src/features/suppliers/suppliers/supplier.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/suppliers/suppliers/supplier.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/features/units/index.js b/src/features/units/index.js deleted file mode 100644 index 622afa5..0000000 --- a/src/features/units/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import unitsRouter from './units/unit.routes.js'; - -const router = Router(); - -router.use('/units', unitsRouter); - -export default router; diff --git a/src/features/units/units/unit.controller.js b/src/features/units/units/unit.controller.js deleted file mode 100644 index 55fb8c6..0000000 --- a/src/features/units/units/unit.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './unit.service.js'; - -export class UnitController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Unit deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new UnitController(); diff --git a/src/features/units/units/unit.model.js b/src/features/units/units/unit.model.js deleted file mode 100644 index 4ecac51..0000000 --- a/src/features/units/units/unit.model.js +++ /dev/null @@ -1,29 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Unit extends Model { - static associate(models) { - // Define associations here if any - } -} - -export default (sequelize) => { - Unit.init({ - id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, allowNull: false }, - name: { type: DataTypes.STRING, allowNull: false }, - code: { type: DataTypes.STRING, allowNull: false, unique: true }, - symbol: { type: DataTypes.STRING, allowNull: true }, - unitType: { type: DataTypes.STRING, field: 'unit_type', allowNull: true }, - conversionFactor: { type: DataTypes.FLOAT, field: 'conversion_factor', defaultValue: 1 }, - baseUnit: { type: DataTypes.STRING, field: 'base_unit', allowNull: true }, - status: { type: DataTypes.STRING, defaultValue: 'active' }, - description: { type: DataTypes.TEXT, allowNull: true }, - createdBy: { type: DataTypes.STRING, field: 'created_by', allowNull: true } - }, { - sequelize, - modelName: 'Unit', - tableName: 'units', - timestamps: true, - underscored: true - }); - return Unit; -}; diff --git a/src/features/units/units/unit.repository.js b/src/features/units/units/unit.repository.js deleted file mode 100644 index 3c58c2d..0000000 --- a/src/features/units/units/unit.repository.js +++ /dev/null @@ -1,32 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class UnitRepository { - async findAll(query = {}) { - return await models.Unit.findAll({ - order: [['createdAt', 'DESC']] - }); - } - - async findById(id) { - return await models.Unit.findByPk(id); - } - - async create(data) { - return await models.Unit.create(data); - } - - async update(id, data) { - const record = await this.findById(id); - if (!record) return null; - return await record.update(data); - } - - async delete(id) { - const record = await this.findById(id); - if (!record) return false; - await record.destroy(); - return true; - } -} - -export default new UnitRepository(); diff --git a/src/features/units/units/unit.routes.js b/src/features/units/units/unit.routes.js deleted file mode 100644 index 275f609..0000000 --- a/src/features/units/units/unit.routes.js +++ /dev/null @@ -1,14 +0,0 @@ -import { Router } from 'express'; -import controller from './unit.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; - -const router = Router(); - -router.get('/', authenticate, authorize([]), controller.getAll); -router.get('/:id', authenticate, authorize([]), controller.getById); -router.post('/', authenticate, authorize([]), controller.create); -router.put('/:id', authenticate, authorize([]), controller.update); -router.delete('/:id', authenticate, authorize([]), controller.delete); - -export default router; diff --git a/src/features/units/units/unit.service.js b/src/features/units/units/unit.service.js deleted file mode 100644 index 2b3be2e..0000000 --- a/src/features/units/units/unit.service.js +++ /dev/null @@ -1,72 +0,0 @@ -import repository from './unit.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class UnitService { - async getAll(query = {}) { - return await repository.findAll(query); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Unit not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - SocketService.broadcast('unit:created', record); - - await AuditService.log({ - action: 'CREATE', - resource: 'Unit', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Unit not found'); - } - - SocketService.broadcast('unit:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Unit', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Unit not found'); - } - - SocketService.broadcast('unit:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Unit', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new UnitService(); diff --git a/src/features/workflows/index.js b/src/features/workflows/index.js deleted file mode 100644 index 6d4bf96..0000000 --- a/src/features/workflows/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Router } from 'express'; -import workflowsRouter from './workflows/workflow.routes.js'; - -const router = Router(); - -router.use('/workflows', workflowsRouter); - -export default router; diff --git a/src/features/workflows/workflows/index.js b/src/features/workflows/workflows/index.js deleted file mode 100644 index 18c5320..0000000 --- a/src/features/workflows/workflows/index.js +++ /dev/null @@ -1,5 +0,0 @@ -export { default as workflowRoutes } from './workflow.routes.js'; -export { default as workflowController } from './workflow.controller.js'; -export { default as workflowService } from './workflow.service.js'; -export { default as workflowRepository } from './workflow.repository.js'; -export { default as workflowModel } from './workflow.model.js'; diff --git a/src/features/workflows/workflows/workflow.controller.js b/src/features/workflows/workflows/workflow.controller.js deleted file mode 100644 index b63d3aa..0000000 --- a/src/features/workflows/workflows/workflow.controller.js +++ /dev/null @@ -1,50 +0,0 @@ -import service from './workflow.service.js'; - -export class WorkflowController { - async getAll(req, res, next) { - try { - const records = await service.getAll(req.query); - return res.status(200).json({ success: true, data: records }); - } catch (error) { - next(error); - } - } - - async getById(req, res, next) { - try { - const record = await service.getById(req.params.id); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async create(req, res, next) { - try { - const record = await service.create(req.body, req.user); - return res.status(201).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async update(req, res, next) { - try { - const record = await service.update(req.params.id, req.body, req.user); - return res.status(200).json({ success: true, data: record }); - } catch (error) { - next(error); - } - } - - async delete(req, res, next) { - try { - await service.delete(req.params.id, req.user); - return res.status(200).json({ success: true, message: 'Workflow deleted successfully' }); - } catch (error) { - next(error); - } - } -} - -export default new WorkflowController(); diff --git a/src/features/workflows/workflows/workflow.model.js b/src/features/workflows/workflows/workflow.model.js deleted file mode 100644 index 14d8a61..0000000 --- a/src/features/workflows/workflows/workflow.model.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Model, DataTypes } from 'sequelize'; - -export class Workflow extends Model { - static associate(models) { - // Define associations here - } -} - -export default (sequelize) => { - Workflow.init({ - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, - allowNull: false - }, - name: { - type: DataTypes.STRING, - allowNull: true - }, - status: { - type: DataTypes.STRING, - defaultValue: 'active' - }, - metadata: { - type: DataTypes.JSONB, - allowNull: true - } - }, { - sequelize, - modelName: 'Workflow', - tableName: 'workflows', - timestamps: true, - underscored: true - }); - - return Workflow; -}; diff --git a/src/features/workflows/workflows/workflow.repository.js b/src/features/workflows/workflows/workflow.repository.js deleted file mode 100644 index 13c43ea..0000000 --- a/src/features/workflows/workflows/workflow.repository.js +++ /dev/null @@ -1,30 +0,0 @@ -import { models } from '../../../shared/database/models.js'; - -export class WorkflowRepository { - async findAll(options = {}) { - return await models.Workflow.findAll(options); - } - - async findById(id, options = {}) { - return await models.Workflow.findByPk(id, options); - } - - async create(data, options = {}) { - return await models.Workflow.create(data, options); - } - - async update(id, data, options = {}) { - const record = await this.findById(id, options); - if (!record) return null; - return await record.update(data, options); - } - - async delete(id, options = {}) { - const record = await this.findById(id, options); - if (!record) return false; - await record.destroy(options); - return true; - } -} - -export default new WorkflowRepository(); diff --git a/src/features/workflows/workflows/workflow.routes.js b/src/features/workflows/workflows/workflow.routes.js deleted file mode 100644 index aa58355..0000000 --- a/src/features/workflows/workflows/workflow.routes.js +++ /dev/null @@ -1,126 +0,0 @@ -import { Router } from 'express'; -import controller from './workflow.controller.js'; -import { authenticate } from '../../../shared/middleware/auth.middleware.js'; -import { validate } from '../../../shared/middleware/validation.middleware.js'; -import { authorize } from '../../../shared/middleware/permission.middleware.js'; -import { audit } from '../../../shared/middleware/audit.middleware.js'; -import { - createValidation, - updateValidation, - deleteValidation, - getByIdValidation -} from './workflow.validation.js'; - -const router = Router(); - -/** - * @swagger - * /api/v1/workflows: - * get: - * summary: Retrieve all workflows - * tags: [Workflows] - * responses: - * 200: - * description: Success - */ -router.get( - '/', - authenticate, - authorize(['read:workflows']), - controller.getAll -); - -/** - * @swagger - * /api/v1/workflows/{id}: - * get: - * summary: Retrieve a single workflow - * tags: [Workflows] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * responses: - * 200: - * description: Success - */ -router.get( - '/:id', - authenticate, - authorize(['read:workflows']), - getByIdValidation, - validate, - controller.getById -); - -/** - * @swagger - * /api/v1/workflows: - * post: - * summary: Create a workflow - * tags: [Workflows] - * responses: - * 201: - * description: Success - */ -router.post( - '/', - authenticate, - authorize(['write:workflows']), - createValidation, - validate, - audit('CREATE_WORKFLOW'), - controller.create -); - -/** - * @swagger - * /api/v1/workflows/{id}: - * put: - * summary: Update a workflow - * tags: [Workflows] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.put( - '/:id', - authenticate, - authorize(['write:workflows']), - updateValidation, - validate, - audit('UPDATE_WORKFLOW'), - controller.update -); - -/** - * @swagger - * /api/v1/workflows/{id}: - * delete: - * summary: Delete a workflow - * tags: [Workflows] - * parameters: - * - in: path - * name: id - * required: true - * responses: - * 200: - * description: Success - */ -router.delete( - '/:id', - authenticate, - authorize(['write:workflows']), - deleteValidation, - validate, - audit('DELETE_WORKFLOW'), - controller.delete -); - -export default router; diff --git a/src/features/workflows/workflows/workflow.service.js b/src/features/workflows/workflows/workflow.service.js deleted file mode 100644 index d8da1a2..0000000 --- a/src/features/workflows/workflows/workflow.service.js +++ /dev/null @@ -1,75 +0,0 @@ -import repository from './workflow.repository.js'; -import { SocketService } from '../../../shared/services/socket.service.js'; -import { AuditService } from '../../../shared/services/audit.service.js'; - -export class WorkflowService { - async getAll(query = {}) { - // Add business logic filtering, pagination, etc. - return await repository.findAll(); - } - - async getById(id) { - const record = await repository.findById(id); - if (!record) { - throw new Error('Workflow not found'); - } - return record; - } - - async create(data, userContext = {}) { - const record = await repository.create(data); - - // Broadcast event - SocketService.broadcast('workflow:created', record); - - // Log audit - await AuditService.log({ - action: 'CREATE', - resource: 'Workflow', - resourceId: record.id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async update(id, data, userContext = {}) { - const record = await repository.update(id, data); - if (!record) { - throw new Error('Workflow not found'); - } - - SocketService.broadcast('workflow:updated', record); - - await AuditService.log({ - action: 'UPDATE', - resource: 'Workflow', - resourceId: id, - userId: userContext.id || 'system', - details: data - }); - - return record; - } - - async delete(id, userContext = {}) { - const deleted = await repository.delete(id); - if (!deleted) { - throw new Error('Workflow not found'); - } - - SocketService.broadcast('workflow:deleted', { id }); - - await AuditService.log({ - action: 'DELETE', - resource: 'Workflow', - resourceId: id, - userId: userContext.id || 'system' - }); - - return true; - } -} - -export default new WorkflowService(); diff --git a/src/features/workflows/workflows/workflow.validation.js b/src/features/workflows/workflows/workflow.validation.js deleted file mode 100644 index 8a1aaf4..0000000 --- a/src/features/workflows/workflows/workflow.validation.js +++ /dev/null @@ -1,32 +0,0 @@ -import { body, param } from 'express-validator'; - -export const createValidation = [ - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const updateValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required'), - body('name') - .optional() - .isString() - .trim() - .withMessage('Name must be a string') -]; - -export const deleteValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; - -export const getByIdValidation = [ - param('id') - .isUUID() - .withMessage('Valid UUID is required') -]; diff --git a/src/shared/database/connection.js b/src/shared/database/connection.js index ecb4af1..4e498ef 100644 --- a/src/shared/database/connection.js +++ b/src/shared/database/connection.js @@ -39,14 +39,8 @@ export const connectDatabase = async () => { { node_code: 'products.variants', node_name: 'Variant Management', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, { node_code: 'products.attributes', node_name: 'Attribute Management', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, { node_code: 'masters.brands', node_name: 'Brands', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'masters.units', node_name: 'Units', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'inventory.stock', node_name: 'Inventory Stock', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'inventory.adjustments', node_name: 'Inventory Adjustments', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, { node_code: 'settings.users', node_name: 'Users', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'settings.roles', node_name: 'Roles & Permissions', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'settings.integrations', node_name: 'Integrations', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'reports.sales', node_name: 'Sales Reports', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true }, - { node_code: 'reports.inventory', node_name: 'Inventory Reports', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true } + { node_code: 'settings.roles', node_name: 'Roles & Permissions', node_type: 'feature', can_view: true, can_create: true, can_edit: true, can_delete: true } ]; for (const node of requiredNodes) { diff --git a/src/shared/database/models.js b/src/shared/database/models.js index 3259f07..a75f5d2 100644 --- a/src/shared/database/models.js +++ b/src/shared/database/models.js @@ -65,37 +65,16 @@ import userRoleModelInit from '../../features/authentication/access/userRole.mod import orgModelInit from '../../features/organization/org/org.model.js'; import metricModelInit from '../../features/dashboard/metrics/metric.model.js'; import productModelInit from '../../features/products/products/product.model.js'; -import variantModelInit from '../../features/products/variants/variant.model.js'; -import bundleModelInit from '../../features/products/bundles/bundle.model.js'; -import configurableProductModelInit from '../../features/products/configurableProducts/configurableProduct.model.js'; -import digitalProductModelInit from '../../features/products/digitalProducts/digitalProduct.model.js'; -import lifecycleModelInit from '../../features/products/lifecycle/lifecycle.model.js'; -import approvalModelInit from '../../features/products/approvals/approval.model.js'; -import publishingModelInit from '../../features/products/publishing/publishing.model.js'; import catalogModelInit from '../../features/catalogs/catalogs/catalog.model.js'; import categorieModelInit from '../../features/categories/categories/categorie.model.js'; import brandModelInit from '../../features/brands/brands/brand.model.js'; import attributeModelInit from '../../features/attributes/attributes/attribute.model.js'; import mediaModelInit from '../../features/media/media/media.model.js'; -import pricingModelInit from '../../features/pricing/pricing/pricing.model.js'; -import inventoryModelInit from '../../features/inventory/inventory/inventory.model.js'; -import supplierModelInit from '../../features/suppliers/suppliers/supplier.model.js'; -import localizationModelInit from '../../features/localization/localization/localization.model.js'; -import workflowModelInit from '../../features/workflows/workflows/workflow.model.js'; -import integrationModelInit from '../../features/integrations/integrations/integration.model.js'; -import channelModelInit from '../../features/channels/channels/channel.model.js'; -import importModelInit from '../../features/imports/imports/import.model.js'; -import exportModelInit from '../../features/exports/exports/export.model.js'; -import notificationModelInit from '../../features/notifications/notifications/notification.model.js'; -import reportModelInit from '../../features/reports/reports/report.model.js'; import settingModelInit from '../../features/settings/settings/setting.model.js'; import auditLogModelInit from '../../features/auditLogs/auditLogs/auditLog.model.js'; -import familyModelInit from '../../features/products/families/family.model.js'; import assetTypeModelInit from '../../features/media/assetTypes/assetType.model.js'; import assetFamilyModelInit from '../../features/media/assetFamilies/assetFamily.model.js'; import assetModelInit from '../../features/media/assets/asset.model.js'; -import unitModelInit from '../../features/units/units/unit.model.js'; - export const initializeDatabaseModels = () => { registerModel('Tenant', tenantModelInit); @@ -107,36 +86,16 @@ export const initializeDatabaseModels = () => { registerModel('Org', orgModelInit); registerModel('Metric', metricModelInit); registerModel('Product', productModelInit); - registerModel('Variant', variantModelInit); - registerModel('Bundle', bundleModelInit); - registerModel('ConfigurableProduct', configurableProductModelInit); - registerModel('DigitalProduct', digitalProductModelInit); - registerModel('Lifecycle', lifecycleModelInit); - registerModel('Approval', approvalModelInit); - registerModel('Publishing', publishingModelInit); registerModel('Catalog', catalogModelInit); registerModel('Categorie', categorieModelInit); registerModel('Brand', brandModelInit); registerModel('Attribute', attributeModelInit); registerModel('Media', mediaModelInit); - registerModel('Pricing', pricingModelInit); - registerModel('Inventory', inventoryModelInit); - registerModel('Supplier', supplierModelInit); - registerModel('Localization', localizationModelInit); - registerModel('Workflow', workflowModelInit); - registerModel('Integration', integrationModelInit); - registerModel('Channel', channelModelInit); - registerModel('Import', importModelInit); - registerModel('Export', exportModelInit); - registerModel('Notification', notificationModelInit); - registerModel('Report', reportModelInit); registerModel('Setting', settingModelInit); registerModel('AuditLog', auditLogModelInit); - registerModel('Family', familyModelInit); registerModel('AssetType', assetTypeModelInit); registerModel('AssetFamily', assetFamilyModelInit); registerModel('Asset', assetModelInit); - registerModel('Unit', unitModelInit); associateModels(); }; diff --git a/src/shared/utils/logger.js b/src/shared/utils/logger.js index b079911..dfb0bf8 100644 --- a/src/shared/utils/logger.js +++ b/src/shared/utils/logger.js @@ -1,5 +1,4 @@ import winston from 'winston'; -import DailyRotateFile from 'winston-daily-rotate-file'; const { combine, timestamp, printf, colorize, errors } = winston.format; @@ -15,28 +14,16 @@ export const logger = winston.createLogger({ logFormat ), transports: [ - new DailyRotateFile({ - filename: 'logs/error-%DATE%.log', - datePattern: 'YYYY-MM-DD', - level: 'error', - maxFiles: '14d', - }), - new DailyRotateFile({ - filename: 'logs/combined-%DATE%.log', - datePattern: 'YYYY-MM-DD', - maxFiles: '14d', - }), + new winston.transports.Console({ + format: combine( + colorize(), + timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), + logFormat + ), + }) ], }); -if (process.env.NODE_ENV !== 'production') { - logger.add(new winston.transports.Console({ - format: combine( - colorize(), - timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - logFormat - ), - })); -} + export default logger;