Skip to content

Commit

Permalink
Remove erroneous try-catch for ValiError
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Feb 4, 2025
1 parent c8552e8 commit 90de719
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,30 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async edit({ cookies, request }) {
async edit({ request }) {
const form = await superValidate(request, valibot(editSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
// return { ok: true, form };
try {
const {
id,
name,
buildEngineAccessToken,
buildEngineURL,
logoURL,
owner,
publicByDefault,
websiteURL,
stores
} = form.data;
await DatabaseWrites.organizations.update({
where: {
Id: id
},
data: {
Name: name,
BuildEngineApiAccessToken: buildEngineAccessToken,
BuildEngineUrl: buildEngineURL,
LogoUrl: logoURL,
OwnerId: owner,
PublicByDefault: publicByDefault,
WebsiteUrl: websiteURL
}
});
await DatabaseWrites.organizationStores.updateOrganizationStores(
id,
stores.filter((s) => s.enabled).map((s) => s.storeId)
);
await DatabaseWrites.organizations.update({
where: {
Id: form.data.id
},
data: {
Name: form.data.name,
BuildEngineApiAccessToken: form.data.buildEngineAccessToken,
BuildEngineUrl: form.data.buildEngineURL,
LogoUrl: form.data.logoURL,
OwnerId: form.data.owner,
PublicByDefault: form.data.publicByDefault,
WebsiteUrl: form.data.websiteURL
}
});
await DatabaseWrites.organizationStores.updateOrganizationStores(
form.data.id,
form.data.stores.filter((s) => s.enabled).map((s) => s.storeId)
);

return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,18 @@ export const actions = {
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const {
buildEngineAccessToken,
buildEngineURL,
logoURL,
name,
owner,
publicByDefault,
useDefaultBuildEngine,
websiteURL
} = form.data;
await DatabaseWrites.organizations.create({
data: {
Name: name,
BuildEngineApiAccessToken: buildEngineAccessToken,
BuildEngineUrl: buildEngineURL,
LogoUrl: logoURL,
OwnerId: owner,
PublicByDefault: publicByDefault,
UseDefaultBuildEngine: useDefaultBuildEngine,
WebsiteUrl: websiteURL
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.organizations.create({
data: {
Name: form.data.name,
BuildEngineApiAccessToken: form.data.buildEngineAccessToken,
BuildEngineUrl: form.data.buildEngineURL,
LogoUrl: form.data.logoURL,
OwnerId: form.data.owner,
PublicByDefault: form.data.publicByDefault,
UseDefaultBuildEngine: form.data.useDefaultBuildEngine,
WebsiteUrl: form.data.websiteURL
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -49,48 +49,25 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async edit({ cookies, request }) {
async edit({ request }) {
const form = await superValidate(request, valibot(editSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const {
id,
name,
applicationType,
workflow,
rebuildWorkflow,
republishWorkflow,
description,
properties
} = form.data;
await DatabaseWrites.productDefinitions.update({
where: {
Id: id
},
data: {
TypeId: applicationType,
Name: name,
WorkflowId: workflow,
RebuildWorkflowId: rebuildWorkflow,
RepublishWorkflowId: republishWorkflow,
Description: description,
Properties: properties
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
// const Id = data.get('id');
// const name = data.get('name');
// const applicationType = data.get('applicationType');
// const workflow = data.get('workflow');
// const rebuildWorkflow = data.get('rebuildWorkflow');
// const republishWorkflow = data.get('republishWorkflow');
// const description = data.get('description');
// const properties = data.get('properties');
await DatabaseWrites.productDefinitions.update({
where: {
Id: form.data.id
},
data: {
TypeId: form.data.applicationType,
Name: form.data.name,
WorkflowId: form.data.workflow,
RebuildWorkflowId: form.data.rebuildWorkflow,
RepublishWorkflowId: form.data.republishWorkflow,
Description: form.data.description,
Properties: form.data.properties
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,17 @@ export const actions = {
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const {
name,
applicationType,
workflow,
rebuildWorkflow,
republishWorkflow,
description,
properties
} = form.data;
await DatabaseWrites.productDefinitions.create({
data: {
Name: name,
TypeId: applicationType,
WorkflowId: workflow,
RebuildWorkflowId: rebuildWorkflow,
RepublishWorkflowId: republishWorkflow,
Description: description,
Properties: properties
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.productDefinitions.create({
data: {
Name: form.data.name,
TypeId: form.data.applicationType,
WorkflowId: form.data.workflow,
RebuildWorkflowId: form.data.rebuildWorkflow,
RepublishWorkflowId: form.data.republishWorkflow,
Description: form.data.description,
Properties: form.data.properties
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,20 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async edit({ cookies, request }) {
async edit({ request }) {
const form = await superValidate(request, valibot(editSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const { id, name, description } = form.data;
await DatabaseWrites.storeTypes.update({
where: {
Id: id
},
data: {
Name: name,
Description: description
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.storeTypes.update({
where: {
Id: form.data.id
},
data: {
Name: form.data.name,
Description: form.data.description
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async new({ cookies, request }) {
async new({ request }) {
const form = await superValidate(request, valibot(createSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const { name, description } = form.data;
await DatabaseWrites.storeTypes.create({
data: {
Name: name,
Description: description
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.storeTypes.create({
data: {
Name: form.data.name,
Description: form.data.description
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,21 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async edit({ cookies, request }) {
async edit({ request }) {
const form = await superValidate(request, valibot(editSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const { id, name, description, storeType } = form.data;
await DatabaseWrites.stores.update({
where: {
Id: id
},
data: {
Name: name,
StoreTypeId: storeType,
Description: description
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.stores.update({
where: {
Id: form.data.id
},
data: {
Name: form.data.name,
StoreTypeId: form.data.storeType,
Description: form.data.description
}
});
return { ok: true, form };
}
} satisfies Actions;
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ export const load = (async ({ url }) => {
}) satisfies PageServerLoad;

export const actions = {
async new({ cookies, request }) {
async new({ request }) {
const form = await superValidate(request, valibot(createSchema));
if (!form.valid) {
return fail(400, { form, ok: false, errors: form.errors });
}
try {
const { name, description, storeType } = form.data;
await DatabaseWrites.stores.create({
data: {
Name: name,
Description: description,
StoreTypeId: storeType
}
});
return { ok: true, form };
} catch (e) {
if (e instanceof v.ValiError) return { form, ok: false, errors: e.issues };
throw e;
}
await DatabaseWrites.stores.create({
data: {
Name: form.data.name,
Description: form.data.description,
StoreTypeId: form.data.storeType
}
});
return { ok: true, form };
}
} satisfies Actions;
Loading

0 comments on commit 90de719

Please sign in to comment.