Skip to content

Commit

Permalink
refactor: enable and fix promise/no-nesting (#2000)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah authored Mar 15, 2021
1 parent c2fd98c commit a78793a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = {
'node/no-sync': 0,
'promise/catch-or-return': 0,
'promise/no-callback-in-promise': 0,
'promise/no-nesting': 0,
'promise/no-return-wrap': 0,
'promise/prefer-await-to-callbacks': 0,
'promise/prefer-await-to-then': 0,
Expand Down
38 changes: 19 additions & 19 deletions src/functions-templates/js/fauna-crud/read-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ const client = new Client({

const handler = async () => {
console.log('Function `read-all` invoked')
return client
.query(query.Paginate(query.Match(query.Index('all_items'))))
.then((response) => {
const itemRefs = response.data
// create new query out of item refs. http://bit.ly/2LG3MLg
const getAllItemsDataQuery = itemRefs.map((ref) => query.Get(ref))
// then query the refs
return client.query(getAllItemsDataQuery).then((ret) => ({
statusCode: 200,
body: JSON.stringify(ret),
}))
})
.catch((error) => {
console.log('error', error)
return {
statusCode: 400,
body: JSON.stringify(error),
}
})

try {
const response = await client.query(query.Paginate(query.Match(query.Index('all_items'))))
const itemRefs = response.data
// create new query out of item refs. http://bit.ly/2LG3MLg
const getAllItemsDataQuery = itemRefs.map((ref) => query.Get(ref))
// then query the refs
const ret = await client.query(getAllItemsDataQuery)
return {
statusCode: 200,
body: JSON.stringify(ret),
}
} catch (error) {
console.log('error', error)
return {
statusCode: 400,
body: JSON.stringify(error),
}
}
}

module.exports = { handler }
26 changes: 12 additions & 14 deletions src/functions-templates/js/slack-rate-limit/slack-rate-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@ class IdentityAPI {
})
}

request(path, options = {}) {
async request(path, options = {}) {
const headers = this.headers(options.headers || {})
return fetch(this.apiURL + path, { ...options, headers }).then((response) => {
const contentType = response.headers.get('Content-Type')
if (contentType && /json/.test(contentType)) {
return this.parseJsonResponse(response)
}
const response = await fetch(this.apiURL + path, { ...options, headers })
const contentType = response.headers.get('Content-Type')
if (contentType && /json/.test(contentType)) {
return this.parseJsonResponse(response)
}

if (!response.ok) {
return response.text().then((data) => {
const error = `Data: ${data}. Status: ${response.status}`
return Promise.reject(new Error(error))
})
}
return response.text()
})
if (!response.ok) {
const data = await response.text()
const error = `Data: ${data}. Status: ${response.status}`
return Promise.reject(new Error(error))
}
return await response.text()
}
}

Expand Down

0 comments on commit a78793a

Please sign in to comment.