Numerious fixes.

This commit is contained in:
Tom Butcher 2026-05-17 19:11:33 +01:00
parent c38c1dee24
commit b9b40c55ca
2 changed files with 16 additions and 0 deletions

View File

@ -19,6 +19,7 @@ const filamentStockSchema = new Schema(
net: { type: Number, required: true }, net: { type: Number, required: true },
gross: { type: Number, required: true }, gross: { type: Number, required: true },
}, },
filament: { type: mongoose.Schema.Types.ObjectId, ref: 'filament', required: true },
filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true }, filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true },
stockLocation: { stockLocation: {
type: mongoose.Schema.Types.ObjectId, type: mongoose.Schema.Types.ObjectId,
@ -29,6 +30,13 @@ const filamentStockSchema = new Schema(
{ timestamps: true } { timestamps: true }
); );
filamentStockSchema.pre('validate', async function () {
if (!this.filament && this.filamentSku) {
const sku = await mongoose.model('filamentSku').findById(this.filamentSku).select('filament').lean();
if (sku?.filament) this.filament = sku.filament;
}
});
const rollupConfigs = [ const rollupConfigs = [
{ {
name: 'totalCurrentWeight', name: 'totalCurrentWeight',

View File

@ -14,6 +14,7 @@ const gcodeFileSchema = new mongoose.Schema(
name: { required: true, type: String }, name: { required: true, type: String },
gcodeFileName: { required: false, type: String }, gcodeFileName: { required: false, type: String },
size: { type: Number, required: false }, size: { type: Number, required: false },
filament: { type: Schema.Types.ObjectId, ref: 'filament', required: true },
filamentSku: { type: Schema.Types.ObjectId, ref: 'filamentSku', required: true }, filamentSku: { type: Schema.Types.ObjectId, ref: 'filamentSku', required: true },
parts: [partSchema], parts: [partSchema],
file: { type: mongoose.SchemaTypes.ObjectId, ref: 'file', required: false }, file: { type: mongoose.SchemaTypes.ObjectId, ref: 'file', required: false },
@ -22,6 +23,13 @@ const gcodeFileSchema = new mongoose.Schema(
{ timestamps: true } { timestamps: true }
); );
gcodeFileSchema.pre('validate', async function () {
if (!this.filament && this.filamentSku) {
const sku = await mongoose.model('filamentSku').findById(this.filamentSku).select('filament').lean();
if (sku?.filament) this.filament = sku.filament;
}
});
gcodeFileSchema.index({ name: 'text', brand: 'text' }); gcodeFileSchema.index({ name: 'text', brand: 'text' });
gcodeFileSchema.virtual('id').get(function () { gcodeFileSchema.virtual('id').get(function () {