upd
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -52,7 +52,7 @@ export default async function getServers(
|
||||
},
|
||||
},
|
||||
},
|
||||
apps: true,
|
||||
apps: { with: { app: true } },
|
||||
}
|
||||
: undefined),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user