From 920ff53d1a9a4840fb6ad9198c5db176d70c7edf Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 17 Mar 2021 02:47:50 +0300 Subject: feat: allow multiple products in a waybill --- src/models/waybill/waybill.schema.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/models') diff --git a/src/models/waybill/waybill.schema.ts b/src/models/waybill/waybill.schema.ts index ce14525..bbebcd4 100644 --- a/src/models/waybill/waybill.schema.ts +++ b/src/models/waybill/waybill.schema.ts @@ -2,29 +2,41 @@ import { Document, Schema, Types } from 'mongoose'; export interface WaybillSchema extends Document { operation: 'in' | 'out'; - productId: string; - quantity: number; + records: [{ + productId: string; + price: number; + quantity: number; + }]; contractorId: string; status: 'waiting' | 'executed' | 'cancelled'; } -export const waybillSchema = new Schema({ - operation: { - type: String, - required: true, - }, - contractorId: { + +const recordSchema = new Schema({ + productId: { type: Types.ObjectId, required: true, }, - productId: { - type: Types.ObjectId, + price: { + type: Number, required: true, }, quantity: { type: Number, min: 1, }, +}); + +export const waybillSchema = new Schema({ + operation: { + type: String, + required: true, + }, + contractorId: { + type: Types.ObjectId, + required: true, + }, + records: [recordSchema], status: { type: String, default: 'waiting', -- cgit v1.2.3