Skip to content

Commit 57beefb

Browse files
committed
Fix query collision on i variable
1 parent 787d35e commit 57beefb

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

backend/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@compass/api",
33
"description": "Backend API endpoints",
4-
"version": "1.0.10",
4+
"version": "1.0.11",
55
"private": true,
66
"scripts": {
77
"watch:serve": "tsx watch src/serve.ts",

backend/api/src/get-profiles.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const loadProfiles = async (props: profileQueryType) => {
111111
FROM profile_${label}
112112
JOIN ${label} ON ${label}.id = profile_${label}.option_id
113113
GROUP BY profile_${label}.profile_id
114-
) i ON i.profile_id = profiles.id`
114+
) profile_${label} ON profile_${label}.profile_id = profiles.id`
115115
}
116116
const interestsJoin = getManyToManyJoin('interests')
117117
const causesJoin = getManyToManyJoin('causes')
@@ -143,10 +143,10 @@ export const loadProfiles = async (props: profileQueryType) => {
143143

144144
function getManyToManyClause(label: OptionTableKey) {
145145
return `EXISTS (
146-
SELECT 1 FROM profile_${label} pi2
147-
JOIN ${label} ii2 ON ii2.id = pi2.option_id
148-
WHERE pi2.profile_id = profiles.id
149-
AND ii2.name = ANY (ARRAY[$(values)])
146+
SELECT 1 FROM profile_${label}
147+
JOIN ${label} ON ${label}.id = profile_${label}.option_id
148+
WHERE profile_${label}.profile_id = profiles.id
149+
AND ${label}.name = ANY (ARRAY[$(values)])
150150
)`
151151
}
152152

@@ -278,9 +278,9 @@ export const loadProfiles = async (props: profileQueryType) => {
278278
} else if (orderByParam === 'last_online_time') {
279279
selectCols += ', user_activity.last_online_time'
280280
}
281-
if (interests) selectCols += `, COALESCE(i.interests, '{}') AS interests`
282-
if (causes) selectCols += `, COALESCE(i.causes, '{}') AS causes`
283-
if (work) selectCols += `, COALESCE(i.work, '{}') AS work`
281+
if (interests) selectCols += `, COALESCE(profile_interests.interests, '{}') AS interests`
282+
if (causes) selectCols += `, COALESCE(profile_causes.causes, '{}') AS causes`
283+
if (work) selectCols += `, COALESCE(profile_work.work, '{}') AS work`
284284

285285
const query = renderSql(
286286
select(selectCols),
@@ -291,7 +291,7 @@ export const loadProfiles = async (props: profileQueryType) => {
291291
limitParam && limit(limitParam),
292292
)
293293

294-
console.debug('query:', query)
294+
// console.debug('query:', query)
295295

296296
const profiles = await pg.map(query, [], convertRow)
297297

0 commit comments

Comments
 (0)