Last active
August 9, 2021 10:47
-
-
Save suvel-the-dev/9929b61c22c5295940c03f8ea5b9efd0 to your computer and use it in GitHub Desktop.
subroute decalration snippt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @subroute<number> | |
* <param_type> param | |
* @param {<type>} <name> | |
*/ | |
router.<method>("<subroute>", async function (req, res, next) { | |
const <param_variable> = req.<param_type>; | |
const action = <paramVariable>.action; | |
const userId = <paramVariable>.userId; | |
let result = undefined; | |
let isInError = 0; | |
let isErrorMsg = ""; | |
let isErrorCode = ""; | |
function validateParams() { | |
if (!action) { | |
isInError = 1; | |
isErrorCode = "INVALID_ACTION"; | |
} | |
else if (!userId) { | |
isInError = 1; | |
isErrorCode = "INVALID_USERID"; | |
} | |
} | |
validateParams(); | |
if (isInError == 0) { | |
const arguments = { | |
action, | |
userId, | |
} | |
<sqlFunctionName>(arguments) | |
.then(function (results) { | |
result = results[0]; | |
}) | |
.catch(function (err) { | |
console.log("ERROR @ <method> of <route><subroute>", err); | |
isErrorCode = "FILTER_ERROR"; | |
if (err.sqlState == 41001) { | |
isErrorMsg = "Make sure to provide your login."; | |
} else { | |
isErrorMsg = | |
err.sqlState + | |
`: We had difficulty performaing this action. Pleae report his number to your contact.`; | |
} | |
}) | |
.finally(function () { | |
const header = getHeaderNode(isErrorCode, isErrorMsg); | |
res.send({ | |
header, | |
results: result, | |
}); | |
}) | |
} | |
else { | |
// end isError | |
console.log("ERROR @ <method> of <route><subroute>"); | |
const header = getHeaderNode(isErrorCode, isErrorMsg); | |
res.send({ | |
header, | |
results: result, | |
}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment