upd
This commit is contained in:
@@ -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;
|
||||
@@ -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),
|
||||
},
|
||||
|
||||
@@ -40,7 +40,6 @@ async function createSession(
|
||||
...body,
|
||||
ownerId: auth.userId,
|
||||
companyId: auth.companyId,
|
||||
status: "starting",
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user