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
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
/// Customer personal data (GDPR) — see privacy/lib.js. Every route is for
|
|
/// the signed-in admin only (`users` has no public sign-up).
|
|
|
|
routerAdd('GET', '/api/privacy/customers', (e) => {
|
|
const privacy = require(`${__hooks}/privacy/lib.js`);
|
|
privacy.requireAdmin(e);
|
|
return e.json(200, privacy.searchCustomers($app, e.request.url.query().get('q')));
|
|
});
|
|
|
|
routerAdd('GET', '/api/privacy/customer', (e) => {
|
|
const privacy = require(`${__hooks}/privacy/lib.js`);
|
|
privacy.requireAdmin(e);
|
|
return e.json(200, privacy.customerData($app, e.request.url.query().get('email')));
|
|
});
|
|
|
|
routerAdd('POST', '/api/privacy/customer/update', (e) => {
|
|
const privacy = require(`${__hooks}/privacy/lib.js`);
|
|
privacy.requireAdmin(e);
|
|
return e.json(200, privacy.updateCustomer($app, e.requestInfo().body));
|
|
});
|
|
|
|
routerAdd('POST', '/api/privacy/customer/erase', (e) => {
|
|
const privacy = require(`${__hooks}/privacy/lib.js`);
|
|
privacy.requireAdmin(e);
|
|
return e.json(200, privacy.eraseCustomer($app, e.requestInfo().body));
|
|
});
|
|
|
|
routerAdd('GET', '/api/privacy/settings', (e) => {
|
|
const privacy = require(`${__hooks}/privacy/lib.js`);
|
|
privacy.requireAdmin(e);
|
|
return e.json(200, privacy.settings($app));
|
|
});
|
|
|
|
// Delete unpaid baskets and anonymise old orders, per the `privacy` global.
|
|
cronAdd('privacyRetention', '15 3 * * *', () => {
|
|
require(`${__hooks}/privacy/lib.js`).applyRetention($app);
|
|
});
|
|
|
|
// Also once at startup, so a box that is down at 03:15 still catches up.
|
|
onBootstrap((e) => {
|
|
e.next();
|
|
try {
|
|
require(`${__hooks}/privacy/lib.js`).applyRetention($app);
|
|
} catch (err) {
|
|
console.error('[privacy] retention at startup failed:', err);
|
|
}
|
|
});
|