Skip to content

Commit

Permalink
feat: add optional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 21, 2019
1 parent aca2854 commit 75c3f05
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
40 changes: 40 additions & 0 deletions SalgodeUserCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@ module.exports.handler = function(event, context, callback) {
console.log('enters create');
let timestamp = moment().format('YYYY-MM-DDTHH:mm:ss-04:00');

let input = event.payload.Item;

if (
!input.email ||
!input.name ||
!input.lastName ||
!input.phone ||
!input.selfieLink ||
!input.dniFrontLink ||
!input.dniBackLink ||
!input.password ||
!input.passwordRepeat
) {
return callback(null, BadRequest);
}

if (input.car && !isEmpty(input.car)) {
if (
!input.car.plate ||
!input.car.model ||
!input.car.color ||
!input.car.brand
) {
return callback(null, BadRequest);
}
}

let params = {
TableName: event.TableName,
Item: {
Expand Down Expand Up @@ -56,6 +83,19 @@ module.exports.handler = function(event, context, callback) {
});
};

function filterEmptyKeys(obj) {
var nonEmptyKeys = Object.keys(obj).filter(k => obj[k] !== '');
var retObj = {};
nonEmptyKeys.forEach(key => {
retObj[key] = obj[key];
});
return retObj;
}

function isEmpty(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object;
}

let BadRequest = {
statusCode: 400,
message: 'Tu solicitud tiene errores'
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"main": "index.js",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"predeploy:UserCreate": "rm SalgodeUserCreate.zip && zip SalgodeUserCreate.zip SalgodeUserCreate.js",
"predeploy:UserRead": "rm SalgodeUserRead.zip && zip SalgodeUserRead.zip SalgodeUserRead.js",
"predeploy:UserUpdate": "rm SalgodeUserUpdate.zip && zip SalgodeUserUpdate.zip SalgodeUserUpdate.js",
"deploy:UserCreate": "aws lambda update-function-code --function-name SalgodeUserCreate --zip-file fileb://SalgodeUserCreate.zip --region us-east-1",
"deploy:UserRead": "aws lambda update-function-code --function-name SalgodeUserRead --zip-file fileb://SalgodeUserRead.zip --region us-east-1",
"deploy:UserUpdate": "aws lambda update-function-code --function-name SalgodeUserUpdate --zip-file fileb://SalgodeUserUpdate.zip --region us-east-1"
},
"private": true,
"devDependencies": {
Expand Down

0 comments on commit 75c3f05

Please sign in to comment.