This commit is contained in:
2025-06-17 17:38:29 +05:00
parent a0b25520e3
commit 46dc5fa25f
4 changed files with 42 additions and 15 deletions
+14 -5
View File
@@ -1,6 +1,6 @@
import { status } from "elysia";
import db from "../../db";
import { appsTable } from "../../db/schema";
import { appsTable, appsToServers } from "../../db/schema";
import { sql } from "drizzle-orm";
import type { AuthContext } from "./../../middlewares/auth";
@@ -26,21 +26,30 @@ export default async function createApp(
name: app,
fileName: app,
companyId: body.companyId,
serverId: body.serverId,
}))
)
.returning()
.onConflictDoUpdate({
target: [appsTable.fileName, appsTable.serverId],
target: [appsTable.fileName],
set: {
name: sql`excluded.name`,
fileName: sql`excluded.fileName`,
companyId: sql`excluded.company_id`,
serverId: sql`excluded.server_id`,
},
});
return apps;
const appsOfServer = await db
.insert(appsToServers)
.values(apps.map(({ id }) => ({ appId: id, serverId: body.serverId })))
.onConflictDoUpdate({
target: [appsToServers.appId, appsToServers.serverId],
set: { appId: sql`excluded.app_id`, serverId: body.serverId },
})
.returning();
console.log(appsOfServer);
return appsOfServer;
} catch (error) {
console.log((error as Error).message);
return status(500, "Internal Server Error");
+1 -1
View File
@@ -52,7 +52,7 @@ export default async function getServers(
},
},
},
apps: true,
apps: { with: { app: true } },
}
: undefined),
},