Refactor environment variable declarations, enhance image handling in item forms, and update asset references in SvelteKit project for improved functionality and performance.
This commit is contained in:
@@ -33,9 +33,11 @@ const actions = {
|
||||
const Has_Parent = parseBool(form.get("Has_Parent"));
|
||||
const Parent = form.get("Parent")?.trim() ?? "";
|
||||
const Stock = parseBool(form.get("Stock"));
|
||||
const imageFileCreate = form.get("Image");
|
||||
const hasImage = imageFileCreate && imageFileCreate.size > 0;
|
||||
if (!Item) return fail(400, { error: "Item name is required", form: "create" });
|
||||
try {
|
||||
await locals.pb.collection(COLLECTION).create({
|
||||
const body = {
|
||||
Item,
|
||||
SKU,
|
||||
Description,
|
||||
@@ -47,7 +49,9 @@ const actions = {
|
||||
Has_Parent: !!Has_Parent,
|
||||
Parent: Parent || null,
|
||||
Stock: !!Stock
|
||||
});
|
||||
};
|
||||
if (hasImage) body.Image = imageFileCreate;
|
||||
await locals.pb.collection(COLLECTION).create(body);
|
||||
} catch (e) {
|
||||
const message = e && typeof e === "object" && "message" in e ? String(e.message) : "Create failed";
|
||||
return fail(500, { error: message, form: "create" });
|
||||
@@ -69,9 +73,11 @@ const actions = {
|
||||
const Has_Parent = parseBool(form.get("Has_Parent"));
|
||||
const Parent = form.get("Parent")?.trim() ?? "";
|
||||
const Stock = parseBool(form.get("Stock"));
|
||||
const Image = form.get("Image");
|
||||
const imageFile = Image && Image.size > 0 ? Image : void 0;
|
||||
if (!Item) return fail(400, { error: "Item name is required", form: "update" });
|
||||
try {
|
||||
await locals.pb.collection(COLLECTION).update(id, {
|
||||
const body = {
|
||||
Item,
|
||||
SKU,
|
||||
Description,
|
||||
@@ -83,7 +89,9 @@ const actions = {
|
||||
Has_Parent: !!Has_Parent,
|
||||
Parent: Parent || null,
|
||||
Stock: !!Stock
|
||||
});
|
||||
};
|
||||
if (imageFile) body.Image = imageFile;
|
||||
await locals.pb.collection(COLLECTION).update(id, body);
|
||||
} catch (e) {
|
||||
const message = e && typeof e === "object" && "message" in e ? String(e.message) : "Update failed";
|
||||
return fail(500, { error: message, form: "update" });
|
||||
|
||||
Reference in New Issue
Block a user