sn-utilities v1.0.138
Utilities
function getParams(req, func)
Parameters:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
req | JSON | HTTP request object containing HTTP parameters
func | function | JavaScript function (example below)Example of func parameter:
function getParams(source, target) {
if (source) {
if (source.id && !target.id) {
target.id = source.id;
}
if (source.name && !target.name) {
target.name = source.name;
}
}
return target;
}function handleError(error, res)
Parameters:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
error | JSON | JSON error object (format below)
res | JSON | HTTP response objectFormat of JSON error parameter:
{
"error": [{}],
"status": [123]
}Above JSON explained:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
error | JSON | The JSON object of the error thrown
status | INT | (Optional) HTTP status code to be used if the status in error is not specifiedExample of above JSON error:
{
"error": {
"errors": [
{
"error": "invalid input syntax for uuid: \"3334c105-f842-98e7-603a\""
}
],
"name": "error",
"length": 118,
"severity": "ERROR",
"code": "22P02",
"detail": "undefined",
"hint": "undefined",
"position": "undefined",
"internalPosition": "undefined",
"internalQuery": "undefined",
"where": "undefined",
"schema": "undefined",
"table": "undefined",
"column": "undefined",
"dataType": "undefined",
"constraint": "undefined",
"file": "uuid.c",
"line": "129",
"routine": "string_to_uuid"
}
}function handleSuccess(success, res)
Parameters:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
success | JSON | JSON success object (format below)
res | JSON | HTTP response objectFormat of JSON success parameter:
{
"success": {
"status": [123],
"message": ["abc"],
"data": {}
},
"status": [123]
}Above JSON explained:
Parameter | Type | Description
--------------------+-------------+-----------------------------------------------------------------------------------
success->status | INT | (Optional) HTTP status code
success->message | TEXT | Description of status
success->data | JSON | (Optional) Metadata
status | INT | (Optional) HTTP status code to be used if the status in success is not specifiedfunction handleContentTypeJSON(param, res)
Parameters:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
param | JSON | JSON param object (format below)
res | JSON | HTTP response objectFormat of JSON param parameter:
{
"contentType": ["abc"]
}Above JSON explained:
Parameter | Type | Description
---------------------+-------------+-------------------------------------------------
contentType | TEXT | The content type of the request to be validatedfunction createUUID(data)
Parameters:
Parameter | Type | Description
--------------------+-------------+------------------------------------------
data | ANYTHING | (Optional)function getLocalTimestampString()
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago