Admin: bundles under Services & products, Vouchers & codes page
Bundles are edited with their parts (service at a length, or product, × count), price and validity. /passes lists codes with used/held/left and each part's share of the price; codes can be voided, reactivated, given a new expiry, or issued without a purchase. Orders show codes bought and bookings paid with a code; the customer page lists codes and erasure covers them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
parent
e824f16e31
commit
df840b7fd7
14 changed files with 543 additions and 27 deletions
|
|
@ -28,7 +28,8 @@
|
|||
const typeFilterLabels: Record<string, string> = {
|
||||
all: 'All',
|
||||
item: 'Products',
|
||||
item_with_time: 'Services'
|
||||
item_with_time: 'Services',
|
||||
bundle: 'Bundles'
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
@ -48,7 +49,7 @@
|
|||
|
||||
<SegmentedControl
|
||||
label="Item type"
|
||||
options={['all', 'item', 'item_with_time']}
|
||||
options={['all', 'item', 'item_with_time', 'bundle']}
|
||||
value={block.data.itemTypeFilter || 'all'}
|
||||
onChange={(v) => updateData({ itemTypeFilter: v as ShopBlockData['itemTypeFilter'] })}
|
||||
formatLabel={(v) => typeFilterLabels[String(v)] || String(v)}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ export const privacyTemplateHtml = `<h2>Privacy policy</h2>
|
|||
<h3>How long we keep it</h3>
|
||||
<ul>
|
||||
<li>Details entered at checkout without completing payment: deleted after [30] days.</li>
|
||||
<li>Gift vouchers and bundles: the code is kept until it expires; your email and any recipient name and message you added are removed together with your order details.</li>
|
||||
<li>Orders: your contact details are removed [after N months / when you ask]; the order record without them is kept for [N] years as required for our accounts.</li>
|
||||
<li>Server logs (including IP addresses): [a few] days.</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -28,4 +28,6 @@ export type CustomerData = {
|
|||
lines: { name: string; quantity: number; price: number; start: string }[];
|
||||
}[];
|
||||
unpaidBaskets: { id: string; updated: string; status: string; customerDetails: CustomerDetails }[];
|
||||
/** Bundle/voucher codes bought with this email, and who they're for. */
|
||||
codes: { code: string; name: string; created: string; expiresAt: string; status: string; recipientName: string; message: string }[];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ export function updateCustomer(pb: Pb, body: { email: string; name?: string; new
|
|||
}
|
||||
|
||||
export function eraseCustomer(pb: Pb, email: string) {
|
||||
return pb.send<{ ordersAnonymised: number; basketsDeleted: number }>('/api/privacy/customer/erase', { method: 'POST', body: { email }, requestKey: null });
|
||||
return pb.send<{ ordersAnonymised: number; basketsDeleted: number; passesAnonymised: number }>('/api/privacy/customer/erase', { method: 'POST', body: { email }, requestKey: null });
|
||||
}
|
||||
|
|
|
|||
32
app-admin/src/lib/server/passes.ts
Normal file
32
app-admin/src/lib/server/passes.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Bundle/voucher codes for the admin. Codes are commerce data: they are
|
||||
// only written by the shop hooks in PocketBase (/api/shop/passes*, signed-in
|
||||
// admins only), which also count what each code has left.
|
||||
|
||||
import { ClientResponseError } from 'pocketbase';
|
||||
import type { createPocketBase } from '$lib/pb';
|
||||
import type { PassSummary } from '$lib/types';
|
||||
|
||||
type Pb = ReturnType<typeof createPocketBase>;
|
||||
|
||||
/** A code as the admin list shows it: the summary plus who bought it and when. */
|
||||
export type AdminPass = PassSummary & { email: string; order: string; created: string; anonymisedAt: string };
|
||||
|
||||
export async function listPasses(pb: Pb, q: string) {
|
||||
const { passes } = await pb.send<{ passes: AdminPass[] }>('/api/shop/passes', { query: { q }, requestKey: null });
|
||||
return passes;
|
||||
}
|
||||
|
||||
export function updatePass(pb: Pb, body: { id: string; status?: 'active' | 'void'; expiresAt?: string }) {
|
||||
return pb.send<{ pass: PassSummary }>('/api/shop/passes/update', { method: 'POST', body, requestKey: null });
|
||||
}
|
||||
|
||||
export function issuePass(pb: Pb, body: { itemId: string; email: string; recipientName: string; message: string; months: string }) {
|
||||
return pb.send<{ pass: PassSummary }>('/api/shop/passes/issue', { method: 'POST', body, requestKey: null });
|
||||
}
|
||||
|
||||
/** The hook's own message (e.g. "Choose a bundle"), or `fallback`. */
|
||||
export function hookError(e: unknown, fallback: string) {
|
||||
if (e instanceof ClientResponseError && e.status >= 400 && e.status < 500 && e.response?.message) return String(e.response.message);
|
||||
console.error(`[passes] ${fallback}`, e);
|
||||
return fallback;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue