Partial select with join throwing TS error

await db.select(
{
...sesizare,
reporterName: authUser.fullName,
votes: count(sesizareVotes.voterId),
voted: count(sesizareVotes.voterId, eq(sesizareVotes.voterId, event.context.user?.id || '')),
},
)
.from(sesizare)
.leftJoin(sesizareVotes, eq(sesizare.id, sesizareVotes.sesizareId))
.leftJoin(authUser, eq(sesizare.reporter, authUser.id))
.where(and(
or(
query.status ? eq(sesizare.status, query.status) : isNotNull(sesizare.status),
like(sesizare.title, `%${query.search}%`),
like(sesizare.description, `%${query.search}%`),
),
between(sesizare.latitude, query.sw_lat, query.ne_lat),
between(sesizare.longitude, query.ne_lng, query.sw_lng),
))
.groupBy(sesizare.id)
.orderBy(query.sort === 'desc' ? desc(sesizare[query.sortby]) : asc(sesizare[query.sortby]))
.limit(query.limit)
.offset(query.offset)
await db.select(
{
...sesizare,
reporterName: authUser.fullName,
votes: count(sesizareVotes.voterId),
voted: count(sesizareVotes.voterId, eq(sesizareVotes.voterId, event.context.user?.id || '')),
},
)
.from(sesizare)
.leftJoin(sesizareVotes, eq(sesizare.id, sesizareVotes.sesizareId))
.leftJoin(authUser, eq(sesizare.reporter, authUser.id))
.where(and(
or(
query.status ? eq(sesizare.status, query.status) : isNotNull(sesizare.status),
like(sesizare.title, `%${query.search}%`),
like(sesizare.description, `%${query.search}%`),
),
between(sesizare.latitude, query.sw_lat, query.ne_lat),
between(sesizare.longitude, query.ne_lng, query.sw_lng),
))
.groupBy(sesizare.id)
.orderBy(query.sort === 'desc' ? desc(sesizare[query.sortby]) : asc(sesizare[query.sortby]))
.limit(query.limit)
.offset(query.offset)
Getting 2 errors: - Getting Expected 0 arguments, but got 1 - Expected 0-1 arguments, but got 2. this one is related to count with filter)
No description
1 Reply
Andrei Vintila
Andrei VintilaOP10mo ago
It works but the types are all broken as if it's not respecting the partial select.
Want results from more Discord servers?
Add your server