Skip to content

Commit 90de719

Browse files
committed
Remove erroneous try-catch for ValiError
1 parent c8552e8 commit 90de719

File tree

17 files changed

+289
-468
lines changed

17 files changed

+289
-468
lines changed

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/organizations/edit/+page.server.ts

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,30 @@ export const load = (async ({ url }) => {
6565
}) satisfies PageServerLoad;
6666

6767
export const actions = {
68-
async edit({ cookies, request }) {
68+
async edit({ request }) {
6969
const form = await superValidate(request, valibot(editSchema));
7070
if (!form.valid) {
7171
return fail(400, { form, ok: false, errors: form.errors });
7272
}
73-
// return { ok: true, form };
74-
try {
75-
const {
76-
id,
77-
name,
78-
buildEngineAccessToken,
79-
buildEngineURL,
80-
logoURL,
81-
owner,
82-
publicByDefault,
83-
websiteURL,
84-
stores
85-
} = form.data;
86-
await DatabaseWrites.organizations.update({
87-
where: {
88-
Id: id
89-
},
90-
data: {
91-
Name: name,
92-
BuildEngineApiAccessToken: buildEngineAccessToken,
93-
BuildEngineUrl: buildEngineURL,
94-
LogoUrl: logoURL,
95-
OwnerId: owner,
96-
PublicByDefault: publicByDefault,
97-
WebsiteUrl: websiteURL
98-
}
99-
});
100-
await DatabaseWrites.organizationStores.updateOrganizationStores(
101-
id,
102-
stores.filter((s) => s.enabled).map((s) => s.storeId)
103-
);
73+
await DatabaseWrites.organizations.update({
74+
where: {
75+
Id: form.data.id
76+
},
77+
data: {
78+
Name: form.data.name,
79+
BuildEngineApiAccessToken: form.data.buildEngineAccessToken,
80+
BuildEngineUrl: form.data.buildEngineURL,
81+
LogoUrl: form.data.logoURL,
82+
OwnerId: form.data.owner,
83+
PublicByDefault: form.data.publicByDefault,
84+
WebsiteUrl: form.data.websiteURL
85+
}
86+
});
87+
await DatabaseWrites.organizationStores.updateOrganizationStores(
88+
form.data.id,
89+
form.data.stores.filter((s) => s.enabled).map((s) => s.storeId)
90+
);
10491

105-
return { ok: true, form };
106-
} catch (e) {
107-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
108-
throw e;
109-
}
92+
return { ok: true, form };
11093
}
11194
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/organizations/new/+page.server.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,18 @@ export const actions = {
3131
if (!form.valid) {
3232
return fail(400, { form, ok: false, errors: form.errors });
3333
}
34-
try {
35-
const {
36-
buildEngineAccessToken,
37-
buildEngineURL,
38-
logoURL,
39-
name,
40-
owner,
41-
publicByDefault,
42-
useDefaultBuildEngine,
43-
websiteURL
44-
} = form.data;
45-
await DatabaseWrites.organizations.create({
46-
data: {
47-
Name: name,
48-
BuildEngineApiAccessToken: buildEngineAccessToken,
49-
BuildEngineUrl: buildEngineURL,
50-
LogoUrl: logoURL,
51-
OwnerId: owner,
52-
PublicByDefault: publicByDefault,
53-
UseDefaultBuildEngine: useDefaultBuildEngine,
54-
WebsiteUrl: websiteURL
55-
}
56-
});
57-
return { ok: true, form };
58-
} catch (e) {
59-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
60-
throw e;
61-
}
34+
await DatabaseWrites.organizations.create({
35+
data: {
36+
Name: form.data.name,
37+
BuildEngineApiAccessToken: form.data.buildEngineAccessToken,
38+
BuildEngineUrl: form.data.buildEngineURL,
39+
LogoUrl: form.data.logoURL,
40+
OwnerId: form.data.owner,
41+
PublicByDefault: form.data.publicByDefault,
42+
UseDefaultBuildEngine: form.data.useDefaultBuildEngine,
43+
WebsiteUrl: form.data.websiteURL
44+
}
45+
});
46+
return { ok: true, form };
6247
}
6348
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/product-definitions/edit/+page.server.ts

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,25 @@ export const load = (async ({ url }) => {
4949
}) satisfies PageServerLoad;
5050

5151
export const actions = {
52-
async edit({ cookies, request }) {
52+
async edit({ request }) {
5353
const form = await superValidate(request, valibot(editSchema));
5454
if (!form.valid) {
5555
return fail(400, { form, ok: false, errors: form.errors });
5656
}
57-
try {
58-
const {
59-
id,
60-
name,
61-
applicationType,
62-
workflow,
63-
rebuildWorkflow,
64-
republishWorkflow,
65-
description,
66-
properties
67-
} = form.data;
68-
await DatabaseWrites.productDefinitions.update({
69-
where: {
70-
Id: id
71-
},
72-
data: {
73-
TypeId: applicationType,
74-
Name: name,
75-
WorkflowId: workflow,
76-
RebuildWorkflowId: rebuildWorkflow,
77-
RepublishWorkflowId: republishWorkflow,
78-
Description: description,
79-
Properties: properties
80-
}
81-
});
82-
return { ok: true, form };
83-
} catch (e) {
84-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
85-
throw e;
86-
}
87-
// const Id = data.get('id');
88-
// const name = data.get('name');
89-
// const applicationType = data.get('applicationType');
90-
// const workflow = data.get('workflow');
91-
// const rebuildWorkflow = data.get('rebuildWorkflow');
92-
// const republishWorkflow = data.get('republishWorkflow');
93-
// const description = data.get('description');
94-
// const properties = data.get('properties');
57+
await DatabaseWrites.productDefinitions.update({
58+
where: {
59+
Id: form.data.id
60+
},
61+
data: {
62+
TypeId: form.data.applicationType,
63+
Name: form.data.name,
64+
WorkflowId: form.data.workflow,
65+
RebuildWorkflowId: form.data.rebuildWorkflow,
66+
RepublishWorkflowId: form.data.republishWorkflow,
67+
Description: form.data.description,
68+
Properties: form.data.properties
69+
}
70+
});
71+
return { ok: true, form };
9572
}
9673
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/product-definitions/new/+page.server.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,17 @@ export const actions = {
3030
if (!form.valid) {
3131
return fail(400, { form, ok: false, errors: form.errors });
3232
}
33-
try {
34-
const {
35-
name,
36-
applicationType,
37-
workflow,
38-
rebuildWorkflow,
39-
republishWorkflow,
40-
description,
41-
properties
42-
} = form.data;
43-
await DatabaseWrites.productDefinitions.create({
44-
data: {
45-
Name: name,
46-
TypeId: applicationType,
47-
WorkflowId: workflow,
48-
RebuildWorkflowId: rebuildWorkflow,
49-
RepublishWorkflowId: republishWorkflow,
50-
Description: description,
51-
Properties: properties
52-
}
53-
});
54-
return { ok: true, form };
55-
} catch (e) {
56-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
57-
throw e;
58-
}
33+
await DatabaseWrites.productDefinitions.create({
34+
data: {
35+
Name: form.data.name,
36+
TypeId: form.data.applicationType,
37+
WorkflowId: form.data.workflow,
38+
RebuildWorkflowId: form.data.rebuildWorkflow,
39+
RepublishWorkflowId: form.data.republishWorkflow,
40+
Description: form.data.description,
41+
Properties: form.data.properties
42+
}
43+
});
44+
return { ok: true, form };
5945
}
6046
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/store-types/edit/+page.server.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,20 @@ export const load = (async ({ url }) => {
3535
}) satisfies PageServerLoad;
3636

3737
export const actions = {
38-
async edit({ cookies, request }) {
38+
async edit({ request }) {
3939
const form = await superValidate(request, valibot(editSchema));
4040
if (!form.valid) {
4141
return fail(400, { form, ok: false, errors: form.errors });
4242
}
43-
try {
44-
const { id, name, description } = form.data;
45-
await DatabaseWrites.storeTypes.update({
46-
where: {
47-
Id: id
48-
},
49-
data: {
50-
Name: name,
51-
Description: description
52-
}
53-
});
54-
return { ok: true, form };
55-
} catch (e) {
56-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
57-
throw e;
58-
}
43+
await DatabaseWrites.storeTypes.update({
44+
where: {
45+
Id: form.data.id
46+
},
47+
data: {
48+
Name: form.data.name,
49+
Description: form.data.description
50+
}
51+
});
52+
return { ok: true, form };
5953
}
6054
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/store-types/new/+page.server.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,17 @@ export const load = (async ({ url }) => {
1616
}) satisfies PageServerLoad;
1717

1818
export const actions = {
19-
async new({ cookies, request }) {
19+
async new({ request }) {
2020
const form = await superValidate(request, valibot(createSchema));
2121
if (!form.valid) {
2222
return fail(400, { form, ok: false, errors: form.errors });
2323
}
24-
try {
25-
const { name, description } = form.data;
26-
await DatabaseWrites.storeTypes.create({
27-
data: {
28-
Name: name,
29-
Description: description
30-
}
31-
});
32-
return { ok: true, form };
33-
} catch (e) {
34-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
35-
throw e;
36-
}
24+
await DatabaseWrites.storeTypes.create({
25+
data: {
26+
Name: form.data.name,
27+
Description: form.data.description
28+
}
29+
});
30+
return { ok: true, form };
3731
}
3832
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/stores/edit/+page.server.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,21 @@ export const load = (async ({ url }) => {
3838
}) satisfies PageServerLoad;
3939

4040
export const actions = {
41-
async edit({ cookies, request }) {
41+
async edit({ request }) {
4242
const form = await superValidate(request, valibot(editSchema));
4343
if (!form.valid) {
4444
return fail(400, { form, ok: false, errors: form.errors });
4545
}
46-
try {
47-
const { id, name, description, storeType } = form.data;
48-
await DatabaseWrites.stores.update({
49-
where: {
50-
Id: id
51-
},
52-
data: {
53-
Name: name,
54-
StoreTypeId: storeType,
55-
Description: description
56-
}
57-
});
58-
return { ok: true, form };
59-
} catch (e) {
60-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
61-
throw e;
62-
}
46+
await DatabaseWrites.stores.update({
47+
where: {
48+
Id: form.data.id
49+
},
50+
data: {
51+
Name: form.data.name,
52+
StoreTypeId: form.data.storeType,
53+
Description: form.data.description
54+
}
55+
});
56+
return { ok: true, form };
6357
}
6458
} satisfies Actions;

source/SIL.AppBuilder.Portal/src/routes/(authenticated)/admin/settings/stores/new/+page.server.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,18 @@ export const load = (async ({ url }) => {
2020
}) satisfies PageServerLoad;
2121

2222
export const actions = {
23-
async new({ cookies, request }) {
23+
async new({ request }) {
2424
const form = await superValidate(request, valibot(createSchema));
2525
if (!form.valid) {
2626
return fail(400, { form, ok: false, errors: form.errors });
2727
}
28-
try {
29-
const { name, description, storeType } = form.data;
30-
await DatabaseWrites.stores.create({
31-
data: {
32-
Name: name,
33-
Description: description,
34-
StoreTypeId: storeType
35-
}
36-
});
37-
return { ok: true, form };
38-
} catch (e) {
39-
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
40-
throw e;
41-
}
28+
await DatabaseWrites.stores.create({
29+
data: {
30+
Name: form.data.name,
31+
Description: form.data.description,
32+
StoreTypeId: form.data.storeType
33+
}
34+
});
35+
return { ok: true, form };
4236
}
4337
} satisfies Actions;

0 commit comments

Comments
 (0)