Skip to content

Commit

Permalink
[Chore] Timestamps (#11)
Browse files Browse the repository at this point in the history
* Include created and updated at timestamps to polls

* Encode spaces in query string
  • Loading branch information
florenceshelley authored and gerry-wu committed Sep 19, 2019
1 parent afffa97 commit a425838
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/routes/polls/polls.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ const getPollsController = async (req, res, next) => {
data: snapshot.docs.map(doc => {
return {
id: doc.id,
...doc.data()
...doc.data(),
created_at: doc._createTime._seconds,
updated_at: doc._updateTime._seconds
}
})
})
Expand Down
19 changes: 14 additions & 5 deletions src/utils/parametize.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// Takes in an object of parameters to include in a request,
// and converts them to a string of params
// This allows us to define our parameters in a more readable way
// from wherever we are including them in a request
/**
* Takes in an object of parameters to include in a request,
* and converts them to query string params
* This allows us to define our parameters in a more readable way
* from wherever we are including them in a request
* Furthermore, if there is a space in the given value,
* this value will be safely encoded
*/

const parametize = params =>
Object.entries(params).reduce((string, [param, value]) => {
const toInterpolate = `${param}=${value}`
const encodedValue = value
.toString()
.split(' ')
.join('%20')
const toInterpolate = `${param}=${encodedValue}`
const prefix = !string ? '' : '&'
return (string += prefix + toInterpolate)
}, '')
Expand Down

0 comments on commit a425838

Please sign in to comment.