Refine 'convertObjectToCypherMapLiteral' with additional parameter

This commit is contained in:
Wolfgang Huß 2022-09-14 16:30:09 +02:00
parent 7bb3a05b07
commit 73b6b24b72
2 changed files with 4 additions and 3 deletions

View File

@ -18,7 +18,7 @@ export default {
removeUndefinedNullValuesFromObject(matchParams)
const session = context.driver.session()
const readTxResultPromise = session.readTransaction(async (txc) => {
const groupMatchParamsCypher = convertObjectToCypherMapLiteral(matchParams)
const groupMatchParamsCypher = convertObjectToCypherMapLiteral(matchParams, true)
let groupCypher
if (isMember === true) {
groupCypher = `

View File

@ -130,7 +130,7 @@ export const removeUndefinedNullValuesFromObject = (obj) => {
})
}
export const convertObjectToCypherMapLiteral = (params) => {
export const convertObjectToCypherMapLiteral = (params, addSpaceInfrontIfMapIsNotEmpty = false) => {
// I have found no other way yet. maybe "apoc.convert.fromJsonMap(key)" can help, but couldn't get it how, see: https://stackoverflow.com/questions/43217823/neo4j-cypher-inline-conversion-of-string-to-a-map
// result looks like: '{id: "g0", slug: "yoga"}'
const paramsEntries = Object.entries(params)
@ -140,5 +140,6 @@ export const convertObjectToCypherMapLiteral = (params) => {
mapLiteral += `${ele[0]}: "${ele[1]}"`
mapLiteral += index < paramsEntries.length - 1 ? ', ' : '}'
})
mapLiteral = (addSpaceInfrontIfMapIsNotEmpty && mapLiteral.length > 0 ? ' ' : '') + mapLiteral
return mapLiteral
}