Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/json-object.js
const flattenObjectToDotNotation = require("../../../utils/flatten-object-to-dot-notation"); | const flattenObjectToDotNotation = require("../../../utils/flatten-object-to-dot-notation"); | ||||
("use strict"); | |||||
module.exports = { | module.exports = { | ||||
name: "json-object", | name: "json-object", | ||||
get_description: function() { | get_description() { | ||||
return "Stores json object value."; | return "Stores json object value."; | ||||
}, | }, | ||||
is_proper_value: async function(context, params, new_value) { | async is_proper_value(context, params, new_value) { | ||||
let stringified_value; | let stringified_value; | ||||
try { | try { | ||||
stringified_value = JSON.stringify(new_value); | stringified_value = JSON.stringify(new_value); | ||||
} catch (e) { | } catch (e) { | ||||
return Promise.reject( | return Promise.reject( | ||||
`Value ${new_value} cannot be represented as JSON object` | `Value ${new_value} cannot be represented as JSON object` | ||||
); | ); | ||||
} | } | ||||
if (!stringified_value.startsWith("{")) { | if (!stringified_value.startsWith("{")) { | ||||
return Promise.reject("A primitive, not an object!"); | return Promise.reject("A primitive, not an object!"); | ||||
} | } | ||||
}, | }, | ||||
encode: function(context, params, value_in_code) { | encode(context, params, value_in_code) { | ||||
return JSON.parse(JSON.stringify(value_in_code)); | return JSON.parse(JSON.stringify(value_in_code)); | ||||
}, | }, | ||||
get_aggregation_stages: function( | get_aggregation_stages( | ||||
context, | context, | ||||
params, | params, | ||||
field_name, | field_name, | ||||
field_value_path, | field_value_path, | ||||
query_params | query_params | ||||
) { | ) { | ||||
const filter = query_params.filter && query_params.filter[field_name]; | const filter = query_params.filter && query_params.filter[field_name]; | ||||
if (!filter) { | if (!filter) { | ||||
Show All 23 Lines |