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

This commit is contained in:
Joan Sanchez 2019-09-13 13:26:50 +02:00
parent a25652293d
commit a529efc783
1 changed files with 12 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,19 @@ 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 (? IS NULL AND zg.parentFk IS NULL)
OR (? IS NOT NULL AND zg.parentFk = ?)) AS nst`,
[zoneFk, parentFk, parentFk, parentFk]);
// Get nodes from depth greather than Origin
stmt.merge(conn.makeSuffix(filter));