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
|
|
@ -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