mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-30 14:39:29 +02:00
add clients to int api
This commit is contained in:
parent
35a68703c2
commit
d38656e026
9 changed files with 158 additions and 14 deletions
|
@ -18,28 +18,28 @@ const getClientSchema = z
|
|||
})
|
||||
.strict();
|
||||
|
||||
async function query(clientId: number) {
|
||||
async function query(clientId: number, orgId: string) {
|
||||
// Get the client
|
||||
const [client] = await db
|
||||
.select()
|
||||
.from(clients)
|
||||
.where(eq(clients.clientId, clientId))
|
||||
.where(and(eq(clients.clientId, clientId), eq(clients.orgId, orgId)))
|
||||
.limit(1);
|
||||
|
||||
|
||||
if (!client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Get the siteIds associated with this client
|
||||
const sites = await db
|
||||
.select({ siteId: clientSites.siteId })
|
||||
.from(clientSites)
|
||||
.where(eq(clientSites.clientId, clientId));
|
||||
|
||||
|
||||
// Add the siteIds to the client object
|
||||
return {
|
||||
...client,
|
||||
siteIds: sites.map(site => site.siteId)
|
||||
siteIds: sites.map((site) => site.siteId)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -75,9 +75,9 @@ export async function getClient(
|
|||
);
|
||||
}
|
||||
|
||||
const { clientId } = parsedParams.data;
|
||||
const { clientId, orgId } = parsedParams.data;
|
||||
|
||||
const client = await query(clientId);
|
||||
const client = await query(clientId, orgId);
|
||||
|
||||
if (!client) {
|
||||
return next(
|
||||
|
@ -98,4 +98,4 @@ export async function getClient(
|
|||
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue