return this.drizzleService.db.query.Client.findMany({
columns: CLIENT_QUERY,
with: {
Documents: {
columns: DOCUMENT_QUERY,
},
SharedClients: {
columns: SHARED_CLIENT_QUERY,
with: {
User_sharedWithId: {
columns: PARTIAL_USER_QUERY,
},
},
where: eq(SharedClient.ownerId, userId),
},
User: {
columns: PARTIAL_USER_QUERY,
// where: ne(Client.ownerId, userId),
},
},
where: or(
eq(Client.ownerId, userId),
inArray(
Client.id,
this.drizzleService.db
.select({ clientId: SharedClient.clientId })
.from(SharedClient)
.where(eq(SharedClient.sharedWithId, userId)),
),
),
});
return this.drizzleService.db.query.Client.findMany({
columns: CLIENT_QUERY,
with: {
Documents: {
columns: DOCUMENT_QUERY,
},
SharedClients: {
columns: SHARED_CLIENT_QUERY,
with: {
User_sharedWithId: {
columns: PARTIAL_USER_QUERY,
},
},
where: eq(SharedClient.ownerId, userId),
},
User: {
columns: PARTIAL_USER_QUERY,
// where: ne(Client.ownerId, userId),
},
},
where: or(
eq(Client.ownerId, userId),
inArray(
Client.id,
this.drizzleService.db
.select({ clientId: SharedClient.clientId })
.from(SharedClient)
.where(eq(SharedClient.sharedWithId, userId)),
),
),
});