Add Backend Support for Managing Malfunctioning Products with Enhanced Validation and Error Handling #1006
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This pull request introduces the backend logic for managing malfunctioning products in the system. The key features include:
MalfunctioningProduct
that links to aProduct
and stores details about the malfunction, actions taken, and the user responsible.createMalfunctioningProduct
: Handles product creation with validation.getMalfunctioningProduct
: Fetches a specific malfunctioning product by ID.updateMalfunctioningProduct
: Updates existing malfunctioning product data.deleteMalfunctioningProduct
: Deletes a malfunctioning product.getAllMalfunctioningProducts
: Supports pagination and search functionality.getMalfunctioningProductCountByStatus
: Provides counts of malfunctioning products by their status.Changes Introduced:
MalfunctioningProduct
model inmodels/MalfunctioningProduct.js
.controllers/MalfunctioningProductController.js
for managing CRUD operations and handling errors.middlewares/validationMiddleware.js
for the input fields for both product creation and updates.routes/malfunctioningProductRoutes.js
to handle the backend logic for the malfunctioning products.middlewares/authenticationMiddleware.js
to authenticate requests.Why This PR is Necessary:
Test Cases to Be Covered:
Create Product:
productId
orcreatedBy
fields.description
,actionsTaken
).Get Product:
Update Product:
Delete Product:
Pagination and Search:
page
andlimit
query parameters.description
field).Get Count by Status:
pending
,in progress
,resolved
).How to Test:
Files Changed:
models/MalfunctioningProduct.js
- Defines the Malfunctioning Product model.controllers/MalfunctioningProductController.js
- Contains CRUD operations and business logic for malfunctioning products.middlewares/validationMiddleware.js
- Includes validation logic for the creation and update of malfunctioning products.middlewares/authenticationMiddleware.js
- Implements authentication for routes.routes/malfunctioningProductRoutes.js
- Defines API routes for malfunctioning products.Example Requests:
Create Malfunctioning Product:
POST
/api/malfunctioning-products
Request Body:
Get Malfunctioning Product by ID:
GET
/api/malfunctioning-products/:id
Example Response:
Update Malfunctioning Product:
PUT
/api/malfunctioning-products/:id
Request Body:
Delete Malfunctioning Product:
DELETE
/api/malfunctioning-products/:id
Additional Notes: