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