This commit is contained in:
2025-06-20 12:13:46 +05:00
parent cd61fc686b
commit 00c840abb7
9 changed files with 55 additions and 37 deletions
+13 -4
View File
@@ -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;
});
+30 -23
View File
@@ -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");
+1
View File
@@ -17,6 +17,7 @@ export async function getComments(sessionId: string, managerId: string) {
id: true,
},
},
session: true,
},
orderBy: desc(commentsTable.createdAt),
});
+1 -1
View File
@@ -52,7 +52,7 @@ export default async function getServers(
},
},
},
apps: { with: { app: true } },
appsToServers: { with: { app: true } },
}
: undefined),
},