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