Skip to content

Commit 8ea97d3

Browse files
committed
added formatting
1 parent ce47855 commit 8ea97d3

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"prettier" // Make sure this is the last
5+
]
6+
}

.prettierrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2-
"tabWidth": 2,
3-
"useTabs": false
2+
"jsxSingleQuote": true,
3+
"semi": false,
4+
"singleQuote": true,
5+
"trailingComma": "es5"
46
}

src/index.js

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const parseText = (text) => {
1515
const parsedText = {
1616
taskType: textArray[0].trim(),
1717
taskTime: textArray[1].trim(),
18-
taskText: textArray[2].trim()
18+
taskText: textArray[2].trim(),
1919
}
2020

2121
return parsedText
@@ -25,7 +25,7 @@ const parseText = (text) => {
2525
const determineTaskType = (taskTypes, searchString) => {
2626
const options = {
2727
includeScore: true,
28-
keys: ['taskTypes.name']
28+
keys: ['taskTypes.name'],
2929
}
3030

3131
const fuse = new Fuse(taskTypes, options)
@@ -42,7 +42,7 @@ const returnTaskTypes = async (env) => {
4242
const url = `${codaEP}/docs/${docId}/tables/${typesTableId}/rows`
4343
const headers = {
4444
'Content-Type': 'application/json',
45-
'Authorization': `Bearer ${env.CODA_API_KEY}`
45+
Authorization: `Bearer ${env.CODA_API_KEY}`,
4646
}
4747

4848
const init = {
@@ -51,44 +51,52 @@ const returnTaskTypes = async (env) => {
5151
}
5252

5353
try {
54-
const response = await fetch(url, init);
54+
const response = await fetch(url, init)
5555
const rj = await response.json()
5656
return rj
5757
} catch (e) {
5858
console.log(e)
59-
return new Response("Oops! Something went wrong. Please try again later.")
59+
return new Response('Oops! Something went wrong. Please try again later.')
6060
}
6161
}
6262

6363
const generateCodaData = async (message, env) => {
6464
const simple = !message.includes(delimiter)
6565

66-
let data = {rows: [{cells: []}]};
66+
let data = { rows: [{ cells: [] }] }
6767

6868
function Cell(columnName, column, value) {
6969
this.column = column
7070
this.value = value
7171
}
7272

73-
if(simple) {
74-
data.rows[0].cells.push(new Cell("Task Name", "c-70z9tdOF3c", message))
75-
data.rows[0].cells.push(new Cell("Task Status", "c-kN87N8b6Gr", "Backlog"))
76-
data.rows[0].cells.push(new Cell("Needs Triage", "c-2alHSrothg", true))
73+
if (simple) {
74+
data.rows[0].cells.push(new Cell('Task Name', 'c-70z9tdOF3c', message))
75+
data.rows[0].cells.push(new Cell('Task Status', 'c-kN87N8b6Gr', 'Backlog'))
76+
data.rows[0].cells.push(new Cell('Needs Triage', 'c-2alHSrothg', true))
7777
} else {
7878
const taskTypeTable = await returnTaskTypes(env)
79-
const taskTypes = taskTypeTable.items.map(item => item.name)
79+
const taskTypes = taskTypeTable.items.map((item) => item.name)
8080
const parsedText = parseText(message)
8181
const taskTypeMatch = determineTaskType(taskTypes, parsedText.taskType)
82-
82+
8383
if (!taskTypeMatch) {
84-
return console.error("Sorry, I don't know that task type. Please try again.")
84+
return console.error(
85+
"Sorry, I don't know that task type. Please try again."
86+
)
8587
}
8688

87-
data.rows[0].cells.push(new Cell("Task Name", "c-70z9tdOF3c", parsedText.taskText))
88-
data.rows[0].cells.push(new Cell("Task Status", "c-kN87N8b6Gr", "Backlog"))
89-
data.rows[0].cells.push(new Cell("Task Type", "c-eDVIqu2xj_", taskTypeMatch))
90-
data.rows[0].cells.push(new Cell("Predicted Duration", "c-L4lltHxi-h", parsedText.taskTime, ))
91-
data.rows[0].cells.push(new Cell("Needs Triage", "c-2alHSrothg", true))
89+
data.rows[0].cells.push(
90+
new Cell('Task Name', 'c-70z9tdOF3c', parsedText.taskText)
91+
)
92+
data.rows[0].cells.push(new Cell('Task Status', 'c-kN87N8b6Gr', 'Backlog'))
93+
data.rows[0].cells.push(
94+
new Cell('Task Type', 'c-eDVIqu2xj_', taskTypeMatch)
95+
)
96+
data.rows[0].cells.push(
97+
new Cell('Predicted Duration', 'c-L4lltHxi-h', parsedText.taskTime)
98+
)
99+
data.rows[0].cells.push(new Cell('Needs Triage', 'c-2alHSrothg', true))
92100
}
93101
return data
94102
}
@@ -104,7 +112,7 @@ const addCodaTodo = async (message, env) => {
104112
const url = `${codaEP}/docs/${docId}/tables/${taskTableId}/rows`
105113
const headers = {
106114
'Content-Type': 'application/json',
107-
'Authorization': 'Bearer ' + CODA_API_KEY
115+
Authorization: 'Bearer ' + CODA_API_KEY,
108116
}
109117

110118
const init = {
@@ -114,46 +122,46 @@ const addCodaTodo = async (message, env) => {
114122
}
115123

116124
try {
117-
const response = await fetch(url, init);
125+
const response = await fetch(url, init)
118126
const rj = await response.json()
119127
return rj
120128
} catch (e) {
121129
console.log(e)
122-
return new Response("Oops! Something went wrong. Please try again later.")
130+
return new Response('Oops! Something went wrong. Please try again later.')
123131
}
124132
}
125133

126134
export default {
127135
async fetch(request, env) {
128136
const OUTBOUND_PHONE = env.OUTBOUND_PHONE
129-
137+
130138
if (request.method != 'POST') {
131-
return new Response("Method Not Allowed", {
132-
status: 405
139+
return new Response('Method Not Allowed', {
140+
status: 405,
133141
})
134142
}
135143

136144
// Get body of the request - will be text since it's URL encoded
137-
const data = await request.text();
145+
const data = await request.text()
138146

139147
// Decode URL
140-
const params = new URLSearchParams(data);
148+
const params = new URLSearchParams(data)
141149
// Get query params and put in a JS object
142-
const twilioObject = Object.fromEntries(params.entries());
143-
const fromNumber = twilioObject.From;
150+
const twilioObject = Object.fromEntries(params.entries())
151+
const fromNumber = twilioObject.From
144152

145153
// Only allow texts from the users number
146154
if (fromNumber != OUTBOUND_PHONE) {
147-
return new Response("Forbidden", {
148-
status: 403
155+
return new Response('Forbidden', {
156+
status: 403,
149157
})
150158
}
151159

152-
const message = twilioObject.Body;
160+
const message = twilioObject.Body
153161

154162
const response = await addCodaTodo(message, env)
155163
console.log(JSON.stringify(response))
156164

157-
return new Response("Item successfully added!")
165+
return new Response('Item successfully added!')
158166
},
159-
};
167+
}

0 commit comments

Comments
 (0)