repair: error code detail
This commit is contained in:
@@ -1,104 +1,70 @@
|
|||||||
const ErrorCodeService = require('../services/error_code.service');
|
const ErrorCodeService = require('../services/error_code.service');
|
||||||
const { setResponse, setResponsePaging } = require('../helpers/utils');
|
const { setResponse, setResponsePaging } = require('../helpers/utils');
|
||||||
const { ErrorHandler } = require('../helpers/error');
|
|
||||||
|
|
||||||
class ErrorCodeController {
|
class ErrorCodeController {
|
||||||
// Get all error codes with pagination and search
|
static async getByBrandId(req, res) {
|
||||||
static async getAll(req, res) {
|
const { brandId } = req.params;
|
||||||
try {
|
const queryParams = {
|
||||||
const queryParams = req.query;
|
...req.query,
|
||||||
const results = await ErrorCodeService.getAllErrorCodes(queryParams);
|
brand_id: brandId
|
||||||
const response = await setResponsePaging(queryParams, results, 'Error codes found');
|
};
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
const results = await ErrorCodeService.getAllErrorCodes(queryParams);
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
const response = await setResponsePaging(queryParams, results, 'Error codes found');
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
res.status(response.statusCode).json(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get error code by ID
|
// Get error code by ID
|
||||||
static async getById(req, res) {
|
static async getById(req, res) {
|
||||||
try {
|
const { id } = req.params;
|
||||||
const { id } = req.params;
|
const result = await ErrorCodeService.getErrorCodeById(id);
|
||||||
const result = await ErrorCodeService.getErrorCodeById(id);
|
const response = setResponse(result, 'Error code found');
|
||||||
const response = setResponse(result, 200, 'Error code found');
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get error codes by brand ID with pagination and search
|
res.status(response.statusCode).json(response);
|
||||||
static async getByBrandId(req, res) {
|
|
||||||
try {
|
|
||||||
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);
|
|
||||||
} catch (error) {
|
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create error code with solutions and spareparts
|
// Create error code with solutions and spareparts
|
||||||
static async create(req, res) {
|
static async create(req, res) {
|
||||||
try {
|
const { brandId } = req.params;
|
||||||
const { brandId } = req.params;
|
const createdBy = req.user?.user_id || null;
|
||||||
const createdBy = req.user?.user_id || null;
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
...req.body,
|
...req.body,
|
||||||
created_by: createdBy
|
created_by: createdBy
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, data);
|
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, data);
|
||||||
const response = setResponse(result, 201, 'Error code created successfully');
|
const response = setResponse(result, 'Error code created successfully');
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
res.status(response.statusCode).json(response);
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update error code with solutions and spareparts
|
// Update error code with solutions and spareparts
|
||||||
static async update(req, res) {
|
static async update(req, res) {
|
||||||
try {
|
const { brandId, errorCode } = req.params;
|
||||||
const { brandId, errorCode } = req.params;
|
const updatedBy = req.user?.user_id || null;
|
||||||
const updatedBy = req.user?.user_id || null;
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
...req.body,
|
...req.body,
|
||||||
updated_by: updatedBy
|
updated_by: updatedBy
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCode, data);
|
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCode, data);
|
||||||
const response = setResponse(result, 200, 'Error code updated successfully');
|
const response = setResponse(result, 'Error code updated successfully');
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
res.status(response.statusCode).json(response);
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soft delete error code
|
// Soft delete error code
|
||||||
static async delete(req, res) {
|
static async delete(req, res) {
|
||||||
try {
|
const { brandId, errorCode } = req.params;
|
||||||
const { brandId, errorCode } = req.params;
|
const deletedBy = req.user?.user_id || null;
|
||||||
const deletedBy = req.user?.user_id || null;
|
|
||||||
|
|
||||||
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCode, deletedBy);
|
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCode, deletedBy);
|
||||||
const response = setResponse(result, 200, 'Error code deleted successfully');
|
const response = setResponse(result, 'Error code deleted successfully');
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
} catch (error) {
|
res.status(response.statusCode).json(response);
|
||||||
const response = setResponse(error.message, error.statusCode || 500);
|
|
||||||
res.status(response.statusCode).json(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user