mega-plant/scripts/setup-asset-qr.mjs
David 8f3a74cf6e Job cards oil path, Fuel tab diesel-only, Mechanic role, Plant Register QR column
- Job cards scanner: oil QR books litres + vehicle (no odo/photo), bundled onto the
  vehicle's job card (open job now, or the next job started the same day)
- Fuel tab is diesel only; /api/clock/oil-out added
- Users: Full / Clock-in user / Mechanic; mechanics see only Fuel + Job cards
- Plant Register: QR code column (double-click to set), kept across re-seeds and
  used when matching scans

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-22 13:44:01 +02:00

16 lines
998 B
JavaScript

// Add `qr_code` to `assets` (idempotent): the text printed in the QR sticker on a vehicle,
// typed into the Plant Register. Empty = the sticker just carries the register code.
// Usage: node scripts/setup-asset-qr.mjs
import PocketBase from "pocketbase";
import { readFileSync } from "node:fs";
for (const l of readFileSync(new URL("../.env.local", import.meta.url), "utf8").split("\n")) {
const i = l.indexOf("="); if (i > 0 && !l.trim().startsWith("#")) process.env[l.slice(0, i).trim()] = l.slice(i + 1).trim();
}
const pb = new PocketBase(process.env.NEXT_PUBLIC_PB_URL);
await pb.collection("_superusers").authWithPassword(process.env.PB_ADMIN, process.env.PB_PASS);
const assets = await pb.collections.getOne("assets");
if (assets.fields.some((f) => f.name === "qr_code")) console.log(" · assets.qr_code already present");
else {
await pb.collections.update(assets.id, { fields: [...assets.fields, { name: "qr_code", type: "text" }] });
console.log(" ✓ added assets.qr_code");
}