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
/
forms.ts
81 lines (74 loc) · 2.02 KB
/
forms.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
import { Document, Schema } from 'mongoose';
import { IRule, ruleSchema } from './common';
import { field, schemaWrapper } from './utils';
export interface ICallout extends Document {
title?: string;
body?: string;
buttonText?: string;
featuredImage?: string;
skip?: boolean;
}
interface ISubmission extends Document {
customerId: string;
submittedAt: Date;
}
export interface IForm {
title: string;
code?: string;
description?: string;
buttonText?: string;
themeColor?: string;
callout?: ICallout;
rules?: IRule;
}
export interface IFormDocument extends IForm, Document {
_id: string;
createdUserId: string;
createdDate: Date;
viewCount: number;
contactsGathered: number;
submissions: ISubmission[];
}
// schema for form's callout component
const calloutSchema = new Schema(
{
title: field({ type: String, optional: true }),
body: field({ type: String, optional: true }),
buttonText: field({ type: String, optional: true }),
featuredImage: field({ type: String, optional: true }),
skip: field({ type: Boolean, optional: true }),
},
{ _id: false },
);
// schema for form submission details
const submissionSchema = new Schema(
{
customerId: field({ type: String }),
submittedAt: field({ type: Date }),
},
{ _id: false },
);
// schema for form document
export const formSchema = schemaWrapper(
new Schema({
_id: field({ pkey: true }),
title: field({ type: String, optional: true }),
description: field({
type: String,
optional: true,
}),
buttonText: field({ type: String, optional: true }),
themeColor: field({ type: String, optional: true }),
code: field({ type: String }),
createdUserId: field({ type: String }),
createdDate: field({
type: Date,
default: Date.now,
}),
callout: field({ type: calloutSchema, default: {} }),
viewCount: field({ type: Number }),
contactsGathered: field({ type: Number }),
submissions: field({ type: [submissionSchema] }),
rules: field({ type: [ruleSchema] }),
}),
);