Enhanced gcodeFile schema to populate part information during validation, improving data integrity for parts. Updated service functions to reflect changes in population logic for parts, ensuring accurate data retrieval.
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit is contained in:
parent
5a4fecbae0
commit
e1b6814efd
@ -28,6 +28,14 @@ gcodeFileSchema.pre('validate', async function () {
|
||||
const sku = await mongoose.model('filamentSku').findById(this.filamentSku).select('filament').lean();
|
||||
if (sku?.filament) this.filament = sku.filament;
|
||||
}
|
||||
if (this.parts?.length) {
|
||||
for (const partItem of this.parts) {
|
||||
if (!partItem.part && partItem.partSku) {
|
||||
const sku = await mongoose.model('partSku').findById(partItem.partSku).select('part').lean();
|
||||
if (sku?.part) partItem.part = sku.part;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
gcodeFileSchema.index({ name: 'text', gcodeFileName: 'text' });
|
||||
|
||||
@ -96,7 +96,7 @@ export const getGCodeFileRouteHandler = async (req, res) => {
|
||||
const result = await getObject({
|
||||
model: gcodeFileModel,
|
||||
id,
|
||||
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'parts.partSku'],
|
||||
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'parts.part', 'parts.partSku'],
|
||||
});
|
||||
if (result?.error) {
|
||||
logger.warn(`GCodeFile not found with supplied id.`);
|
||||
@ -143,7 +143,7 @@ export const editGCodeFileRouteHandler = async (req, res) => {
|
||||
id,
|
||||
updateData,
|
||||
user: req.user,
|
||||
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'parts.partSku'],
|
||||
populate: ['filament', { path: 'filamentSku', populate: 'filament' }, 'parts.part', 'parts.partSku'],
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user