repair: brand + errorcode
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
const ErrorCodeService = require('../services/error_code.service');
|
||||
const { setResponse, setResponsePaging } = require('../helpers/utils');
|
||||
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
|
||||
const {
|
||||
insertErrorCodeSchema,
|
||||
updateErrorCodeSchema,
|
||||
} = require('../validate/error_code.schema');
|
||||
|
||||
class ErrorCodeController {
|
||||
static async getByBrandId(req, res) {
|
||||
@@ -23,15 +27,16 @@ class ErrorCodeController {
|
||||
|
||||
// Create error code with solutions and spareparts
|
||||
static async create(req, res) {
|
||||
const { error, value } = await checkValidate(insertErrorCodeSchema, req);
|
||||
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
const { brandId } = req.params;
|
||||
const createdBy = req.user?.user_id || null;
|
||||
value.created_by = req.user?.user_id || null;
|
||||
|
||||
const data = {
|
||||
...req.body,
|
||||
created_by: createdBy
|
||||
};
|
||||
|
||||
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, data);
|
||||
const result = await ErrorCodeService.createErrorCodeWithFullData(brandId, value);
|
||||
const response = setResponse(result, 'Error code created successfully');
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
@@ -39,15 +44,16 @@ class ErrorCodeController {
|
||||
|
||||
// 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 { error, value } = await checkValidate(updateErrorCodeSchema, req);
|
||||
|
||||
const data = {
|
||||
...req.body,
|
||||
updated_by: updatedBy
|
||||
};
|
||||
if (error) {
|
||||
return res.status(400).json(setResponse(error, 'Validation failed', 400));
|
||||
}
|
||||
|
||||
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCode, data);
|
||||
const { brandId, errorCodeId } = req.params;
|
||||
value.updated_by = req.user?.user_id || null;
|
||||
|
||||
const result = await ErrorCodeService.updateErrorCodeWithFullData(brandId, errorCodeId, value);
|
||||
const response = setResponse(result, 'Error code updated successfully');
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
@@ -55,10 +61,10 @@ class ErrorCodeController {
|
||||
|
||||
// Soft delete error code
|
||||
static async delete(req, res) {
|
||||
const { brandId, errorCode } = req.params;
|
||||
const { brandId, errorCodeId } = req.params;
|
||||
const deletedBy = req.user?.user_id || null;
|
||||
|
||||
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCode, deletedBy);
|
||||
const result = await ErrorCodeService.deleteErrorCode(brandId, errorCodeId, deletedBy);
|
||||
const response = setResponse(result, 'Error code deleted successfully');
|
||||
|
||||
res.status(response.statusCode).json(response);
|
||||
|
||||
Reference in New Issue
Block a user