This commit is contained in:
2025-03-24 12:24:39 +05:00
parent c30a868761
commit 98653d6fde
8 changed files with 75 additions and 13 deletions
+44
View File
@@ -0,0 +1,44 @@
import { eq } from "drizzle-orm";
import db from "../../db";
import { clientsTable } from "../../db/schema";
import { error } from "elysia";
async function createClient(
auth: {
userId: string;
companyId: string;
},
body: {
name: string;
phone: string;
email?: string;
}
) {
try {
// Check for existing client
const [existingClient] = await db
.select()
.from(clientsTable)
.where(eq(clientsTable.name, body.name));
if (existingClient) {
return existingClient;
}
// Create new client
const [newClient] = await db
.insert(clientsTable)
.values({
...body,
ownerId: auth.userId,
companyId: auth.companyId,
})
.returning();
return newClient;
} catch (err) {
return error(500, "Internal Server Error");
}
}
export default createClient;
+4 -1
View File
@@ -32,7 +32,9 @@ export default async function getServers(
with: {
client: {
columns: {
fullname: true,
name: true,
phone: true,
email: true,
},
},
app: {
@@ -42,6 +44,7 @@ export default async function getServers(
},
},
},
apps: true,
}
: undefined),
},
-1
View File
@@ -40,7 +40,6 @@ async function createSession(
...body,
ownerId: auth.userId,
companyId: auth.companyId,
status: "starting",
})
.returning();