getleaves fix
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-09-13 13:00:33 +02:00
parent efcfa9c568
commit d30a21974d
1 changed files with 10 additions and 13 deletions

View File

@ -31,7 +31,7 @@ module.exports = Self => {
}
});
Self.getLeaves = async(zoneFk, parentFk, filter) => {
Self.getLeaves = async(zoneFk, parentFk = null, filter) => {
let conn = Self.dataSource.connector;
let stmts = [];
@ -78,20 +78,17 @@ module.exports = Self => {
ON zg.lft <= ch.lft AND zg.rgt >= ch.rgt
UNION ALL
SELECT
child.id,
child.name,
child.lft,
child.rgt,
child.depth,
child.sons,
zg.id,
zg.name,
zg.lft,
zg.rgt,
zg.depth,
zg.sons,
zi.isIncluded AS selected
FROM zoneGeo parent
JOIN zoneGeo child ON child.lft > parent.lft
AND child.rgt < parent.rgt
AND child.depth = parent.depth + 1
LEFT JOIN zoneIncluded zi ON zi.geoFk = child.id
FROM zoneGeo zg
LEFT JOIN zoneIncluded zi ON zi.geoFk = zg.id
AND zi.zoneFk = ?
WHERE parent.id = ?) AS nst`, [zoneFk, parentFk]);
WHERE zg.parentFk IS NULL OR zg.parentFk = ?) AS nst`, [zoneFk, parentFk]);
// Get nodes from depth greather than Origin
stmt.merge(conn.makeSuffix(filter));