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
/
fields.ts
84 lines (75 loc) · 2.05 KB
/
fields.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
import { Document, Schema } from 'mongoose';
import { FIELDS_GROUPS_CONTENT_TYPES } from './constants';
import { field } from './utils';
export interface IField {
contentType?: string;
contentTypeId?: string;
type?: string;
validation?: string;
text?: string;
description?: string;
options?: string[];
isRequired?: boolean;
isDefinedByErxes?: boolean;
order?: number;
groupId?: string;
isVisible?: boolean;
lastUpdatedUserId?: string;
}
export interface IFieldDocument extends IField, Document {
_id: string;
}
export interface IFieldGroup {
name?: string;
contentType?: string;
order?: number;
isDefinedByErxes?: boolean;
description?: string;
lastUpdatedUserId?: string;
isVisible?: boolean;
}
export interface IFieldGroupDocument extends IFieldGroup, Document {
_id: string;
}
// Mongoose schemas =============
export const fieldSchema = new Schema({
_id: field({ pkey: true }),
// form, customer, company
contentType: field({ type: String }),
// formId when contentType is form
contentTypeId: field({ type: String }),
type: field({ type: String }),
validation: field({
type: String,
optional: true,
}),
text: field({ type: String }),
description: field({
type: String,
optional: true,
}),
options: field({
type: [String],
optional: true,
}),
isRequired: field({ type: Boolean }),
isDefinedByErxes: field({ type: Boolean }),
order: field({ type: Number }),
groupId: field({ type: String }),
isVisible: field({ type: Boolean, default: true }),
lastUpdatedUserId: field({ type: String }),
});
export const fieldGroupSchema = new Schema({
_id: field({ pkey: true }),
name: field({ type: String }),
// customer, company
contentType: field({ type: String, enum: FIELDS_GROUPS_CONTENT_TYPES.ALL }),
order: field({ type: Number }),
isDefinedByErxes: field({ type: Boolean, default: false }),
description: field({
type: String,
}),
// Id of user who updated the group
lastUpdatedUserId: field({ type: String }),
isVisible: field({ type: Boolean, default: true }),
});