Skip to content

Commit

Permalink
added id and sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
pc committed Oct 2, 2019
1 parent 14ef314 commit 22ebd6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion database/candidateQueryBuilder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const dbHandler = require('./dbHandler')
const sanitizeData = require('../utils/utilities').sanitizeData
const uuid = require('uuid/v4')
const moment = require('moment')

/**
*
Expand Down Expand Up @@ -52,7 +54,10 @@ const getCandidate = async (attrs) => {
* @param {*} attrs {candidateData}
*/
const registerUser = async (attrs) => {
const {name, instituteId, branch, experience} = attrs
if(!attrs.id){
attrs.id = uuid()
}
attrs.lastModifiedOn = moment().valueOf()
const resp = await dbHandler.docClient.put({
"TableName": process.env.CANDIDATE_TABLE,
"Item": attrs,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
},
"dependencies": {
"moment": "^2.24.0",
"moment-timezone": "^0.5.26"
"moment-timezone": "^0.5.26",
"sanitize": "^2.1.0",
"uuid": "^3.3.3"
}
}
7 changes: 6 additions & 1 deletion utils/utilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const constants = require('./constants')
const sanitizer = require('sanitize')()

const respondBack = (attrs) => {
const {error, statusCode, body, headers, callback} = attrs
Expand All @@ -21,12 +22,16 @@ const sanitizeData = (data) => {
if(Arrays.isArray(data)){
//
} else {
data = data.map(v=>{
data = data.map((v, k)=>{
if(k == 'username'){
return v;
}
return sanitizeData(v)
})
}
} else if(typeof data == 'string'){
// TODO:
data = sanitizer.value(data, 'string')
}
return data
}
Expand Down

0 comments on commit 22ebd6d

Please sign in to comment.