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
/
boards.ts
154 lines (139 loc) · 3.52 KB
/
boards.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { Document, Schema } from 'mongoose';
import { BOARD_TYPES, PIPELINE_VISIBLITIES, PROBABILITY } from './constants';
import { field, schemaWrapper } from './utils';
interface ICommonFields {
userId?: string;
createdAt?: Date;
order?: number;
type: string;
}
export interface IItemCommonFields {
name?: string;
companyIds?: string[];
customerIds?: string[];
closeDate?: Date;
description?: string;
assignedUserIds?: string[];
watchedUserIds?: string[];
notifiedUserIds?: string[];
attachments?: any[];
stageId?: string;
initialStageId?: string;
modifiedAt?: Date;
modifiedBy?: string;
userId?: string;
createdAt?: Date;
order?: number;
}
export interface IBoard extends ICommonFields {
name?: string;
isDefault?: boolean;
}
export interface IBoardDocument extends IBoard, Document {
_id: string;
}
export interface IPipeline extends ICommonFields {
name?: string;
boardId?: string;
visibility?: string;
memberIds?: string[];
bgColor?: string;
watchedUserIds?: string[];
}
export interface IPipelineDocument extends IPipeline, Document {
_id: string;
}
export interface IStage extends ICommonFields {
name?: string;
probability?: string;
pipelineId?: string;
}
export interface IStageDocument extends IStage, Document {
_id: string;
}
export interface IOrderInput {
_id: string;
order: number;
}
const attachmentSchema = new Schema(
{
name: field({ type: String }),
url: field({ type: String }),
type: field({ type: String }),
size: field({ type: Number, optional: true }),
},
{ _id: false },
);
// Mongoose schemas =======================
const commonFieldsSchema = {
userId: field({ type: String }),
createdAt: field({
type: Date,
default: new Date(),
}),
order: field({ type: Number }),
type: field({
type: String,
enum: BOARD_TYPES.ALL,
required: true,
}),
};
export const commonItemFieldsSchema = {
_id: field({ pkey: true }),
userId: field({ type: String }),
createdAt: field({
type: Date,
default: new Date(),
}),
order: field({ type: Number }),
name: field({ type: String }),
companyIds: field({ type: [String] }),
customerIds: field({ type: [String] }),
closeDate: field({ type: Date }),
description: field({ type: String, optional: true }),
assignedUserIds: field({ type: [String] }),
watchedUserIds: field({ type: [String] }),
attachments: field({ type: [attachmentSchema] }),
stageId: field({ type: String, optional: true }),
initialStageId: field({ type: String, optional: true }),
modifiedAt: field({
type: Date,
default: new Date(),
}),
modifiedBy: field({ type: String }),
};
export const boardSchema = schemaWrapper(
new Schema({
_id: field({ pkey: true }),
name: field({ type: String }),
isDefault: field({
type: Boolean,
default: false,
}),
...commonFieldsSchema,
}),
);
export const pipelineSchema = new Schema({
_id: field({ pkey: true }),
name: field({ type: String }),
boardId: field({ type: String }),
visibility: field({
type: String,
enum: PIPELINE_VISIBLITIES.ALL,
default: PIPELINE_VISIBLITIES.PUBLIC,
}),
watchedUserIds: field({ type: [String] }),
memberIds: field({ type: [String] }),
bgColor: field({ type: String }),
...commonFieldsSchema,
});
export const stageSchema = new Schema({
_id: field({ pkey: true }),
name: field({ type: String }),
probability: field({
type: String,
enum: PROBABILITY.ALL,
}), // Win probability
pipelineId: field({ type: String }),
...commonFieldsSchema,
});