-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.js
101 lines (92 loc) · 1.71 KB
/
service.js
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
response.status = 400;
const FORM = [
{
"id": "1111",
"label": "First Name",
"name": "nameFirst",
"type": "text",
"required": 1
},
{
"id": "2222",
"label": "Last Name",
"name": "nameLast",
"type": "text",
"required": 1
},
{
"id": "3333",
"label": "Your Phone Number",
"name": "contactPhone",
"type": "tel",
"pattern": "[0-9]{10}",
"required": 0
},
{
"id": "4444",
"label": "Your Email",
"name": "contactEmail",
"type": "email",
"required": 0
},
{
"id": "5555",
"legend": "Your preferred contact",
"name": "contactPreferred",
"type": "radio",
"required": 1,
"options": [
{
"id": "5555-1",
"label": "Phone",
"value": "phone"
},
{
"id": "5555-2",
"label": "Email",
"value": "email"
}
]
}
];
const FORM_DATA = [
{
"name": "nameFirst",
"value": "Jane"
},
{
"name": "nameLast",
"value": "Doe"
},
{
"name": "contactPhone",
"value": "9999999999"
},
{
"name": "contactEmail",
"value": "jd@email.com"
},
{
"name": "contactPreferred",
"value": "phone"
}
];
if (request.request_method === 'GET') {
response.status = 200;
response.headers['Content-Type'] = 'application/json';
response.body = FORM;
}
if (request.request_method === 'POST') {
var submission = JSON.parse(request.body);
var res = {};
if (JSON.stringify(submission) === JSON.stringify(FORM_DATA)) {
response.status = 200;
response.body = {
message: 'Thank you for your submission.'
}
} else {
response.body = {
message: 'Your submission is invalid, please try again.'
}
}
}