fix: 🐛 Fix v2 search API not working at all

This commit is contained in:
Jesse Wierzbinski 2024-06-28 23:59:01 -10:00
parent 93b8609411
commit 84bdb75d77
No known key found for this signature in database

View file

@ -154,42 +154,50 @@ export default (app: Hono) =>
); );
} }
const accounts = await User.manyFromSql( const accounts =
and( accountResults.length > 0
inArray( ? await User.manyFromSql(
Users.id, and(
accountResults.map((hit) => hit), inArray(
), Users.id,
self accountResults.map((hit) => hit),
? sql`EXISTS (SELECT 1 FROM Relationships WHERE Relationships.subjectId = ${ ),
self?.id self && following
} AND Relationships.following = ${!!following} AND Relationships.ownerId = ${ ? sql`EXISTS (SELECT 1 FROM "Relationships" WHERE "Relationships"."subjectId" = ${
Users.id self?.id
})` } AND "Relationships".following = ${!!following} AND "Relationships"."ownerId" = ${
: undefined, Users.id
), })`
); : undefined,
),
)
: [];
const statuses = await Note.manyFromSql( const statuses =
and( statusResults.length > 0
inArray( ? await Note.manyFromSql(
Notes.id, and(
statusResults.map((hit) => hit), inArray(
), Notes.id,
account_id ? eq(Notes.authorId, account_id) : undefined, statusResults.map((hit) => hit),
self ),
? sql`EXISTS (SELECT 1 FROM Relationships WHERE Relationships.subjectId = ${ account_id
self?.id ? eq(Notes.authorId, account_id)
} AND Relationships.following = ${!!following} AND Relationships.ownerId = ${ : undefined,
Notes.authorId self && following
})` ? sql`EXISTS (SELECT 1 FROM "Relationships" WHERE "Relationships"."subjectId" = ${
: undefined, self?.id
), } AND "Relationships".following = ${!!following} AND "Relationships"."ownerId" = ${
undefined, Notes.authorId
undefined, })`
undefined, : undefined,
self?.id, ),
); undefined,
undefined,
undefined,
self?.id,
)
: [];
return jsonResponse({ return jsonResponse({
accounts: accounts.map((account) => account.toApi()), accounts: accounts.map((account) => account.toApi()),