Files
Stackq/build/server/chunks/10-SJ35hfdn.js
T
eewing f6d0c065a4
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m31s
PWA
2026-02-18 11:45:07 -06:00

94 lines
4.1 KiB
JavaScript

import { f as fail, r as redirect, e as error } from './index-B2LGyy1l.js';
const COLLECTION = "Stackq_Items";
function parseNum(val) {
if (val === "" || val === null || val === void 0) return void 0;
const n = Number(val);
return Number.isFinite(n) ? n : void 0;
}
function parseBool(val) {
return val === "on" || val === "true" || val === true;
}
const load = async ({ params, locals }) => {
const id = params.id;
if (!id) throw error(404, "Item not found");
try {
const item = await locals.pb.collection(COLLECTION).getOne(id, { expand: "Parent" });
const list = await locals.pb.collection(COLLECTION).getFullList({ sort: "-created", expand: "Parent" }).catch(() => []);
const itemsForParent = list.map((i) => ({ id: i.id, Item: i.Item, SKU: i.SKU }));
return { item, itemsForParent };
} catch {
throw error(404, "Item not found");
}
};
const actions = {
update: async ({ request, locals, params }) => {
const id = params.id;
if (!id) return fail(400, { error: "Missing id", form: "update" });
const form = await request.formData();
const Item = form.get("Item")?.trim() ?? "";
const SKU = form.get("SKU")?.trim() ?? "";
const Description = form.get("Description")?.trim() ?? "";
const UOM = form.get("UOM")?.trim() ?? "";
const Cost = parseNum(form.get("Cost"));
const Vendor = form.get("Vendor")?.trim() ?? "";
const Catagory = form.get("Catagory")?.trim() ?? "";
const Sub_Catagory = form.get("Sub_Catagory")?.trim() ?? "";
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 {
const body = {
Item,
SKU,
Description,
UOM: UOM || void 0,
Cost: Cost ?? 0,
Vendor,
Catagory: Catagory || void 0,
Sub_Catagory: Sub_Catagory || void 0,
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" });
}
return { success: true };
},
delete: async ({ locals, params }) => {
const id = params.id;
if (!id) return fail(400, { error: "Missing id", form: "delete" });
try {
await locals.pb.collection(COLLECTION).delete(id);
} catch (e) {
const message = e && typeof e === "object" && "message" in e ? String(e.message) : "Delete failed";
return fail(500, { error: message, form: "delete" });
}
throw redirect(303, "/items");
}
};
var _page_server_ts = /*#__PURE__*/Object.freeze({
__proto__: null,
actions: actions,
load: load
});
const index = 10;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-BsXYacKi.js')).default;
const server_id = "src/routes/items/[id]/+page.server.ts";
const imports = ["_app/immutable/nodes/10.Bk0Y3XDZ.js","_app/immutable/chunks/Bzak7iHL.js","_app/immutable/chunks/BH97ETpZ.js","_app/immutable/chunks/Qgf5A_kA.js","_app/immutable/chunks/BD8q7RHQ.js","_app/immutable/chunks/UvStrNyM.js","_app/immutable/chunks/BR6tTwie.js","_app/immutable/chunks/Cf_fsnlT.js","_app/immutable/chunks/CgtTdn_a.js","_app/immutable/chunks/CCY2d7sc.js","_app/immutable/chunks/mylYChEY.js","_app/immutable/chunks/CeetFYTo.js","_app/immutable/chunks/iYSIr-5j.js","_app/immutable/chunks/Dw-PWoyz.js","_app/immutable/chunks/Bysmuwvg.js","_app/immutable/chunks/BkOB8zes.js","_app/immutable/chunks/BzfwckE1.js","_app/immutable/chunks/CBjBL7Hz.js","_app/immutable/chunks/Cr7vHN1I.js","_app/immutable/chunks/C3TONo7J.js","_app/immutable/chunks/D4nn9Y_6.js"];
const stylesheets = [];
const fonts = [];
export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
//# sourceMappingURL=10-SJ35hfdn.js.map