feat: add sparepart_number and sparepart_yearly fields to sparepart schema and database queries

This commit is contained in:
2026-04-25 19:40:53 +07:00
parent 0ce6a04f97
commit cb5e864206
3 changed files with 28 additions and 0 deletions

View File

@@ -28,6 +28,8 @@ class SparepartService {
throw new ErrorHandler(404, "Sparepart not found");
}
sparepart[0].sparepart_yearly = JSON.parse(sparepart[0].sparepart_yearly);
return sparepart[0];
} catch (error) {
throw new ErrorHandler(error.statusCode || 500, error.message);
@@ -42,6 +44,11 @@ class SparepartService {
if (exists)
throw new ErrorHandler(400, "Sparepart name already exists");
}
if (data.sparepart_yearly) {
data.sparepart_yearly = JSON.stringify(data.sparepart_yearly);
}
const created = await createSparepartDb(data);
if (!created) throw new ErrorHandler(500, "Failed to create Sparepart");
return created;
@@ -65,6 +72,11 @@ class SparepartService {
if (exists)
throw new ErrorHandler(400, "Sparepart name already exists");
}
if (data.sparepart_yearly) {
data.sparepart_yearly = JSON.stringify(data.sparepart_yearly);
}
const updated = await updateSparepartDb(id, data);
if (!updated) throw new ErrorHandler(500, "Failed to update Sparepart");
return await this.getSparepartById(id);