aboutsummaryrefslogtreecommitdiffstats
path: root/apidoc/utils/send_sample_request_utils.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-06 16:48:13 -0800
committerAdam Soltys <[email protected]>2023-02-06 16:48:13 -0800
commit9c667055c6367e1b2e239686e72f52995679a47e (patch)
tree0b1d4aee51ec2d4e92d08a9d1404ba4e2ecd462a /apidoc/utils/send_sample_request_utils.js
parent15294844dbc8e73b4d1e92008a7eebc6b86b9ec5 (diff)
parent6f5602d112b68adb7452abf3047f20c32e7725b6 (diff)
downloadcoinos-server-9c667055c6367e1b2e239686e72f52995679a47e.tar.gz
coinos-server-9c667055c6367e1b2e239686e72f52995679a47e.zip
Merge branch 'master' into test
Diffstat (limited to 'apidoc/utils/send_sample_request_utils.js')
-rw-r--r--apidoc/utils/send_sample_request_utils.js97
1 files changed, 0 insertions, 97 deletions
diff --git a/apidoc/utils/send_sample_request_utils.js b/apidoc/utils/send_sample_request_utils.js
deleted file mode 100644
index fbda1ffd..00000000
--- a/apidoc/utils/send_sample_request_utils.js
+++ /dev/null
@@ -1,97 +0,0 @@
-//this block is used to make this module works with Node (CommonJS module format)
-if (typeof define !== 'function') {
- var define = require('amdefine')(module)
-}
-
-define(['lodash'], function (_) {
-
- var log = console;
-
- function handleNestedFields(object, key, params, paramType) {
- var attributes = key.split('.');
- var field = attributes[0];
- params.push(field);
- if (attributes.length > 1 && paramType[params.join('.')] == 'Object') {
- var nestedField = attributes.slice(1).join('.');
- if (!object[field])
- object[field] = {};
- if (typeof object[field] == 'object') {
- object[field][nestedField] = object[key];
- delete object[key];
- handleNestedFields(object[field], nestedField, params, paramType);
- }
- }
- }
-
- function handleNestedFieldsForAllParams(param, paramType) {
- var result = Object.assign({}, param);
- Object.keys(result).forEach(function (key) {
- handleNestedFields(result, key, [], paramType);
- });
- return result
- }
-
- function handleArraysAndObjectFields(param, paramType) {
- var result = Object.assign({}, param);
- Object.keys(paramType).forEach(function (key) {
- if (result[key] && (paramType[key].endsWith('[]') || paramType[key] === 'Object')) {
- try {
- result[key] = JSON.parse(result[key]);
- } catch (e) {;}
- }
- });
- return result
- }
-
- function tryParsingAsType(object, path, type) {
- var val = _.get(object, path);
- if (val !== undefined) {
- if (type === 'Boolean') {
- if (val === 'true') {
- _.set(object, path, true);
- } else if (val === 'false') {
- _.set(object, path, false);
- } else {
- log.warn('Failed to parse object value at path [' + path + ']. Value: (' + val + '). Type: (' + type + ')');
- }
- } else if (type === 'Number') {
- var parsedInt = parseInt(val, 10);
- if (!_.isNaN(parsedInt)) {
- _.set(object, path, parsedInt);
- } else {
- log.warn('Failed to parse object value at path [' + path + ']. Value: (' + val + '). Type: (' + type + ')');
- }
- }
- }
- }
-
- function handleNestedAndParsingFields(param, paramType) {
- var result = handleArraysAndObjectFields(param, paramType);
- result = handleNestedFieldsForAllParams(result, paramType);
- return result;
- }
-
- function tryParsingWithTypes(param, paramType) {
- var result = Object.assign({}, param);
- Object.keys(paramType).forEach(function (key) {
- tryParsingAsType(result, key, paramType[key]);
- });
- return result;
- }
-
- // Converts path params in the {param} format to the accepted :param format, used before inserting the URL params.
- function convertPathParams(url) {
- return url.replace(/{(.+?)}/g, ':$1');
- }
-
- function setLogger(logger) {
- log = logger;
- }
-
- return {
- handleNestedAndParsingFields,
- convertPathParams,
- tryParsingWithTypes,
- setLogger
- };
-});