Bundles: keep parts from being deleted out from under them
Bundle parts are JSON, so deleting a service left bundles pointing at nothing (shown as "Item" in the shop). An onRecordDelete hook on items now refuses while a bundle contains it or a usable code still has sessions of it to book. A bundle with an inactive part is no longer sold or issued; the admin items list marks it "Not on sale" and shows how many codes are waiting on an inactive service. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
parent
c7e019131a
commit
338aef9e01
5 changed files with 109 additions and 13 deletions
|
|
@ -59,12 +59,28 @@ routerAdd('POST', '/api/shop/passes/update', (e) => {
|
|||
return e.json(200, { pass: shop.updatePass($app, e.requestInfo().body) });
|
||||
});
|
||||
|
||||
routerAdd('GET', '/api/shop/passes/waiting', (e) => {
|
||||
if (!e.auth) throw new UnauthorizedError('Sign in to see codes');
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, { waiting: shop.codesWaiting($app) });
|
||||
});
|
||||
|
||||
routerAdd('POST', '/api/shop/passes/issue', (e) => {
|
||||
if (!e.auth) throw new UnauthorizedError('Sign in to issue codes');
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
return e.json(200, { pass: shop.issuePass($app, e.requestInfo().body) });
|
||||
});
|
||||
|
||||
// Bundles hold their parts as JSON, so nothing else stops a service or
|
||||
// product from being deleted out from under a bundle or an unused code.
|
||||
// Runs for every delete (admin app, dashboard, API).
|
||||
onRecordDelete((e) => {
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
const blocker = shop.deleteBlocker(e.app, e.record);
|
||||
if (blocker) throw new BadRequestError(blocker, { item: new ValidationError('in_use', blocker) });
|
||||
e.next();
|
||||
}, 'items');
|
||||
|
||||
routerAdd('POST', '/api/shop/order-email-status', (e) => {
|
||||
const shop = require(`${__hooks}/shop/lib.js`);
|
||||
shop.recordEmailStatus($app, e.request.header.get('X-Internal-Secret'), e.requestInfo().body);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue