general ui patches
This commit is contained in:
@@ -55,6 +55,48 @@ async function updateCollection(id: string, col: any): Promise<void> {
|
||||
console.log(` ✓ Updated collection: ${col.name || id}`);
|
||||
}
|
||||
|
||||
async function createRecord(collection: string, data: any): Promise<void> {
|
||||
const t = await auth();
|
||||
const res = await fetch(`${PB_ENDPOINT}/api/collections/${collection}/records`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${t}` },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const d = await res.json();
|
||||
throw new Error(`Create record ${collection} failed: ${JSON.stringify(d)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Seed two default seasons (Holidays, Term time) per family so the family-admin
|
||||
// season picker always has options. Idempotent by name.
|
||||
async function ensureDefaultSeasons(): Promise<void> {
|
||||
const famsCol = await getCollection("fams");
|
||||
if (!famsCol) return;
|
||||
const t = await auth();
|
||||
const famsRes = await fetch(`${PB_ENDPOINT}/api/collections/fams/records?perPage=200`, {
|
||||
headers: { Authorization: `Bearer ${t}` },
|
||||
});
|
||||
const fams = (await famsRes.json()).items || [];
|
||||
const defaults = [
|
||||
{ name: "Holidays", color: "#f59e0b", active: true },
|
||||
{ name: "Term time", color: "#3b82f6", active: true },
|
||||
];
|
||||
for (const fam of fams) {
|
||||
const sRes = await fetch(
|
||||
`${PB_ENDPOINT}/api/collections/seasons/records?filter=(famId='${fam.id}')&fields=name&perPage=200`,
|
||||
{ headers: { Authorization: `Bearer ${t}` } }
|
||||
);
|
||||
const have = new Set(((await sRes.json()).items || []).map((s: any) => s.name));
|
||||
for (const d of defaults) {
|
||||
if (!have.has(d.name)) {
|
||||
await createRecord("seasons", { famId: fam.id, ...d });
|
||||
console.log(` ✓ Seeded season ${d.name} for fam ${fam.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the custom fields + rules the app relies on to PB's native `users`
|
||||
// auth collection (created automatically on first serve). Children live here as
|
||||
// role='child'; username is a password-auth identity so the server can
|
||||
@@ -332,6 +374,7 @@ export async function migrate(): Promise<void> {
|
||||
await ensureAssignedChoreFields();
|
||||
await ensureAccessCodes();
|
||||
await ensurePlatform();
|
||||
await ensureDefaultSeasons();
|
||||
console.log("[migrate] Done");
|
||||
}
|
||||
|
||||
@@ -353,6 +396,12 @@ async function ensureAssignedChoreFields(): Promise<void> {
|
||||
typeField.values = [...typeField.values, "emoji"];
|
||||
changed = true;
|
||||
}
|
||||
// Direct todos (created by a parent, not from a template) have no templateId.
|
||||
const tplField = col.fields.find((f: any) => f.name === "templateId");
|
||||
if (tplField && tplField.required) {
|
||||
tplField.required = false;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
await updateCollection(col.id, { ...col, fields: [...col.fields] });
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ export async function toggle(pb: any, famId: string, memberId: string, body: { a
|
||||
value: Number(chore.value),
|
||||
rewardType: 'cash',
|
||||
status: 'unclaimed',
|
||||
claimable: 'payday',
|
||||
date
|
||||
});
|
||||
rewardId = reward.id;
|
||||
|
||||
Reference in New Issue
Block a user