Skip to content

Commit

Permalink
fix: refNode.value.split is not a function
Browse files Browse the repository at this point in the history
# Problems
- The json path `$..reference` may be nested object
- and get {"reference": "xxx"}

# Solutions
- Check whether object
- If is object, split "reference" field
- otherwise, split value
  • Loading branch information
Chinlinlee committed Sep 2, 2023
1 parent 06e1f71 commit 43c9212
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/mongodb/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require("lodash");
const jp = require("jsonpath");
const mongoose = require("mongoose");

Expand All @@ -19,7 +20,7 @@ const mongoose = require("mongoose");
async function storeResourceRefBy(resource) {
let referenceInItem = jp.nodes(resource, "$..reference");
for (let refNode of referenceInItem) {
let referenceSplit = refNode.value.split("/");
let referenceSplit = _.isObject(refNode.value) ? refNode.value["reference"].split("/") : refNode.value.split("/");
let id = referenceSplit[referenceSplit.length - 1];
let resourceType = referenceSplit[referenceSplit.length - 2];

Expand Down

0 comments on commit 43c9212

Please sign in to comment.