wisdom #63
@@ -28,7 +28,10 @@ class SparepartService {
|
||||
throw new ErrorHandler(404, "Sparepart not found");
|
||||
}
|
||||
|
||||
sparepart[0].sparepart_yearly = JSON.parse(sparepart[0].sparepart_yearly);
|
||||
if (sparepart[0]) {
|
||||
if (sparepart[0].sparepart_yearly) sparepart[0].sparepart_yearly = JSON.parse(sparepart[0].sparepart_yearly);
|
||||
if (sparepart[0].sparepart_monthly) sparepart[0].sparepart_monthly = JSON.parse(sparepart[0].sparepart_monthly);
|
||||
}
|
||||
|
||||
return sparepart[0];
|
||||
} catch (error) {
|
||||
@@ -49,6 +52,10 @@ class SparepartService {
|
||||
data.sparepart_yearly = JSON.stringify(data.sparepart_yearly);
|
||||
}
|
||||
|
||||
if (data.sparepart_monthly) {
|
||||
data.sparepart_monthly = JSON.stringify(data.sparepart_monthly);
|
||||
}
|
||||
|
||||
const created = await createSparepartDb(data);
|
||||
if (!created) throw new ErrorHandler(500, "Failed to create Sparepart");
|
||||
return created;
|
||||
@@ -70,14 +77,17 @@ class SparepartService {
|
||||
data.sparepart_number,
|
||||
id
|
||||
);
|
||||
if (exists)
|
||||
throw new ErrorHandler(400, "Sparepart name already exists");
|
||||
}
|
||||
|
||||
if (data.sparepart_yearly) {
|
||||
data.sparepart_yearly = JSON.stringify(data.sparepart_yearly);
|
||||
}
|
||||
|
||||
if (data.sparepart_monthly) {
|
||||
data.sparepart_monthly = JSON.stringify(data.sparepart_monthly);
|
||||
}
|
||||
|
||||
|
||||
const updated = await updateSparepartDb(id, data);
|
||||
if (!updated) throw new ErrorHandler(500, "Failed to update Sparepart");
|
||||
return await this.getSparepartById(id);
|
||||
|
||||
Reference in New Issue
Block a user