diff --git a/README.md b/README.md index 1c5eefe..4cd9299 100644 --- a/README.md +++ b/README.md @@ -260,27 +260,19 @@ npm start
-### 2.1.1) Subir un objeto al bucket -#### Request +### 2.1.1) Subir un objeto al bucket s3 +#### Request | Code snippet ``` postman -- Método : POST - -- Url : {{base_url}}/dev/upload-object - -- Headers: - - Content-Type : application/json - - Authorization : {{bearer_token}} - - x-api-key : {{x-api-key}} - -- Body : - - { - "type":"image", - "format":"JPG", - "description":"1000 × 1261 png", - "url":"https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi&mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0" - } - +curl --location 'http://localhost:4000/dev/upload-object' \ +--header 'x-api-key: f98d8cd98h73s204e3456998ecl9427j' \ +--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' \ +--header 'Content-Type: application/json' \ +--data '{ + "type":"image", + "format":"png", + "description":"5000 × 3061 png", + "url":"https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi&mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0" +}' ``` #### Response @@ -288,10 +280,10 @@ npm start { "message": { "type": "image", - "format": "JPG", - "description": "1000 × 1261 png", + "format": "png", + "description": "5000 × 3061 png", "url": "https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi&mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0", - "uuid": 103053674 + "uuid": 104851112 } } ``` @@ -300,22 +292,14 @@ npm start
-### 2.1.2) Obtener un objeto del bucket -#### Request +### 2.1.2) Obtener un objeto del bucket según su uuuid +#### Request | Code snippet ``` postman -- Método : GET - -- Url : {{base_url}}/dev/get-object/{uuid} - -- Headers: - - Content-Type : application/json - - Authorization : {{bearer_token}} - - x-api-key : {{x-api-key}} - -- Body : - - NULL - +curl --location 'http://localhost:4000/dev/get-object/103053674' \ +--header 'x-api-key: f98d8cd98h73s204e3456998ecl9427j' \ +--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' \ +--header 'Content-Type: application/json' \ +--data '' ``` #### Response @@ -335,25 +319,19 @@ npm start
-### 2.1.3) Actualizar un objeto del bucket -#### Request +### 2.1.3) Actualizar un objeto del bucket s3 +#### Request | Code snippet ``` postman -- Método : PUT - -- Url : {{base_url}}/dev/edit-object/{uuid} - -- Headers: - - Content-Type : application/json - - Authorization : {{bearer_token}} - - x-api-key : {{x-api-key}} - -- Body : - { +curl --location --request PUT 'http://localhost:4000/dev/edit-object/104851112' \ +--header 'x-api-key: f98d8cd98h73s204e3456998ecl9427j' \ +--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' \ +--header 'Content-Type: application/json' \ +--data '{ "type":"image", - "format":"png", - "description":"EDITED", + "format":"jpg", + "description":"1200 × 1201 png", "url":"https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi& mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0" - } +}' ``` @@ -362,10 +340,10 @@ npm start { "message": { "type": "image", - "format": "JPG", - "description": "1000 × 1261 png", - "url": "https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi&mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0", - "uuid": 103053674 + "format": "jpg", + "description": "1200 × 1201 png", + "url": "https://www.bing.com/images/search?view=detailV2&ccid=Tf4BFI68&id=D66EF5BFB7DA0A645A70240C32CB8664E8F8BF09&thid=OIP.Tf4BFI6846neirVSebC0vAHaEi& mediaurl=https%3a%2f%2flogos-download.com%2fwp-content%2fuploads%2f2016%2f09%2fNode_logo_NodeJS.png&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4dfe01148ebce3a9de8ab55279b0b4bc%3frik%3dCb%252f46GSGyzIMJA%26pid%3dImgRaw%26r%3d0&exph=3061&expw=5000&q=jpg+nodejs&simid=608055434302923247&FORM=IRPRST&ck=2FF3D39CAEF945F20B996CF6042F88A6&selectedIndex=1&ajaxhist=0&ajaxserp=0", + "uuid": 104851112 } } ``` @@ -375,27 +353,18 @@ npm start
### 2.1.4) Eliminar un objeto del bucket -#### Request +#### Request | Code snippet ``` postman -- Método : DELETE - -- Url : {{base_url}}/dev/delete-object/{uuid} - -- Headers: - - Content-Type : application/json - - Authorization : {{bearer_token}} - - x-api-key : {{x-api-key}} - -- Body : - - NULL - +curl --location --request DELETE 'http://localhost:4000/dev/delete-object/104851112' \ +--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' \ +--header 'x-api-key: f98d8cd98h73s204e3456998ecl9427j' \ +--header 'Content-Type: application/json' ``` #### Response ``` postman { - "message": "Removed object with uuid 103053674 successfully." + "message": "Removed object with uuid 104851112 successfully." } ``` diff --git a/src/controllers/deleteObject.js b/src/controllers/deleteObject.js index 5b2c1c9..dacc73b 100644 --- a/src/controllers/deleteObject.js +++ b/src/controllers/deleteObject.js @@ -1,4 +1,4 @@ - +"use strict"; //Enums const { statusCode @@ -34,32 +34,34 @@ const { //Const/Vars - let eventBody; let eventHeaders; - let jsonInit; let validateReqParams; let validateAuth; - let validateBodyAddObject; let obj; + let indexObj; + let uuidInput; let bucketContent; let bucketContentResult; + let msg; + let code; /** - * @description Function to edit an object according to its uuid from the s3 repository + * @description Function to delete an object according to its uuid from the s3 repository * @param {Object} event Object type * @returns a body response with http code and message */ module.exports.handler = async (event) => { try { //Init - jsonInit = []; - bodyObj = null; obj = null; bucketContent = null; + uuidInput = null; + indexObj = null; bucketContentResult = null; + msg = null; + code = null; - //-- start with validation Headers --- eventHeaders = await event.headers; @@ -88,7 +90,7 @@ const { await initBucketIfEmpty(); - let uuidInput = parseInt(await event.pathParameters.uuid); + uuidInput = parseInt(await event.pathParameters.uuid); bucketContent = await readBucket(); @@ -102,7 +104,7 @@ const { bucketContent = await formatToJson(bucketContent); - let indexObj = await bucketContent.indexOf(obj); + indexObj = await bucketContent.indexOf(obj); //Remove the object with the entered uuid await bucketContent.splice(indexObj, 1); @@ -130,11 +132,11 @@ const { } catch (error) { - console.log(error); - return await bodyResponse( - statusCode.INTERNAL_SERVER_ERROR, - "An unexpected error has occurred. Try again" - ); + code = statusCode.INTERNAL_SERVER_ERROR; + msg = `Error in DELETE OBJECT lambda. Caused by ${error}. Stack error type : ${error.stack}`; + console.error(msg); + + return await requestResult(code, msg); } } \ No newline at end of file diff --git a/src/controllers/editObject.js b/src/controllers/editObject.js index 37db2f0..2e95f6e 100644 --- a/src/controllers/editObject.js +++ b/src/controllers/editObject.js @@ -1,3 +1,4 @@ +"use strict"; //Enums const { statusCode @@ -38,13 +39,17 @@ const { //Const/Vars let eventBody; let eventHeaders; -let jsonInit; let bucketContent; let validateReqParams; let validateAuth; let validateBodyAddObject; let obj; +let uuidInput; let newObject; +let indexObj; +let newObjectResult; +let msg; +let code; /** * @description edit an object in s3 bucket based on its uuid @@ -54,10 +59,13 @@ let newObject; module.exports.handler = async (event) => { try { //Init - jsonInit = []; - bodyObj = null; bucketContent = null; + uuidInput = null; + indexObj = null; + newObjectResult = null; obj = null; + msg = null; + code = null; //-- start with validation Headers --- @@ -102,7 +110,7 @@ module.exports.handler = async (event) => { await initBucketIfEmpty(); - let uuidInput = parseInt(await event.pathParameters.uuid); + uuidInput = parseInt(await event.pathParameters.uuid); bucketContent = await readBucket(); @@ -118,7 +126,7 @@ module.exports.handler = async (event) => { bucketContent = await formatToJson(bucketContent); - let indexObj = await bucketContent.indexOf(obj); + indexObj = await bucketContent.indexOf(obj); //Remove the object with the entered uuid await bucketContent.splice(indexObj, 1); @@ -132,7 +140,7 @@ module.exports.handler = async (event) => { //convert json to string format to save if is not a string format newObject = await formatToString(bucketContent); - let newObjectResult = await appendBucket(newObject); + newObjectResult = await appendBucket(newObject); //-- end with bucket operations --- @@ -153,11 +161,11 @@ module.exports.handler = async (event) => { } catch (error) { - console.log(error); - return await bodyResponse( - statusCode.INTERNAL_SERVER_ERROR, - "An unexpected error has occurred. Try again" - ); + code = statusCode.INTERNAL_SERVER_ERROR; + msg = `Error in EDIT OBJECT lambda. Caused by ${error}. Stack error type : ${error.stack}`; + console.error(msg); + + return await requestResult(code, msg); } } \ No newline at end of file diff --git a/src/controllers/getObject.js b/src/controllers/getObject.js index b2bfbf3..d396844 100644 --- a/src/controllers/getObject.js +++ b/src/controllers/getObject.js @@ -1,3 +1,4 @@ +"use strict"; //Enums const { statusCode @@ -19,13 +20,14 @@ const { findByUuid } = require("../helpers/bucket/operations/findByUuid"); //Const/Vars -let eventBody; let eventHeaders; -let jsonInit; let bucketContent; let validateReqParams; let validateAuth; +let uuidInput; let obj; +let msg; +let code; /** @@ -37,10 +39,11 @@ let obj; module.exports.handler = async (event) => { try { //Init - jsonInit = []; - bodyObj = null; bucketContent = null; + uuidInput = null; obj = null; + msg = null; + code = null; //-- start with validation Headers --- @@ -68,7 +71,7 @@ module.exports.handler = async (event) => { //-- start with bucket operations --- - let uuidInput = parseInt( await event.pathParameters.uuid); + uuidInput = parseInt( await event.pathParameters.uuid); bucketContent = await readBucket(); @@ -94,11 +97,11 @@ module.exports.handler = async (event) => { //-- end with bucket operations --- } catch (error) { - console.log(error); - return await bodyResponse( - statusCode.INTERNAL_SERVER_ERROR, - "An unexpected error has occurred. Try again" - ); + code = statusCode.INTERNAL_SERVER_ERROR; + msg = `Error in GET OBJECT lambda. Caused by ${error}. Stack error type : ${error.stack}`; + console.error(msg); + + return await bodyResponse(code, msg); } } \ No newline at end of file diff --git a/src/controllers/uploadObject.js b/src/controllers/uploadObject.js index 4771a65..11daadf 100644 --- a/src/controllers/uploadObject.js +++ b/src/controllers/uploadObject.js @@ -1,3 +1,4 @@ +"use strict"; //Enums const { statusCode @@ -37,12 +38,14 @@ const { //Const/Vars let eventBody; let eventHeaders; -let jsonInit; let bucketContent; let validateReqParams; let validateAuth; let validateBodyAddObject; let newObject; +let newObjectResult; +let msg; +let code; /** * @description add an object inside the s3 bucket @@ -52,10 +55,11 @@ let newObject; module.exports.handler = async (event) => { try { //Init - jsonInit = []; - bodyObj = null; bucketContent = null; newObject = null; + newObjectResult = null; + msg = null; + code = null; //-- start with validation Headers --- @@ -117,7 +121,7 @@ module.exports.handler = async (event) => { newObject = await formatToString(bucketContent); - let newObjectResult = await appendBucket(newObject); + newObjectResult = await appendBucket(newObject); if (newObjectResult != null) { return await bodyResponse( @@ -134,11 +138,11 @@ module.exports.handler = async (event) => { //-- end with bucket operations --- } catch (error) { - console.log(error); - return await bodyResponse( - statusCode.INTERNAL_SERVER_ERROR, - "An unexpected error has occurred. Try again" - ); + code = statusCode.INTERNAL_SERVER_ERROR; + msg = `Error in UPLOAD OBJECT lambda. Caused by ${error}. Stack error type : ${error.stack}`; + console.error(msg); + + return await bodyResponse(code, msg); } } \ No newline at end of file diff --git a/src/helpers/auth/headers.js b/src/helpers/auth/headers.js index 130ad8e..cb23590 100644 --- a/src/helpers/auth/headers.js +++ b/src/helpers/auth/headers.js @@ -1,3 +1,4 @@ +"use strict"; //Environment vars const X_API_KEY = process.env.X_API_KEY; const BEARER_TOKEN = process.env.BEARER_TOKEN; @@ -12,20 +13,23 @@ let validate; * @returns a boolean */ const validateAuthHeaders = async (eventHeaders) => { + try { + xApiKey = await eventHeaders["x-api-key"]; + authorization = await eventHeaders["Authorization"]; - xApiKey = await eventHeaders["x-api-key"]; - authorization = await eventHeaders["Authorization"]; - - validate = true; - - if (xApiKey != X_API_KEY - || authorization != BEARER_TOKEN - || authorization == null) { + validate = + xApiKey != X_API_KEY || + authorization != BEARER_TOKEN || + authorization == null + ? false + : true; + } catch (error) { validate = false; + console.error( + `Error in validateAuthHeaders() function. Caused by ${error}. Specific stack is ${error.stack}` + ); } return validate; -} - -module.exports = { validateAuthHeaders } - +}; +module.exports = { validateAuthHeaders }; \ No newline at end of file diff --git a/src/helpers/bucket/config/clientS3.js b/src/helpers/bucket/config/clientS3.js index e34aee9..cb7bec5 100644 --- a/src/helpers/bucket/config/clientS3.js +++ b/src/helpers/bucket/config/clientS3.js @@ -1,11 +1,9 @@ "use strict"; - //External const { S3Client } = require("@aws-sdk/client-s3"); - /** * @description define the credentials and endpoint for a new s3 client * @param {Object} event Object type @@ -23,7 +21,9 @@ const newClientS3 = async () => { return client; } catch (error) { - console.log(error); + console.error( + `Error in newClientS3() function. Caused by ${error}. Specific stack is ${error.stack}` + ); } } diff --git a/src/helpers/bucket/operations/findByUuid.js b/src/helpers/bucket/operations/findByUuid.js index 9daf1c0..bcbb9d7 100644 --- a/src/helpers/bucket/operations/findByUuid.js +++ b/src/helpers/bucket/operations/findByUuid.js @@ -17,14 +17,15 @@ let checkObjUuid; * @returns a json object */ const findByUuid = async (bucketContent, uuidInput) => { - obj = null; - objUuid = null; - checkObjUuid = false; try { + obj = null; + objUuid = null; + checkObjUuid = false; + while (bucketContent != null || bucketContent != undefined) { bucketContent = await formatToJson(bucketContent); - for (i of bucketContent) { + for (let i of bucketContent) { objUuid = i.uuid; checkObjUuid = (objUuid == uuidInput) ? true : false; diff --git a/src/helpers/format/formatToJson.js b/src/helpers/format/formatToJson.js index 85efea5..ed38e38 100644 --- a/src/helpers/format/formatToJson.js +++ b/src/helpers/format/formatToJson.js @@ -1,4 +1,4 @@ - +"use strict"; /** * @description Convert to json format * @param {Object} obj Object type @@ -6,14 +6,14 @@ */ const formatToJson = async (obj) => { try { - if (typeof obj != 'object') { - //Convert to json to save - obj = await JSON.parse(obj); - } - } catch (error) { - console.log(error); - } - return obj; + obj = (typeof obj != "object") ? await JSON.parse(obj) : obj; + + return obj; + } catch (error) { + console.error( + `Error in formatToJson(), caused by ${error}. Specific stack is ${error.stack}` + ); + } } module.exports = { diff --git a/src/helpers/format/formatToString.js b/src/helpers/format/formatToString.js index 32202ea..99244dd 100644 --- a/src/helpers/format/formatToString.js +++ b/src/helpers/format/formatToString.js @@ -1,4 +1,4 @@ - +"use strict"; /** * @description Convert to string format * @param {Object} obj Object type @@ -6,13 +6,14 @@ */ const formatToString = async (obj) => { try { - if (typeof obj != 'string') { - obj = JSON.stringify(obj, null, 2); - } - } catch (error) { - console.log(error); - } - return obj; + obj = typeof obj != "string" ? JSON.stringify(obj, null, 2) : obj; + + return obj; + } catch (error) { + console.error( + `Error in formatToString(), caused by ${error}. Specific stack is ${error.stack}` + ); + } } module.exports = { diff --git a/src/helpers/http/bodyResponse.js b/src/helpers/http/bodyResponse.js index 9d156d3..87ef9c5 100644 --- a/src/helpers/http/bodyResponse.js +++ b/src/helpers/http/bodyResponse.js @@ -1,3 +1,4 @@ +"use strict"; /** * @description get a json with the http status code, a message and input * @param {Number} statusCode Number type @@ -6,17 +7,22 @@ * @returns a json for the lambda response */ const bodyResponse = async (statusCode,message, input) => { - return { - statusCode: statusCode, - body: JSON.stringify( + try { + return { + statusCode: statusCode, + body: JSON.stringify( { - message: message, - input: input, + message: message, }, null, 2 - ), - }; + ), + }; + } catch (error) { + console.error( + `Error in bodyResponse() function. Caused by ${error}. Specific stack is ${error.stack}` + ); + } } module.exports = { bodyResponse } \ No newline at end of file diff --git a/src/helpers/math/generateUuid.js b/src/helpers/math/generateUuid.js index ce45125..0e24dae 100644 --- a/src/helpers/math/generateUuid.js +++ b/src/helpers/math/generateUuid.js @@ -1,3 +1,4 @@ +"use strict"; //Const/vars let newUUID; @@ -7,11 +8,12 @@ let newUUID; * @example 109401114 */ const generateUUID = async () => { - newUUID = null; try { + newUUID = null; + newUUID = parseInt(Math.random() * 10000000 + 100000000); } catch (error) { - console.log(error); + console.error(`ERROR in function generateUUID(). Caused by ${error} . Specific stack is ${error.stack} `); } return newUUID; } diff --git a/src/helpers/validator/http/requestBodyAddObjectParams.js b/src/helpers/validator/http/requestBodyAddObjectParams.js index 613d187..6dfb764 100644 --- a/src/helpers/validator/http/requestBodyAddObjectParams.js +++ b/src/helpers/validator/http/requestBodyAddObjectParams.js @@ -1,4 +1,5 @@ -//External Imports +"use strict"; +//External const { Validator } = require("node-input-validator"); //Const/vars let validateCheck; @@ -11,21 +12,20 @@ let eventBodyObj; * @returns a boolean */ const validateBodyAddObjectParams = async (eventBody) => { - eventBodyObj = null; - validatorObj= null; - validateCheck = false; - - try{ - if(eventBody!=null){ + try { + eventBodyObj = null; + validatorObj = null; + validateCheck = false; - eventBodyObj ={ - data:{ + if (eventBody != null) { + eventBodyObj = { + data: { type: await eventBody["type"], format: await eventBody["format"], description: await eventBody["description"], url: await eventBody["url"], - } - } + }, + }; validatorObj = new Validator( { @@ -33,22 +33,23 @@ const validateBodyAddObjectParams = async (eventBody) => { }, { "eventBodyObj.data.type": "required|string|minLength:3|maxLength:50", - "eventBodyObj.data.format": "required|string|minLength:2|maxLength:50", + "eventBodyObj.data.format": + "required|string|minLength:2|maxLength:50", "eventBodyObj.data.description": "string|minLength:3|maxLength:100", "eventBodyObj.data.url": "string|minLength:3|maxLength:2000", } ); validateCheck = await validatorObj.check(); - } - } catch (error) { - console.log(error); + console.error( + `ERROR in function validateBodyAddObjectParams(). Caused by ${error} . Specific stack is ${error.stack} ` + ); } return validateCheck; -} +}; module.exports = { - validateBodyAddObjectParams -} \ No newline at end of file + validateBodyAddObjectParams, +}; diff --git a/src/helpers/validator/http/requestBodyUpdateObjectParams.js b/src/helpers/validator/http/requestBodyUpdateObjectParams.js index bcdbd48..3cc20e2 100644 --- a/src/helpers/validator/http/requestBodyUpdateObjectParams.js +++ b/src/helpers/validator/http/requestBodyUpdateObjectParams.js @@ -1,4 +1,5 @@ -//External Imports +"use strict"; +//External const { Validator } = require("node-input-validator"); //Const/vars let validateCheck; @@ -11,21 +12,20 @@ let eventBodyObj; * @returns a boolean */ const validateBodyUpdateObjectParams = async (eventBody) => { - eventBodyObj = null; - validatorObj= null; - validateCheck = false; - - try{ - if(eventBody!=null){ + try { + eventBodyObj = null; + validatorObj = null; + validateCheck = false; - eventBodyObj ={ - data:{ + if (eventBody != null) { + eventBodyObj = { + data: { type: await eventBody["type"], format: await eventBody["format"], description: await eventBody["description"], url: await eventBody["url"], - } - } + }, + }; validatorObj = new Validator( { @@ -35,20 +35,20 @@ const validateBodyUpdateObjectParams = async (eventBody) => { "eventBodyObj.data.type": "string|minLength:3|maxLength:50", "eventBodyObj.data.format": "string|minLength:2|maxLength:50", "eventBodyObj.data.description": "string|minLength:3|maxLength:100", - "eventBodyObj.data.url": "string|minLength:3|maxLength:2000" + "eventBodyObj.data.url": "string|minLength:3|maxLength:2000", } ); validateCheck = await validatorObj.check(); - } - } catch (error) { - console.log(error); + console.error( + `ERROR in function validateBodyUpdateObjectParams(). Caused by ${error} . Specific stack is ${error.stack} ` + ); } return validateCheck; -} +}; module.exports = { - validateBodyUpdateObjectParams -} \ No newline at end of file + validateBodyUpdateObjectParams, +}; diff --git a/src/helpers/validator/http/requestHeadersParams.js b/src/helpers/validator/http/requestHeadersParams.js index f20b63f..585a934 100644 --- a/src/helpers/validator/http/requestHeadersParams.js +++ b/src/helpers/validator/http/requestHeadersParams.js @@ -1,4 +1,5 @@ -//External Imports +"use strict"; +//External const { Validator } = require("node-input-validator"); //Const/vars let validateCheck; @@ -12,21 +13,19 @@ let eventHeadersObj; * @example Content-Type, Authorization, etc */ const validateHeadersParams = async (eventHeaders) => { - eventHeadersObj = null; - validatorObj= null; - validateCheck = false; + try { + eventHeadersObj = null; + validatorObj = null; + validateCheck = false; - try{ - if(eventHeaders != null){ - - eventHeadersObj ={ - headers:{ + if (eventHeaders != null) { + eventHeadersObj = { + headers: { contentType: await eventHeaders["Content-Type"], authorization: await eventHeaders["Authorization"], xApiKey: await eventHeaders["x-api-key"], - - } - } + }, + }; validatorObj = new Validator( { @@ -34,20 +33,23 @@ const validateHeadersParams = async (eventHeaders) => { }, { "eventHeadersObj.headers.contentType": "required|string|maxLength:20", - "eventHeadersObj.headers.authorization": "required|string|minLength:100|maxLength:400", - "eventHeadersObj.headers.xApiKey": "required|string|minLength:30|maxLength:100", + "eventHeadersObj.headers.authorization": + "required|string|minLength:100|maxLength:400", + "eventHeadersObj.headers.xApiKey": + "required|string|minLength:30|maxLength:100", } ); - validateCheck = await validatorObj.check() + validateCheck = await validatorObj.check(); } - } catch (error) { - console.log(error); + console.error( + `ERROR in function validateHeadersParams(). Caused by ${error} . Specific stack is ${error.stack} ` + ); } return validateCheck; -} +}; module.exports = { - validateHeadersParams -} \ No newline at end of file + validateHeadersParams, +};