Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/map extent setting #1380

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions backend/src/components/projectObject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ export async function getProjectObjectsByProjectId(projectId: string) {

export async function getGeometriesByProjectId(projectId: string) {
return getPool().any(sql.type(dbProjectObjectGeometrySchema)`
WITH dump as (${getProjectObjectGeometryDumpFragment()})
SELECT
ST_AsGeoJSON(ST_CollectionExtract(geom)) AS geom,
id "projectObjectId",
object_name "objectName"
FROM app.project_object
dump.geom,
po.id "projectObjectId",
po.object_name "objectName"
FROM app.project_object po
LEFT JOIN dump ON dump.id = po.id
WHERE project_id = ${projectId} AND deleted = false;
`);
}
Expand Down
31 changes: 16 additions & 15 deletions backend/src/components/projectObject/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
timePeriodFragment,
} from '@backend/components/projectObject/index.js';
import { getPool } from '@backend/db.js';
import { logger } from '@backend/logging.js';

import {
ObjectsByProjectSearch,
Expand Down Expand Up @@ -117,31 +118,30 @@ function getObjectRoleFilterFragment(
// Object participants includes all roles except suunnitteluttaja and rakennuttaja
if (objectParticipantUser) {
return sql.fragment`
((pour.role).code_list_id = 'KohdeKayttajaRooli' AND pour.user_id = ${objectParticipantUser})`;
((pour_participant.role).code_list_id = 'KohdeKayttajaRooli' AND pour_participant.user_id = ${objectParticipantUser})`;
}
return sql.fragment`true`;
}

if (rakennuttajaUsers.length > 0 && suunnitteluttajaUsers.length > 0) {
return sql.fragment`((pour.role = ('InvestointiKohdeKayttajaRooli', '01')::app.code_id AND pour.user_id = ANY(${sql.array(
return sql.fragment`((pour_rakennuttaja.role = ('InvestointiKohdeKayttajaRooli', '01')::app.code_id AND pour_rakennuttaja.user_id = ANY(${sql.array(
rakennuttajaUsers,
'text',
)})) OR (pour.role = ('InvestointiKohdeKayttajaRooli', '02')::app.code_id AND pour.user_id = ANY(${sql.array(
)})) AND (pour_suunnitteluttaja.role = ('InvestointiKohdeKayttajaRooli', '02')::app.code_id AND pour_suunnitteluttaja.user_id = ANY(${sql.array(
suunnitteluttajaUsers,
'text',
)})) OR ${objectParticipantFragment(objectParticipantUser)})`;
)})) AND ${objectParticipantFragment(objectParticipantUser) ?? sql.fragment`true`})`;
} else if (rakennuttajaUsers.length > 0) {
return sql.fragment`((pour.role = ('InvestointiKohdeKayttajaRooli', '01')::app.code_id AND pour.user_id = ANY(${sql.array(
return sql.fragment`((pour_rakennuttaja.role = ('InvestointiKohdeKayttajaRooli', '01')::app.code_id AND pour_rakennuttaja.user_id = ANY(${sql.array(
rakennuttajaUsers,
'text',
)})) OR ${objectParticipantFragment(objectParticipantUser)})`;
)})) AND ${objectParticipantFragment(objectParticipantUser) ?? sql.fragment`true`})`;
} else if (suunnitteluttajaUsers.length > 0) {
return sql.fragment`((pour.role = ('InvestointiKohdeKayttajaRooli', '02')::app.code_id AND pour.user_id = ANY(${sql.array(
return sql.fragment`((pour_suunnitteluttaja.role = ('InvestointiKohdeKayttajaRooli', '02')::app.code_id AND pour_suunnitteluttaja.user_id = ANY(${sql.array(
suunnitteluttajaUsers,
'text',
)})) OR ${objectParticipantFragment(objectParticipantUser)})`;
)})) AND ${objectParticipantFragment(objectParticipantUser) ?? sql.fragment`true`})`;
} else {
return objectParticipantFragment(objectParticipantUser);
return objectParticipantFragment(objectParticipantUser) ?? sql.fragment`true`;
}
}

Expand Down Expand Up @@ -203,7 +203,9 @@ export async function projectObjectSearch(input: ProjectObjectSearch) {
withGeoHash: true,
withGeometries,
})}
LEFT JOIN app.project_object_user_role pour ON po.id = pour.project_object_id
LEFT JOIN app.project_object_user_role pour_rakennuttaja ON po.id = pour_rakennuttaja.project_object_id
LEFT JOIN app.project_object_user_role pour_suunnitteluttaja ON po.id = pour_suunnitteluttaja.project_object_id
LEFT JOIN app.project_object_user_role pour_participant ON po.id = pour_participant.project_object_id
WHERE po.deleted = false
-- search date range intersection
AND ${timePeriodFragment(input)}
Expand Down Expand Up @@ -238,10 +240,9 @@ export async function projectObjectSearch(input: ProjectObjectSearch) {
rakennuttajaUsers,
suunnitteluttajaUsers,
)}

GROUP BY po.id, poi.project_object_id, project.id, poi.object_stage


GROUP BY po.id, poi.project_object_id, project.id, poi.object_stage ${
withGeometries ? sql.fragment`, project_dump.geom, object_dump.geom` : sql.fragment``
}
),
search_results AS (select * from total_results LIMIT ${limit}),
project_object_results AS (
Expand Down
Loading
Loading