Changeset View
Changeset View
Standalone View
Standalone View
lib/chip-types/field-type-default-methods.js
"use strict"; | |||||
const Promise = require("bluebird"); | const Promise = require("bluebird"); | ||||
const expandHash = require("expand-hash"); | const expandHash = require("expand-hash"); | ||||
const FieldTypeDescription = require("../data-structures/field-type-description.js"); | const FieldTypeDescription = require("../data-structures/field-type-description.js"); | ||||
const default_methods = { | const default_methods = { | ||||
init: function() { | init() { | ||||
return null; | return null; | ||||
}, | }, | ||||
has_index: function(params) { | has_index(params) { | ||||
return false; | return false; | ||||
}, | }, | ||||
is_proper_value: function(context, params, new_value, old_value) { | is_proper_value(context, params, new_value, old_value) { | ||||
return Promise.resolve(); | return Promise.resolve(); | ||||
}, | }, | ||||
format: function(context, params, decoded_value, format_params) { | format(context, params, decoded_value, format_params) { | ||||
return decoded_value; | return decoded_value; | ||||
}, | }, | ||||
encode: function(context, params, value_in_code) { | encode(context, params, value_in_code) { | ||||
return value_in_code; | return value_in_code; | ||||
}, | }, | ||||
get_description: function(context, params) { | get_description(context, params) { | ||||
return new FieldTypeDescription(this.name); | return new FieldTypeDescription(this.name); | ||||
}, | }, | ||||
decode: function(context, params, value_in_database) { | decode(context, params, value_in_database) { | ||||
return value_in_database; | return value_in_database; | ||||
}, | }, | ||||
filter_to_query: function(context, params, query) { | filter_to_query(context, params, query) { | ||||
return Promise.resolve(this.encode(context, params, query)).then( | return Promise.resolve(this.encode(context, params, query)).then( | ||||
function(encoded_value) { | encoded_value => ({ | ||||
return { | |||||
$eq: encoded_value, | $eq: encoded_value, | ||||
}; | }) | ||||
} | |||||
); | ); | ||||
}, | }, | ||||
full_text_search_enabled: function() { | full_text_search_enabled() { | ||||
return false; | return false; | ||||
}, | }, | ||||
get_aggregation_stages: async function( | async get_aggregation_stages( | ||||
context, | context, | ||||
params, | params, | ||||
field_name, | field_name, | ||||
field_value_path, | field_value_path, | ||||
query_params | query_params | ||||
) { | ) { | ||||
const self = this; | const self = this; | ||||
if (!query_params || !query_params.filter) return []; | if (!query_params || !query_params.filter) return []; | ||||
Show All 9 Lines | ) { | ||||
if (!(field_name in expanded_filter)) { | if (!(field_name in expanded_filter)) { | ||||
return []; | return []; | ||||
} | } | ||||
if (field_name in expanded_filter && field_filter === undefined) | if (field_name in expanded_filter && field_filter === undefined) | ||||
return [{ $match: { [field_value_path]: { $exists: false } } }]; | return [{ $match: { [field_value_path]: { $exists: false } } }]; | ||||
let new_filter = null; | let new_filter = null; | ||||
if (field_filter instanceof Array) { | if (field_filter instanceof Array) { | ||||
new_filter = await Promise.all( | new_filter = await Promise.all( | ||||
field_filter.map(function(element) { | field_filter.map(element => { | ||||
return self.encode(context, params, element); | return self.encode(context, params, element); | ||||
}) | }) | ||||
).then(filters => { | ).then(filters => { | ||||
return { $in: filters }; | return { $in: filters }; | ||||
}); | }); | ||||
} else { | } else { | ||||
new_filter = await self.filter_to_query( | new_filter = await self.filter_to_query( | ||||
context, | context, | ||||
Show All 9 Lines |