Skip to content

Commit

Permalink
feat: separate lambda functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Méndez committed Oct 21, 2019
1 parent b8e5cbd commit 9b01ff5
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 391 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Se aprecia el aporte al backend de:
- [Franco Méndez Z.](https://github.com/fnmendez)
- [Matías Andrade](https://github.com/mandrade2)
- [José Morales Lira](https://github.com/josemlira)
- [Bruno Calderon](https://github.com/brunocalderon)
- [Domingo Ramírez](https://github.com/chuma9615)
- [Maurice Poirrier](https://github.com/mauricepoirrier)
- [Felipe Navarro](https://github.com/fcnavarro)
Expand Down
36 changes: 13 additions & 23 deletions done/SalgodeUserCreate.js → SalgodeUserCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var AWS = require('aws-sdk');
var dynamoDb = new AWS.DynamoDB.DocumentClient();
const aws = require('aws-sdk');
const dynamoDb = new aws.DynamoDB.DocumentClient();
const uuidv4 = require('uuid/v4');
const moment = require('moment');

module.exports.handler = function(event, context, callback) {
if (
Expand All @@ -13,13 +15,13 @@ module.exports.handler = function(event, context, callback) {
}

console.log('enters create');
var timestamp = new Date().getTime();
let timestamp = moment().format('YYYY-MM-DDTHH:mm:ss-04:00');

var params = {
let params = {
TableName: event.TableName,
Item: {
id: uuid(),
token: uuid(),
id: 'usr_' + uuidv4(),
token: uuidv4(),
...event.payload.Item,
createdAt: timestamp,
updatedAt: timestamp
Expand All @@ -46,39 +48,27 @@ module.exports.handler = function(event, context, callback) {

delete params.Item.password;

var response = {
let response = {
statusCode: 200,
body: params.Item
};
return callback(null, response);
});
};

function uuid() {
var dt = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(
c
) {
var r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
return uuid;
}

var BadRequest = {
let BadRequest = {
statusCode: 400,
message: 'Tu solicitud tiene errores'
};
var ValidationErrorEmailAlreadyInUse = {
let ValidationErrorEmailAlreadyInUse = {
statusCode: 400,
message: 'El email ya está en uso'
};
var ValidationErrorPasswordMismatch = {
let ValidationErrorPasswordMismatch = {
statusCode: 400,
message: 'Las contraseñas no coinciden'
};
var InternalServerError = {
let InternalServerError = {
statusCode: 503,
message: 'Algo inesperado acaba de pasar... gracias por intentar más tarde'
};
File renamed without changes.
50 changes: 41 additions & 9 deletions resources/user/update.js → SalgodeUserUpdate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
var AWS = require('aws-sdk');
var dynamoDb = new AWS.DynamoDB.DocumentClient();

var {
Unauthorized,
ValidationErrorPasswordMismatch,
NotFound,
InternalServerError
} = require('../../constants/errorResponses');
var { filterEmptyKeys, isEmpty, removePassword, uuid } = require('../../utils');

module.exports = function(event, callback) {
module.exports.handler = function(event, context, callback) {
console.log('enters update');
var timestamp = new Date().getTime();

Expand Down Expand Up @@ -78,3 +70,43 @@ module.exports = function(event, callback) {
});
});
};

function removePassword(obj) {
var retObj = {};
Object.keys(obj).forEach(key => {
if (key !== 'password' && key !== 'passwordRepeat') {
retObj[key] = obj[key];
}
});
return retObj;
}

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

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

var ValidationErrorPasswordMismatch = {
statusCode: 400,
message: 'Las contraseñas no coinciden'
};
var Unauthorized = {
statusCode: 401,
message: 'No estás autorizado para esto'
};
var NotFound = {
statusCode: 404,
message: 'No se ha encontrado lo que buscas'
};
var InternalServerError = {
statusCode: 503,
message: 'Algo inesperado acaba de pasar... gracias por intentar más tarde'
};
30 changes: 0 additions & 30 deletions constants/errorResponses.js

This file was deleted.

25 changes: 0 additions & 25 deletions index.js

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"predeploy": "rm SalgodeCore.zip && zip -r SalgodeCore.zip index.js resources utils constants",
"deploy": "aws lambda update-function-code --function-name SalgodeCore --zip-file fileb://SalgodeCore.zip --region us-east-1"
"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
4 changes: 0 additions & 4 deletions resources/index.js

This file was deleted.

37 changes: 0 additions & 37 deletions resources/trip/create.js

This file was deleted.

26 changes: 0 additions & 26 deletions resources/trip/destroy.js

This file was deleted.

20 changes: 0 additions & 20 deletions resources/trip/index.js

This file was deleted.

Empty file removed resources/trip/list.js
Empty file.
39 changes: 0 additions & 39 deletions resources/trip/read.js

This file was deleted.

Empty file removed resources/trip/update.js
Empty file.
52 changes: 0 additions & 52 deletions resources/user/create.js

This file was deleted.

Loading

0 comments on commit 9b01ff5

Please sign in to comment.