Updated product stock schema to include default state as 'draft', added 'postedAt' field, and introduced rollup configurations for 'draft' and 'posted' states.
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
a9999f95d0
commit
f358eaa1d0
@ -14,9 +14,10 @@ const productStockSchema = new Schema(
|
|||||||
{
|
{
|
||||||
_reference: { type: String, default: () => generateId()() },
|
_reference: { type: String, default: () => generateId()() },
|
||||||
state: {
|
state: {
|
||||||
type: { type: String, required: true },
|
type: { type: String, required: true, default: 'draft' },
|
||||||
progress: { type: Number, required: false },
|
progress: { type: Number, required: false },
|
||||||
},
|
},
|
||||||
|
postedAt: { type: Date, required: false },
|
||||||
product: { type: mongoose.Schema.Types.ObjectId, ref: 'product', required: true },
|
product: { type: mongoose.Schema.Types.ObjectId, ref: 'product', required: true },
|
||||||
currentQuantity: { type: Number, required: true },
|
currentQuantity: { type: Number, required: true },
|
||||||
partStocks: [partStockUsageSchema],
|
partStocks: [partStockUsageSchema],
|
||||||
@ -30,6 +31,16 @@ const rollupConfigs = [
|
|||||||
filter: {},
|
filter: {},
|
||||||
rollups: [{ name: 'totalCurrentQuantity', property: 'currentQuantity', operation: 'sum' }],
|
rollups: [{ name: 'totalCurrentQuantity', property: 'currentQuantity', operation: 'sum' }],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'draft',
|
||||||
|
filter: { 'state.type': 'draft' },
|
||||||
|
rollups: [{ name: 'draft', property: 'state.type', operation: 'count' }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'posted',
|
||||||
|
filter: { 'state.type': 'posted' },
|
||||||
|
rollups: [{ name: 'posted', property: 'state.type', operation: 'count' }],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
productStockSchema.statics.stats = async function () {
|
productStockSchema.statics.stats = async function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user