-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (37 loc) · 1.65 KB
/
index.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
///<reference path="utilities.ts"/>
import { Questions, Order } from './index.types';
const SALES_ORDER_ID = '1eICUwBol5a2SPT_6FHE17FiNEQyYD-eAkDcJTuMoVWQ';
const DELIVERY_ORDER_ID = '';
const form = FormApp.getActiveForm();
const docs = DocumentApp.openById(SALES_ORDER_ID);
function onSubmit() {
const response: Questions = {};
const formResponse = form.getResponses().slice(-1).pop();
const itemResponses = formResponse.getItemResponses();
for (let i = 0; i < itemResponses.length; i++) {
const itemResponse = itemResponses[i];
const titleResponse = itemResponse.getItem().getTitle();
const answerResponse = itemResponse.getResponse();
if (!titleResponse.includes('PDPA'))
response[titleResponse] = answerResponse;
}
return normalize(response);
}
function normalize(response: Questions) {
const data: Order = {};
data['Shirt_Size'] = response['What is your size?'];
data['Shirt_Quantity'] = response['How many t-shirts are you purchasing?'];
data['Delivery_Type'] = response['How do you want your t-shirts delivered?'];
data['Delivery_Location'] = response['Mailing Address'];
data['Delivery_Postal_Code'] = response['Postal Code'];
data['Customer_Name'] = response['Full Name'];
data['Customer_Tel'] = Util.formatInternational(response['Contact Number']);
data['Customer_HomeTel'] = Util.formatInternational(response['Home Number']);
data['Customer_Email'] = response['Email Address'];
data['Customer_Graduating_Class'] = response['Graduating Class'];
data['Customer_Graduating_Year'] = response['Graduating Year'];
return documentMergeData(data);
}
function documentMergeData(order: Order) {
Logger.log(order);
}