This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
deals.ts
79 lines (69 loc) · 1.88 KB
/
deals.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Document, Schema } from 'mongoose';
import { commonItemFieldsSchema, IItemCommonFields } from './boards';
import { PRODUCT_TYPES } from './constants';
import { field } from './utils';
export interface IProduct {
name: string;
type?: string;
description?: string;
sku?: string;
productId?: string;
}
export interface IProductDocument extends IProduct, Document {
_id: string;
createdAt: Date;
}
interface IProductData extends Document {
productId: string;
uom: string;
currency: string;
quantity: number;
unitPrice: number;
taxPercent?: number;
tax?: number;
discountPercent?: number;
discount?: number;
amount?: number;
}
export interface IDeal extends IItemCommonFields {
productsData?: IProductData[];
}
export interface IDealDocument extends IDeal, Document {
_id: string;
}
// Mongoose schemas =======================
export const productSchema = new Schema({
_id: field({ pkey: true }),
name: field({ type: String }),
type: field({
type: String,
enum: PRODUCT_TYPES.ALL,
default: PRODUCT_TYPES.PRODUCT,
}),
description: field({ type: String, optional: true }),
sku: field({ type: String, optional: true }), // Stock Keeping Unit
createdAt: field({
type: Date,
default: new Date(),
}),
});
const productDataSchema = new Schema(
{
_id: field({ type: String }),
productId: field({ type: String }),
uom: field({ type: String }), // Units of measurement
currency: field({ type: String }),
quantity: field({ type: Number }),
unitPrice: field({ type: Number }),
taxPercent: field({ type: Number }),
tax: field({ type: Number }),
discountPercent: field({ type: Number }),
discount: field({ type: Number }),
amount: field({ type: Number }),
},
{ _id: false },
);
export const dealSchema = new Schema({
...commonItemFieldsSchema,
productsData: field({ type: [productDataSchema] }),
});