upd
This commit is contained in:
@@ -28,10 +28,19 @@ async function createClient(
|
||||
})
|
||||
.returning();
|
||||
|
||||
await tx.insert(clientsToManagers).values({
|
||||
clientId: newClient.id,
|
||||
managerId: auth.managerId,
|
||||
});
|
||||
await tx
|
||||
.insert(clientsToManagers)
|
||||
.values({
|
||||
clientId: newClient.id,
|
||||
managerId: auth.managerId,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [clientsToManagers.clientId, clientsToManagers.managerId],
|
||||
set: {
|
||||
clientId: newClient.id,
|
||||
managerId: auth.managerId,
|
||||
},
|
||||
});
|
||||
|
||||
return newClient;
|
||||
});
|
||||
|
||||
@@ -13,31 +13,38 @@ async function getClients({
|
||||
companyId: string;
|
||||
}) {
|
||||
try {
|
||||
return await db.query.clientsTable.findMany({
|
||||
where: and(
|
||||
eq(clientsTable.companyId, companyId),
|
||||
search
|
||||
? or(
|
||||
ilike(clientsTable.name, `%${search}%`),
|
||||
ilike(clientsTable.email, `%${search}%`),
|
||||
ilike(clientsTable.phone, `%${search}%`)
|
||||
)
|
||||
: undefined
|
||||
),
|
||||
limit,
|
||||
with: {
|
||||
managers: { with: { manager: { columns: { password: false } } } },
|
||||
sessions: {
|
||||
with: {
|
||||
manager: { columns: { password: false } },
|
||||
app: true,
|
||||
comments: { with: { manager: { columns: { password: false } } } },
|
||||
server: true,
|
||||
client: true,
|
||||
return (
|
||||
await db.query.clientsTable.findMany({
|
||||
where: and(
|
||||
eq(clientsTable.companyId, companyId),
|
||||
search
|
||||
? or(
|
||||
ilike(clientsTable.name, `%${search}%`),
|
||||
ilike(clientsTable.email, `%${search}%`),
|
||||
ilike(clientsTable.phone, `%${search}%`)
|
||||
)
|
||||
: undefined
|
||||
),
|
||||
limit,
|
||||
with: {
|
||||
clientsToManagers: {
|
||||
with: { manager: { columns: { password: false } } },
|
||||
},
|
||||
sessions: {
|
||||
with: {
|
||||
manager: { columns: { password: false } },
|
||||
app: true,
|
||||
comments: { with: { manager: { columns: { password: false } } } },
|
||||
server: true,
|
||||
client: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
).map(({ clientsToManagers, ...client }) => ({
|
||||
...client,
|
||||
managers: clientsToManagers.map(({ manager }) => manager),
|
||||
}));
|
||||
} catch (error) {
|
||||
console.log((error as Error).message);
|
||||
return status(500, "Internal Server Error");
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function getComments(sessionId: string, managerId: string) {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
session: true,
|
||||
},
|
||||
orderBy: desc(commentsTable.createdAt),
|
||||
});
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function getServers(
|
||||
},
|
||||
},
|
||||
},
|
||||
apps: { with: { app: true } },
|
||||
appsToServers: { with: { app: true } },
|
||||
}
|
||||
: undefined),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user