Skip to content

Commit f08eeb5

Browse files
committed
Bug fixes
Avoid cloning functions with structuredClone Create app group after validating apps, avoiding empty app groups when apps are invalid
1 parent 4590499 commit f08eeb5

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

backend/src/db/repo/appGroup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ export class AppGroupRepo {
3030
}
3131
}
3232

33+
async delete(appGroupId: number) {
34+
if (
35+
(await this.client.app.count({ where: { appGroupId: appGroupId } })) > 0
36+
) {
37+
throw new Error("App group is not empty");
38+
}
39+
await this.client.appGroup.delete({ where: { id: appGroupId } });
40+
}
41+
3342
async getById(appGroupId: number): Promise<AppGroup> {
3443
return await this.client.appGroup.findUnique({
3544
where: { id: appGroupId },

backend/src/db/repo/deployment.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,9 @@ export class DeploymentRepo {
288288
if (config === null) {
289289
return null;
290290
}
291-
const newConfig = structuredClone(config);
291+
const { getEnv, displayEnv, asGitConfig, ...clonable } = config;
292+
const newConfig = structuredClone(clonable);
292293
const env = config.getEnv();
293-
delete newConfig.displayEnv;
294-
delete newConfig.getEnv;
295-
296294
return { ...newConfig, env };
297295
}
298296

backend/src/service/createApp.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export async function createApp(appData: NewApp, userId: number) {
2626
}
2727

2828
let app: App;
29+
30+
let { config, commitMessage } = (
31+
await appService.prepareMetadataForApps(organization, user, {
32+
type: "create",
33+
...appData,
34+
})
35+
)[0];
36+
2937
let appGroupId: number;
3038

3139
switch (appData.appGroup.type) {
@@ -59,13 +67,6 @@ export async function createApp(appData: NewApp, userId: number) {
5967
}
6068
}
6169

62-
let { config, commitMessage } = (
63-
await appService.prepareMetadataForApps(organization, user, {
64-
type: "create",
65-
...appData,
66-
})
67-
)[0];
68-
6970
try {
7071
app = await db.app.create({
7172
orgId: appData.orgId,

backend/src/service/createAppGroup.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,12 @@ export async function createAppGroup(
1919
appData: NewAppWithoutGroup[],
2020
) {
2121
appService.validateAppGroupName(groupName);
22-
const groupId = await db.appGroup.create(orgId, groupName, false);
23-
// let groupId: number;
24-
// try {
25-
// groupId = await db.appGroup.create(orgId, groupName, false);
26-
// } catch (e) {
27-
// if (e instanceof ConflictError) {
28-
// throw new ValidationError(
29-
// "An app group already exists with the same name.",
30-
// );
31-
// }
32-
// throw e;
33-
// }
34-
const appsWithGroups = appData.map(
22+
const apps = appData.map(
3523
(app) =>
3624
({
3725
...app,
3826
orgId: orgId,
39-
appGroup: { type: "add-to", id: groupId },
40-
}) satisfies NewApp,
27+
}) satisfies Omit<NewApp, "appGroup">,
4128
);
4229

4330
const [organization, user] = await Promise.all([
@@ -59,11 +46,24 @@ export async function createAppGroup(
5946
})),
6047
);
6148

62-
const appsWithMetadata = appsWithGroups.map((app, idx) => ({
49+
const appsWithMetadata = apps.map((app, idx) => ({
6350
appData: app,
6451
metadata: validationResults[idx],
6552
}));
6653

54+
const groupId = await db.appGroup.create(orgId, groupName, false);
55+
// let groupId: number;
56+
// try {
57+
// groupId = await db.appGroup.create(orgId, groupName, false);
58+
// } catch (e) {
59+
// if (e instanceof ConflictError) {
60+
// throw new ValidationError(
61+
// "An app group already exists with the same name.",
62+
// );
63+
// }
64+
// throw e;
65+
// }
66+
6767
for (const { appData, metadata } of appsWithMetadata) {
6868
let { config, commitMessage } = metadata;
6969
let app: App;

0 commit comments

Comments
 (0)