wisdom #17

Merged
bragaz_rexita merged 8 commits from wisdom into main 2025-11-25 03:50:09 +00:00
2 changed files with 15 additions and 7 deletions
Showing only changes of commit 8dcdddb42f - Show all commits

View File

@@ -13,12 +13,14 @@ class SparepartController {
const response = await setResponsePaging(queryParams, results, 'Sparepart found');
res.status(response.statusCode).json(response);
}
static async getById(req, res) {
const { id } = req.params;
const results = await SparepartService.getSparepartById(id);
const response = await setResponse(results, 'Sparepart found');
res.status(response.statusCode).json(response);
}
static async create(req, res) {
const { error, value } = await checkValidate(insertSparepartSchema, req);
if (error) {

View File

@@ -20,16 +20,22 @@ class SparepartService {
throw new ErrorHandler(error.statusCode || 500, error.message);
}
}
static async getSparepartById(id) {
try {
const Sparepart = await getSparepartByIdDb(id);
if (!Sparepart) throw new ErrorHandler(404, "Sparepart not found");
return Sparepart;
const sparepart = await getSparepartByIdDb(id);
if (!sparepart || sparepart.length === 0) {
throw new ErrorHandler(404, "Sparepart not found");
}
return sparepart[0];
} catch (error) {
throw new ErrorHandler(error.statusCode || 500, error.message);
}
}
static async createSparepart(data) {
try {
if (!data || typeof data !== "object") data = {};