Customers page: export, correct and erase personal data; automatic retention
Admin /customers finds a customer by name, email, phone or notes (orders and unpaid checkouts), exports everything stored as JSON, corrects details on every record, and erases them — anonymising orders (amounts, services and dates stay for the accounts) and deleting unpaid checkouts. A daily cron (and PocketBase start) deletes unpaid checkouts after N days and, when set, anonymises orders after M months, skipping orders with a booking ahead. A paid basket's copy of the details is cleared when its order is created. All writes are in pocketbase/pb_hooks/privacy (orders and baskets are superuser-only); migration 1793000000 makes orders.email optional and adds orders.anonymisedAt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
This commit is contained in:
parent
5828d65a00
commit
971efebcdb
13 changed files with 749 additions and 8 deletions
31
app-admin/src/lib/customers.ts
Normal file
31
app-admin/src/lib/customers.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Shapes returned by PocketBase's /api/privacy routes (pocketbase/pb_hooks/privacy/lib.js).
|
||||
|
||||
export type CustomerSummary = {
|
||||
email: string;
|
||||
name: string;
|
||||
phone: string;
|
||||
orders: number;
|
||||
/** Checkouts started but not paid for. */
|
||||
unpaid: number;
|
||||
lastSeen: string;
|
||||
};
|
||||
|
||||
export type CustomerDetails = { name?: string; email?: string; phone?: string; notes?: string };
|
||||
|
||||
/** Everything stored about one customer; also the GDPR export file. */
|
||||
export type CustomerData = {
|
||||
email: string;
|
||||
exportedAt: string;
|
||||
orders: {
|
||||
id: string;
|
||||
created: string;
|
||||
status: string;
|
||||
total: number;
|
||||
email: string;
|
||||
customerDetails: CustomerDetails;
|
||||
customerEmailSentAt: string;
|
||||
clientEmailSentAt: string;
|
||||
lines: { name: string; quantity: number; price: number; start: string }[];
|
||||
}[];
|
||||
unpaidBaskets: { id: string; updated: string; status: string; customerDetails: CustomerDetails }[];
|
||||
};
|
||||
24
app-admin/src/lib/server/customers.ts
Normal file
24
app-admin/src/lib/server/customers.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Customer personal data for the /customers page. All reads and writes go
|
||||
// through PocketBase's /api/privacy routes (orders and baskets are
|
||||
// superuser-only collections; the hook does the writes).
|
||||
|
||||
import type { createPocketBase } from '$lib/pb';
|
||||
import type { CustomerData, CustomerSummary } from '$lib/customers';
|
||||
|
||||
type Pb = ReturnType<typeof createPocketBase>;
|
||||
|
||||
export function searchCustomers(pb: Pb, q: string) {
|
||||
return pb.send<{ customers: CustomerSummary[]; truncated: boolean }>('/api/privacy/customers', { query: { q }, requestKey: null });
|
||||
}
|
||||
|
||||
export function loadCustomer(pb: Pb, email: string) {
|
||||
return pb.send<CustomerData>('/api/privacy/customer', { query: { email }, requestKey: null });
|
||||
}
|
||||
|
||||
export function updateCustomer(pb: Pb, body: { email: string; name?: string; newEmail?: string; phone?: string; clearNotes?: boolean }) {
|
||||
return pb.send<{ updated: number; email: string }>('/api/privacy/customer/update', { method: 'POST', body, requestKey: null });
|
||||
}
|
||||
|
||||
export function eraseCustomer(pb: Pb, email: string) {
|
||||
return pb.send<{ ordersAnonymised: number; basketsDeleted: number }>('/api/privacy/customer/erase', { method: 'POST', body: { email }, requestKey: null });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue