Admin: stop a member campaign on every rail (pause + archive, releases unspent budget) and grant refunds as purchased-grade credits (Shift AI closed)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-04 07:06:42 -05:00
parent 3f758cdd38
commit ca7a579990
+16 -1
View File
@@ -2254,7 +2254,10 @@ const server = http.createServer(async (req, res) => {
// the grant. A correction that reads "granted by admin" explains nothing; one that
// names itself is the difference between a refund and a mystery (Marty, 2026-09-17).
const why = String(b.note || '').trim().slice(0, 120) || 'Credits granted by admin';
await ads.addEarned(e, n, { log: { kind: 'grant', note: why } });
// purchased: true returns PURCHASED credits (a refund of money the member paid) at purchase grade, so they keep their
// money value; without it the grant is ordinary earned credits (2026-10-04, the Shift AI refunds)
if (b.purchased === true) await ads.addEarned(e, n, { purchased: true, log: { kind: 'credit', note: why } });
else await ads.addEarned(e, n, { log: { kind: 'grant', note: why } });
console.log('admin credits', e, n, String(b.note || '').slice(0, 100));
}
return json(res, 200, await adminMember.view(e));
@@ -3954,6 +3957,18 @@ const server = http.createServer(async (req, res) => {
console.log('fraud exception ' + (b.remove ? 'removed' : 'added') + ': ' + String(b.email || '').replace(/^(.).*(@.*)$/, '$1***$2'));
return json(res, 200, r);
}
// stop a member's campaign for good (2026-10-04, Marty: Shift AI closed, stop its ads): pause it on every rail, then archive it.
// Reserved budget is computed from active/paused campaigns, so archiving releases the unspent remainder to the member at
// once; flat up-front buys (visit packs) are refunded separately through /api/admin/member grantCredits.
if (p === '/api/admin/campaign/stop' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const c = await ads.campaignById(Number(b.id)); if (!c) return json(res, 404, { error: 'No such campaign.' });
const owner = c.owner || c.ownerEmail || c.owner_email;
if (c.status === 'active') { const r = await ads.setStatus(owner, c.id, 'paused'); if (r && r.error) return json(res, 400, r); }
const a = (c.status === 'archived') ? { ok: true, already: true, freed: 0 } : await ads.archive(owner, c.id);
console.log('admin stop campaign', c.id, owner, String(b.reason || '').slice(0, 80), JSON.stringify({ freed: a.freed }));
return json(res, a.error ? 400 : 200, Object.assign({ id: c.id, owner }, a));
}
if (p === '/api/admin/campaigns' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
return json(res, 200, { campaigns: await ads.adminList(), rates: ads.rates(), bannerSizes: ads.bannerSizes(), houseOwner: ads.HOUSE_OWNER });