Download mock-app/modules/a2r/rest.js from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.91 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/mock-app/modules/a2r/rest.js
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/mock-app/modules/a2r/rest.js
-
curl -L -o rest.js https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/mock-app/modules/a2r/rest.js
2.91 kB
| ; | |
| // A2R Fusion-style REST facade (MOCK; shapes ASSUMED/UNVERIFIED) + internal recipe API. Synthetic data only. | |
| const express = require('express'); | |
| const S = require('./store'); | |
| const { AppError } = require('../../core/errors'); | |
| const { wrap } = require('../../core/ui'); | |
| const ok = (role, a) => { if (!S.can(role, a)) throw new AppError(403, 'FORBIDDEN', `Persona ${role} is not authorized (${a}).`); }; | |
| const list = (items) => ({ items, count: items.length, hasMore: false }); | |
| const filt = (items, q) => { if (!q) return items; const conds = [...String(q).matchAll(/(\w+)\s*=\s*'([^']*)'/g)]; return items.filter((it) => conds.every(([, k, v]) => String(it[k] ?? '') === v)); }; | |
| const assetOut = (a) => ({ AssetId: a.id, AssetNumber: a.number, BookTypeCode: a.book, AssetCategory: a.category, Description: a.description, Cost: a.cost, Units: a.units, LifeInMonths: a.life, DepreciationMethod: a.method, | |
| DatePlacedInService: a.dpis, InvoiceNumber: a.invoiceNumber, Location: a.location, DepreciationReserve: a.reserve, | |
| depreciation: a.depreciation.map((d) => ({ PeriodName: d.period, DepreciationAmount: d.amount, ReserveAfter: d.reserveAfter })), | |
| journalEntries: S.list('sla').filter((e) => e.assetNumber === a.number).flatMap((e) => e.lines.map((l) => ({ EventType: e.type, Status: e.status, Side: l.side, AccountClass: l.accountClass, Account: l.account, Amount: l.amount }))) }); | |
| const SCHEMAS = { | |
| fixedAssets: [['AssetNumber', 'string'], ['BookTypeCode', 'string', true], ['AssetCategory', 'string', true], ['Cost', 'number', true], ['Units', 'number'], ['LifeInMonths', 'number'], ['DatePlacedInService', 'date']], | |
| assetBooks: [['BookTypeCode', 'string'], ['CurrentOpenPeriod', 'string'], ['LastClosedPeriod', 'string']], | |
| }; | |
| const fx = express.Router(); | |
| fx.get('/fixedAssets', wrap((req, role) => { ok(role, 'asset.view'); return list(filt(S.list('assets').filter((a) => S.bookOk(role, a.book)).map(assetOut), req.query.q)); })); | |
| fx.get('/assetBooks', wrap((req, role) => { ok(role, 'asset.view'); return list(filt(S.booksOf(role).map((b) => { const ps = S.periods(b); const closed = ps.filter((p) => p.status === 'Closed'); | |
| return { BookTypeCode: b, CurrentOpenPeriod: (ps.find((p) => p.status === 'Open') || {}).name || null, LastClosedPeriod: (closed[closed.length - 1] || {}).name || null }; }), req.query.q)); })); | |
| const api = express.Router(); | |
| api.get('/refs', wrap(() => ({ ...S.refs(), corpBook: S.CORP, otherBook: S.OTHER, accounts: S.ACCOUNTS }))); | |
| // Recipe helpers (DR-A2R-SRC-001): list source lines, and prepare one (same rules as the Prepare Source Lines page). | |
| api.get('/source-lines', wrap((req, role) => ({ items: S.list('sourceLines').filter((x) => S.bookOk(role, x.book)) }))); | |
| api.patch('/source-lines/:id', wrap((req, role) => S.prepareSourceLine(role, req.params.id, req.body || {}))); | |
| module.exports = { fx, api, SCHEMAS }; | |