Implemented Product SKU.
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good

This commit is contained in:
Tom Butcher 2026-03-07 22:42:03 +00:00
parent f358eaa1d0
commit d1dbbe2b11
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import mongoose from 'mongoose';
import { generateId } from '../../utils.js';
const { Schema } = mongoose;
// Define the main product SKU schema
const productSkuSchema = new Schema(
{
_reference: { type: String, default: () => generateId()() },
sku: { type: String, required: true },
product: { type: Schema.Types.ObjectId, ref: 'product', required: true },
name: { type: String, required: false },
description: { type: String, required: false },
},
{ timestamps: true }
);
// Add virtual id getter
productSkuSchema.virtual('id').get(function () {
return this._id;
});
// Configure JSON serialization to include virtuals
productSkuSchema.set('toJSON', { virtuals: true });
// Create and export the model
export const productSkuModel = mongoose.model('productSku', productSkuSchema);

View File

@ -5,6 +5,7 @@ import { filamentModel } from './management/filament.schema.js';
import { gcodeFileModel } from './production/gcodefile.schema.js'; import { gcodeFileModel } from './production/gcodefile.schema.js';
import { partModel } from './management/part.schema.js'; import { partModel } from './management/part.schema.js';
import { productModel } from './management/product.schema.js'; import { productModel } from './management/product.schema.js';
import { productSkuModel } from './management/productsku.schema.js';
import { vendorModel } from './management/vendor.schema.js'; import { vendorModel } from './management/vendor.schema.js';
import { filamentStockModel } from './inventory/filamentstock.schema.js'; import { filamentStockModel } from './inventory/filamentstock.schema.js';
import { purchaseOrderModel } from './inventory/purchaseorder.schema.js'; import { purchaseOrderModel } from './inventory/purchaseorder.schema.js';
@ -73,6 +74,13 @@ export const models = {
referenceField: '_reference', referenceField: '_reference',
label: 'Product', label: 'Product',
}, },
PSK: {
model: productSkuModel,
idField: '_id',
type: 'productSku',
referenceField: '_reference',
label: 'Product SKU',
},
VEN: { VEN: {
model: vendorModel, model: vendorModel,
idField: '_id', idField: '_id',