repair: get detail sparepart
This commit is contained in:
@@ -13,12 +13,14 @@ class SparepartController {
|
|||||||
const response = await setResponsePaging(queryParams, results, 'Sparepart found');
|
const response = await setResponsePaging(queryParams, results, 'Sparepart found');
|
||||||
res.status(response.statusCode).json(response);
|
res.status(response.statusCode).json(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getById(req, res) {
|
static async getById(req, res) {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const results = await SparepartService.getSparepartById(id);
|
const results = await SparepartService.getSparepartById(id);
|
||||||
const response = await setResponse(results, 'Sparepart found');
|
const response = await setResponse(results, 'Sparepart found');
|
||||||
res.status(response.statusCode).json(response);
|
res.status(response.statusCode).json(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async create(req, res) {
|
static async create(req, res) {
|
||||||
const { error, value } = await checkValidate(insertSparepartSchema, req);
|
const { error, value } = await checkValidate(insertSparepartSchema, req);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -20,15 +20,21 @@ class SparepartService {
|
|||||||
throw new ErrorHandler(error.statusCode || 500, error.message);
|
throw new ErrorHandler(error.statusCode || 500, error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async getSparepartById(id) {
|
|
||||||
try {
|
static async getSparepartById(id) {
|
||||||
const Sparepart = await getSparepartByIdDb(id);
|
try {
|
||||||
if (!Sparepart) throw new ErrorHandler(404, "Sparepart not found");
|
const sparepart = await getSparepartByIdDb(id);
|
||||||
return Sparepart;
|
|
||||||
} catch (error) {
|
if (!sparepart || sparepart.length === 0) {
|
||||||
throw new ErrorHandler(error.statusCode || 500, error.message);
|
throw new ErrorHandler(404, "Sparepart not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sparepart[0];
|
||||||
|
} catch (error) {
|
||||||
|
throw new ErrorHandler(error.statusCode || 500, error.message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static async createSparepart(data) {
|
static async createSparepart(data) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user