Skip to content

Commit

Permalink
Update locations to use locations model
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Jan 9, 2025
1 parent 8def78a commit c6fd164
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions core/models/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ SELECT
SELECT
DISTINCT(a.name)
FROM
locations_boundaryalias a
locations_locationalias a
WHERE
a.boundary_id = l.id AND
a.location_id = l.id AND
a.is_active = TRUE AND
a.org_id = $1
ORDER BY
a.name
)a ) aliases
FROM
locations_adminboundary l
locations_location l
WHERE
l.lft >= (select lft from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1) and
l.rght <= (select rght from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1) and
l.tree_id = (select tree_id from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1)
l.lft >= (select lft from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1) and
l.rght <= (select rght from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1) and
l.tree_id = (select tree_id from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1)
ORDER BY
l.level, l.id;
`
10 changes: 5 additions & 5 deletions core/models/locations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
func TestLocations(t *testing.T) {
ctx, rt := testsuite.Runtime()

defer rt.DB.MustExec(`DELETE FROM locations_boundaryalias WHERE created_by_id = 2`)
defer rt.DB.MustExec(`DELETE FROM locations_locationalias WHERE created_by_id = 2`)

rt.DB.MustExec(`INSERT INTO locations_boundaryalias(is_active, created_on, modified_on, name, boundary_id, created_by_id, modified_by_id, org_id)
VALUES(TRUE, NOW(), NOW(), 'Soko', 8148, 2, 1, 1);`)
rt.DB.MustExec(`INSERT INTO locations_boundaryalias(is_active, created_on, modified_on, name, boundary_id, created_by_id, modified_by_id, org_id)
VALUES(TRUE, NOW(), NOW(), 'Sokoz', 8148, 2, 1, 2);`)
rt.DB.MustExec(`INSERT INTO locations_locationalias(is_active, created_on, modified_on, name, location_id, created_by_id, modified_by_id, org_id)
VALUES(TRUE, NOW(), NOW(), 'Soko', 987, 2, 1, 1);`)
rt.DB.MustExec(`INSERT INTO locations_locationalias(is_active, created_on, modified_on, name, location_id, created_by_id, modified_by_id, org_id)
VALUES(TRUE, NOW(), NOW(), 'Sokoz', 987, 2, 1, 2);`)

oa, err := models.GetOrgAssetsWithRefresh(ctx, rt, testdata.Org1.ID, models.RefreshLocations)
require.NoError(t, err)
Expand Down
Binary file modified testsuite/testfiles/postgres.dump
Binary file not shown.

0 comments on commit c6fd164

Please sign in to comment.