summaryrefslogtreecommitdiff
path: root/src/models/waybill/waybill.schema.ts
blob: 55d2127f0b458d9d3c37162de7789632d8eee833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Document, Schema, Types } from 'mongoose';

export interface WaybillSchema extends Document {
  date: string;
  operation: 'in' | 'out';
  records: [{
    productId: string;
    price: number;
    quantity: number;
  }];
  contractorId: string;
  status: 'waiting' | 'executed' | 'cancelled';
}


const recordSchema = new Schema({
  productId: {
    type: Types.ObjectId,
    required: true,
  },
  price: {
    type: Number,
    required: true,
  },
  quantity: {
    type: Number,
    min: 1,
  },
});

export const waybillSchema = new Schema({
  date: {
    type: Date,
    required: true,
  },
  operation: {
    type: String,
    required: true,
  },
  contractorId: {
    type: Types.ObjectId,
    required: true,
  },
  records: [recordSchema],
  status: {
    type: String,
    default: 'waiting',
  },
}, { timestamps: true });