const ErrorCodeService = require('../services/error_code.service'); const { setResponse, setResponsePaging } = require('../helpers/utils'); class ErrorCodeController { static async getByBrandId(req, res) { const { brandId } = req.params; const queryParams = { ...req.query, brand_id: brandId }; const results = await ErrorCodeService.getAllErrorCodes(queryParams); const response = await setResponsePaging(queryParams, results, 'Error codes found'); res.status(response.statusCode).json(response); } // Get error code by ID static async getById(req, res) { const { id } = req.params; const result = await ErrorCodeService.getErrorCodeById(id); const response = setResponse(result, 'Error code found'); res.status(response.statusCode).json(response); } // Create error code with solutions and spareparts static async create(req, res) { const { brandId } = req.params; const createdBy = req.user?.user_id || null; const data = { ...req.body, created_by: createdBy }; const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, data); const response = setResponse(result, 'Error code created successfully'); res.status(response.statusCode).json(response); } // Update error code with solutions and spareparts static async update(req, res) { const { brandId, errorCode } = req.params; const updatedBy = req.user?.user_id || null; const data = { ...req.body, updated_by: updatedBy }; const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCode, data); const response = setResponse(result, 'Error code updated successfully'); res.status(response.statusCode).json(response); } // Soft delete error code static async delete(req, res) { const { brandId, errorCode } = req.params; const deletedBy = req.user?.user_id || null; const result = await ErrorCodeService.deleteErrorCode(brandId, errorCode, deletedBy); const response = setResponse(result, 'Error code deleted successfully'); res.status(response.statusCode).json(response); } } module.exports = ErrorCodeController;