Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
more specific proposal for tei attribue search
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Sep 15, 2021
1 parent c6ce718 commit 387fb23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
14 changes: 7 additions & 7 deletions ast.json
Expand Up @@ -3082,10 +3082,10 @@
"valid": true
},
{
"name": "valByName",
"name": "attrVal",
"params": [
"attr",
"name"
"tei",
"attributeName"
],
"docs": {
"description": "Gets an attribute value by its case-insensitive display name",
Expand All @@ -3106,21 +3106,21 @@
},
{
"title": "param",
"description": "An array of tracked entity attributes",
"description": "A tracked entity instance (TEI) object",
"type": {
"type": "NameExpression",
"name": "Object"
},
"name": "attr"
"name": "tei"
},
{
"title": "param",
"description": "The display name to search for",
"description": "The 'displayName' to search for in the TEI's attributes",
"type": {
"type": "NameExpression",
"name": "string"
},
"name": "name"
"name": "attributeName"
},
{
"title": "returns",
Expand Down
16 changes: 8 additions & 8 deletions lib/Adaptor.js
Expand Up @@ -34,7 +34,7 @@ exports.update = update;
exports.patch = patch;
exports.del = del;
exports.upsert = upsert;
exports.valByName = valByName;
exports.attrVal = attrVal;
Object.defineProperty(exports, "field", {
enumerable: true,
get: function get() {
Expand Down Expand Up @@ -1859,16 +1859,16 @@ function upsert(resourceType, uniqueAttribute, data, params, options, callback)
* @example
* valByName(tei.attributes, 'first name')
* @function
* @param {Object} attr - An array of tracked entity attributes
* @param {string} name - The display name to search for
* @param {Object} tei - A tracked entity instance (TEI) object
* @param {string} attributeName - The 'displayName' to search for in the TEI's attributes
* @returns {string}
*/


function valByName(attr, name) {
var _attr$find;
function attrVal(tei, attributeName) {
var _tei$attributes, _tei$attributes$find;

return (_attr$find = attr.find(function (a) {
return a.displayName.toLowerCase() == name.toLowerCase();
})) === null || _attr$find === void 0 ? void 0 : _attr$find.value;
return tei === null || tei === void 0 ? void 0 : (_tei$attributes = tei.attributes) === null || _tei$attributes === void 0 ? void 0 : (_tei$attributes$find = _tei$attributes.find(function (a) {
return (a === null || a === void 0 ? void 0 : a.displayName.toLowerCase()) == attributeName.toLowerCase();
})) === null || _tei$attributes$find === void 0 ? void 0 : _tei$attributes$find.value;
}
16 changes: 9 additions & 7 deletions src/Adaptor.js
Expand Up @@ -899,8 +899,9 @@ export function discover(httpMethod, endpoint) {
if (param.schema['$ref']) {
let schemaRefIndex =
param.schema['$ref'].lastIndexOf('/') + 1;
let schemaRef =
param.schema['$ref'].slice(schemaRefIndex);
let schemaRef = param.schema['$ref'].slice(
schemaRefIndex
);
param.schema = tempData.components.schemas[schemaRef];
}

Expand Down Expand Up @@ -1933,13 +1934,14 @@ export function upsert(
* @example
* valByName(tei.attributes, 'first name')
* @function
* @param {Object} attr - An array of tracked entity attributes
* @param {string} name - The display name to search for
* @param {Object} tei - A tracked entity instance (TEI) object
* @param {string} attributeName - The 'displayName' to search for in the TEI's attributes
* @returns {string}
*/
export function valByName(attr, name) {
return attr.find(a => a.displayName.toLowerCase() == name.toLowerCase())
?.value;
export function attrVal(tei, attributeName) {
return tei?.attributes?.find(
a => a?.displayName.toLowerCase() == attributeName.toLowerCase()
)?.value;
}

export { attribute } from './Utils';
Expand Down

0 comments on commit 387fb23

Please sign in to comment.