Enhance filament schema by adding vendor reference and improving formatting
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Introduced a new optional field `vendor` in the filament schema to reference the vendor associated with the filament. - Improved code formatting for better readability and maintainability, including consistent indentation and line breaks. - Ensured that the `recalculate` method remains functional with updated schema structure.
This commit is contained in:
parent
766f4722ea
commit
0a1f75d050
@ -3,20 +3,28 @@ import { generateId } from '../../utils.js';
|
|||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose;
|
||||||
|
|
||||||
// Filament base - cost and tax; color and cost override at FilamentSKU
|
// Filament base - cost and tax; color and cost override at FilamentSKU
|
||||||
const filamentSchema = new mongoose.Schema({
|
const filamentSchema = new mongoose.Schema(
|
||||||
_reference: { type: String, default: () => generateId()() },
|
{
|
||||||
name: { required: true, type: String },
|
_reference: { type: String, default: () => generateId()() },
|
||||||
barcode: { required: false, type: String },
|
name: { required: true, type: String },
|
||||||
url: { required: false, type: String },
|
vendor: { required: false, type: Schema.Types.ObjectId, ref: 'vendor' },
|
||||||
image: { required: false, type: Buffer },
|
barcode: { required: false, type: String },
|
||||||
material: { type: Schema.Types.ObjectId, ref: 'material', required: true },
|
url: { required: false, type: String },
|
||||||
diameter: { required: true, type: Number },
|
image: { required: false, type: Buffer },
|
||||||
density: { required: true, type: Number },
|
material: { type: Schema.Types.ObjectId, ref: 'material', required: true },
|
||||||
emptySpoolWeight: { required: true, type: Number },
|
diameter: { required: true, type: Number },
|
||||||
cost: { type: Number, required: false },
|
density: { required: true, type: Number },
|
||||||
costTaxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
emptySpoolWeight: { required: true, type: Number },
|
||||||
costWithTax: { type: Number, required: false },
|
cost: { type: Number, required: false },
|
||||||
}, { timestamps: true });
|
costTaxRate: {
|
||||||
|
type: Schema.Types.ObjectId,
|
||||||
|
ref: 'taxRate',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
costWithTax: { type: Number, required: false }
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
filamentSchema.index({ name: 'text', barcode: 'text', url: 'text' });
|
filamentSchema.index({ name: 'text', barcode: 'text', url: 'text' });
|
||||||
|
|
||||||
@ -28,7 +36,10 @@ filamentSchema.set('toJSON', { virtuals: true });
|
|||||||
|
|
||||||
filamentSchema.statics.recalculate = async function (filament, user) {
|
filamentSchema.statics.recalculate = async function (filament, user) {
|
||||||
const filamentSkuModel = mongoose.model('filamentSku');
|
const filamentSkuModel = mongoose.model('filamentSku');
|
||||||
const skus = await filamentSkuModel.find({ filament: filament._id }).select('_id').lean();
|
const skus = await filamentSkuModel
|
||||||
|
.find({ filament: filament._id })
|
||||||
|
.select('_id')
|
||||||
|
.lean();
|
||||||
for (const sku of skus) {
|
for (const sku of skus) {
|
||||||
await filamentSkuModel.recalculate(sku, user);
|
await filamentSkuModel.recalculate(sku, user);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user