diff --git a/.eslintrc.json b/.eslintrc.json index ef56cee..b68d1bf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ "array-bracket-newline": ["warn", "consistent"], "eol-last": ["warn", "always"], "indent": ["warn", 2], + "no-fallthrough": "warn", "no-prototype-builtins": "off", "no-trailing-spaces": ["warn", { "ignoreComments": true }], "no-unused-vars": ["warn"], diff --git a/services/interactions/handler.js b/services/interactions/handler.js index eed4b3f..be1bfeb 100644 --- a/services/interactions/handler.js +++ b/services/interactions/handler.js @@ -7,9 +7,15 @@ import db from "../../lib/db"; import docClient from "../../lib/docClient"; import handlerHelpers from "../../lib/handlerHelpers"; import helpers from "../../lib/handlerHelpers"; -import { CURRENT_EVENT } from "./constants"; -import { handleBooth, handleConnection, handleWorkshop } from "./helpers"; -import { QueryCommand } from "@aws-sdk/lib-dynamodb"; +import { + CURRENT_EVENT +} from "./constants"; +import { + handleBooth, handleConnection, handleWorkshop +} from "./helpers"; +import { + QueryCommand +} from "@aws-sdk/lib-dynamodb"; const CONNECTION = "CONNECTION"; const WORK = "WORKSHOP"; @@ -37,27 +43,29 @@ export const postInteraction = async (event, ctx, callback) => { } const timestamp = new Date().getTime(); - const { userID, eventType, eventParam } = data; + const { + userID, eventType, eventParam + } = data; let response; switch (eventType) { - case CONNECTION: - response = await handleConnection(userID, eventParam, timestamp); - break; - - case WORK: - response = await handleWorkshop(userID, eventParam, timestamp); - break; - - case BOOTH: - response = await handleBooth(userID, eventParam, timestamp); - break; - - default: - throw handlerHelpers.createResponse(400, { - message: "interactionType argument does not match known case" - }); + case CONNECTION: + response = await handleConnection(userID, eventParam, timestamp); + break; + + case WORK: + response = await handleWorkshop(userID, eventParam, timestamp); + break; + + case BOOTH: + response = await handleBooth(userID, eventParam, timestamp); + break; + + default: + throw handlerHelpers.createResponse(400, { + message: "interactionType argument does not match known case" + }); } callback(null, response); @@ -78,7 +86,9 @@ export const getAllConnections = async (event, ctx, callback) => { const userID = event.pathParameters.id; - const { data: profileData } = await db.getOne(userID, QRS_TABLE, { + const { + data: profileData + } = await db.getOne(userID, QRS_TABLE, { "eventID;year": CURRENT_EVENT }); @@ -117,7 +127,9 @@ export const getAllQuests = async (event, ctx, callback) => { const userID = event.pathParameters.id; - const { data: profileData } = await db.getOne(userID, QRS_TABLE, { + const { + data: profileData + } = await db.getOne(userID, QRS_TABLE, { "eventID;year": CURRENT_EVENT }); diff --git a/services/interactions/helpers.js b/services/interactions/helpers.js index bf2d472..6193cf3 100644 --- a/services/interactions/helpers.js +++ b/services/interactions/helpers.js @@ -1,4 +1,6 @@ -import { QueryCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb"; +import { + QueryCommand, UpdateCommand +} from "@aws-sdk/lib-dynamodb"; import { QRS_TABLE, CONNECTIONS_TABLE, @@ -48,8 +50,12 @@ export const handleConnection = async (userID, connID, timestamp) => { }); } - let { data: userData, type: userType } = profileData; - let { data: connData, type: connType } = connProfileData; + let { + data: userData, type: userType + } = profileData; + let { + data: connData, type: connType + } = connProfileData; if (await isDuplicateRequest(userData.registrationID, connID)) { return handlerHelpers.createResponse(400, { @@ -75,39 +81,46 @@ export const handleConnection = async (userID, connID, timestamp) => { createdAt: timestamp, ...(connData.linkedinURL ? { - linkedinURL: connData.linkedinURL - } - : {}), + linkedinURL: connData.linkedinURL + } + : { + }), ...(connData.fname ? { - fname: connData.fname - } - : {}), + fname: connData.fname + } + : { + }), ...(connData.lname ? { - lname: connData.lname - } - : {}), + lname: connData.lname + } + : { + }), ...(connData.major ? { - major: connData.major - } - : {}), + major: connData.major + } + : { + }), ...(connData.year ? { - year: connData.year - } - : {}), + year: connData.year + } + : { + }), ...(connData.company ? { - company: connData.company - } - : {}), + company: connData.company + } + : { + }), ...(connData.title ? { - title: connData.title - } - : {}) + title: connData.title + } + : { + }) }; const connPut = { @@ -117,66 +130,73 @@ export const handleConnection = async (userID, connID, timestamp) => { createdAt: timestamp, ...(userData.linkedinURL ? { - linkedinURL: userData.linkedinURL - } - : {}), + linkedinURL: userData.linkedinURL + } + : { + }), ...(userData.fname ? { - fname: userData.fname - } - : {}), + fname: userData.fname + } + : { + }), ...(userData.lname ? { - lname: userData.lname - } - : {}), + lname: userData.lname + } + : { + }), ...(userData.major ? { - major: userData.major - } - : {}), + major: userData.major + } + : { + }), ...(userData.year ? { - year: userData.year - } - : {}), + year: userData.year + } + : { + }), ...(userData.company ? { - company: userData.company - } - : {}), + company: userData.company + } + : { + }), ...(userData.title ? { - title: userData.title - } - : {}) + title: userData.title + } + : { + }) }; const promises = []; switch (connType) { - case EXEC + EXEC: - promises.push( - incrementQuestProgress(connData.registrationID, QUEST_CONNECT_EXEC_H) - ); + case EXEC + EXEC: + promises.push( + incrementQuestProgress(connData.registrationID, QUEST_CONNECT_EXEC_H) + ); - case EXEC: - promises.push( - incrementQuestProgress(userData.registrationID, QUEST_CONNECT_EXEC_H) - ); + case EXEC: + promises.push( + incrementQuestProgress(userData.registrationID, QUEST_CONNECT_EXEC_H) + ); // case ATTENDEE: - default: - promises.push( - db.put(connPut, CONNECTIONS_TABLE, true), - db.put(userPut, CONNECTIONS_TABLE, true), - incrementQuestProgress(userData.registrationID, QUEST_CONNECT_ONE), - incrementQuestProgress(userData.registrationID, QUEST_CONNECT_FOUR), - incrementQuestProgress(userData.registrationID, QUEST_CONNECT_TEN_H), - incrementQuestProgress(connData.registrationID, QUEST_CONNECT_ONE), - incrementQuestProgress(connData.registrationID, QUEST_CONNECT_FOUR), - incrementQuestProgress(connData.registrationID, QUEST_CONNECT_TEN_H) - ); - break; + default: + promises.push( + db.put(connPut, CONNECTIONS_TABLE, true), + db.put(userPut, CONNECTIONS_TABLE, true), + incrementQuestProgress(userData.registrationID, QUEST_CONNECT_ONE), + incrementQuestProgress(userData.registrationID, QUEST_CONNECT_FOUR), + incrementQuestProgress(userData.registrationID, QUEST_CONNECT_TEN_H), + incrementQuestProgress(connData.registrationID, QUEST_CONNECT_ONE), + incrementQuestProgress(connData.registrationID, QUEST_CONNECT_FOUR), + incrementQuestProgress(connData.registrationID, QUEST_CONNECT_TEN_H) + ); + break; } try { @@ -216,7 +236,9 @@ const isDuplicateRequest = async (userID, connID) => { }; export const handleWorkshop = async (profileID, workshopID, timestamp) => { - const { data } = await db.getOne(profileID, QRS_TABLE, { + const { + data + } = await db.getOne(profileID, QRS_TABLE, { "eventID;year": CURRENT_EVENT }); @@ -240,7 +262,9 @@ export const handleWorkshop = async (profileID, workshopID, timestamp) => { }; export const handleBooth = async (profileID, boothID, timestamp) => { - const { data } = await db.getOne(profileID, QRS_TABLE, { + const { + data + } = await db.getOne(profileID, QRS_TABLE, { "eventID;year": CURRENT_EVENT });