diff --git a/src/database/schemas/production/gcodefile.schema.js b/src/database/schemas/production/gcodefile.schema.js index a30eac2..964f619 100644 --- a/src/database/schemas/production/gcodefile.schema.js +++ b/src/database/schemas/production/gcodefile.schema.js @@ -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' });