Implemented Product SKU.
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
This commit is contained in:
parent
f358eaa1d0
commit
d1dbbe2b11
26
src/database/schemas/management/productsku.schema.js
Normal file
26
src/database/schemas/management/productsku.schema.js
Normal 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);
|
||||
@ -5,6 +5,7 @@ import { filamentModel } from './management/filament.schema.js';
|
||||
import { gcodeFileModel } from './production/gcodefile.schema.js';
|
||||
import { partModel } from './management/part.schema.js';
|
||||
import { productModel } from './management/product.schema.js';
|
||||
import { productSkuModel } from './management/productsku.schema.js';
|
||||
import { vendorModel } from './management/vendor.schema.js';
|
||||
import { filamentStockModel } from './inventory/filamentstock.schema.js';
|
||||
import { purchaseOrderModel } from './inventory/purchaseorder.schema.js';
|
||||
@ -73,6 +74,13 @@ export const models = {
|
||||
referenceField: '_reference',
|
||||
label: 'Product',
|
||||
},
|
||||
PSK: {
|
||||
model: productSkuModel,
|
||||
idField: '_id',
|
||||
type: 'productSku',
|
||||
referenceField: '_reference',
|
||||
label: 'Product SKU',
|
||||
},
|
||||
VEN: {
|
||||
model: vendorModel,
|
||||
idField: '_id',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user