Skip to content

feat(collection): undo imports, save views, guard edits, and attach insurance PDFs - #654

Merged
gogorichie merged 6 commits into
mainfrom
feat/inventory-views-import-undo-documents
Nov 20, 2026
Merged

gogorichie merged 6 commits into
mainfrom
feat/inventory-views-import-undo-documents

Conversation

@gogorichie

@gogorichie gogorichie commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Includes the reporting changes from #651 and targets main so the repository’s CI and Docker smoke checks run. The four additions in this PR are listed below.

  • Both CSV import screens link to dated import history with filenames and row counts. Preview undo and preserve edited records or firearms with related documents, photos, or logs. Undo rechecks eligibility inside a transaction. Tracking begins with new imports.
  • Both inventories can save named searches, filters, and sorts under the signed-in account.
  • Firearm and ammo forms offer Keep editing and Discard changes on in-app links. Browser navigation uses the browser’s unsaved-changes prompt.
  • Attach receipt and appraisal PDFs to a firearm and choose individual files for a downloadable, self-contained HTML insurance report. The files travel inside the report and can be saved offline.

Includes a SQLite migration and integration tests for import undo, document inclusion, authenticated download, and saved views.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T15:15:03.023225Z cdf5ef5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gogorichie
gogorichie changed the base branch from feat/collection-reporting-and-history to main November 20, 2026 15:03

Copy link
Copy Markdown
Member Author

📝 Documentation Updated

I reviewed the changes in this PR and drafted documentation updates in #655, which targets this branch. Merge #655 to add the docs here.

  • README.md: new user-facing features (receipt and appraisal PDFs, import history and undo, saved views, the unsaved-changes guard, the downloadable insurance report with embedded PDFs). It also says that app.db now holds the attached PDFs, and adds a privacy note that the downloaded report is an unprotected HTML file.
  • docs/architecture.md: the new collection feature, repository, views and migration 013_collection_tools.sql (directory tree plus a schema table). Adds a "Collection tools" section covering routes, undo rules and the CSRF-via-header upload, and describes the packet=1 streamed report.

Security notes in the docs: PDFs are stored as BLOBs in app.db, so backups include them. Validation only checks the %PDF- magic bytes; files are always served as attachments with no-store. The downloaded report bundles serials, locations and values when those are selected.

No documentation changes were needed for: tests/integration/firearms.integration.test.js (tests only), src/public/js/firearm-import.js (only adds the file-name header, covered in the architecture doc) and the small view wiring changes, which are covered by the feature descriptions above.

Suggestions (not done): wiki/Operations.md (backup) and wiki/Security.md should get matching notes. docs/architecture.md still has no ammo feature section, which was missing before this PR.

This comment was generated automatically by the Claude Documentation Routine.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f35274c1be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

);
CREATE INDEX idx_batches_owner ON import_batches(user_id, kind, id);
ALTER TABLE firearms ADD COLUMN import_batch_id INTEGER REFERENCES import_batches(id);
ALTER TABLE ammo_inventory ADD COLUMN import_batch_id INTEGER REFERENCES import_batches(id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the CSV round-trip test for import batch metadata

Adding import_batch_id to ammunition rows breaks the existing CSV round-trip test in tests/unit/ammo.import.test.js:113–114: service.list() returns this column, but the test's strip helper does not exclude it, so otherwise identical inventories compare unequal because separate imports have different batch IDs. Running npm test -- --silent confirmed this failure (45 suites passed, one failed). Update the comparison to exclude internal import metadata while retaining the inventory-content assertion.

Useful? React with 👍 / 👎.

Comment on lines +9 to +12
router.get(root + '/imports', (req, res) => {
const batches = service.batches(req.session.user.id, kind);
res.render('collection/imports', { kind, batches, entry: null });
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Introduce a controller for the collection HTTP handlers

The new collection feature implements its HTTP handlers directly in the route-registration module, including rendering, response status selection, and redirects, rather than providing a controller. This bypasses the controller/service/repository pattern explicitly required for all new features by the root AGENTS.md. Extract these handlers into a collection controller and keep this module responsible for route and middleware registration.

AGENTS.md reference: AGENTS.md:L59-L59

Useful? React with 👍 / 👎.

Comment on lines +13 to +17
function members(userId, kind, id) {
const related = kind === 'firearms' ? ['firearm_photos', 'range_sessions', 'maintenance_logs', 'firearm_documents']
.map(table => `EXISTS(SELECT 1 FROM ${table} WHERE firearm_id=r.id)`).join(' OR ') : '0';
return db.prepare(`SELECT m.record_id, m.label,
CASE WHEN r.id IS NULL THEN 'Absent' WHEN m.edited OR ${related} THEN 'Keep' ELSE 'Remove' END AS action

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move import-undo policy into the collection service

The repository now owns the business policy for which imported records must be preserved, assigns the user-facing Keep/Remove actions, and orchestrates undo based on those decisions; the collection service merely re-exports this implementation. The root AGENTS.md explicitly requires repositories to remain SQL-only and contain no business logic. Move eligibility and undo policy into the service, exposing repository operations that preserve the existing transactional recheck.

AGENTS.md reference: AGENTS.md:L49-L49

Useful? React with 👍 / 👎.

<a href="/<%= kind %>/import">Back to CSV import</a>
<h2>Import history</h2>
<% if (!entry) { %>
<% if (!batches.length) { %><p>No tracked imports yet. History starts with imports made after this update.</p><% } %>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update user documentation for the new collection tools

This commit adds import undo, saved views, edit guards, and downloadable insurance reports with supporting PDFs, but leaves README.md, docs/index.html, and the website screenshots unchanged. In particular, users are not told that import history only starts after this update or that undo preserves edited records. The root AGENTS.md requires README updates for changes to app usage and website/screenshot updates for user-facing features; document these workflows and limitations alongside the implementation.

AGENTS.md reference: AGENTS.md:L156-L157

Useful? React with 👍 / 👎.

@gogorichie
gogorichie merged commit 56111ce into main Nov 20, 2026
7 of 8 checks passed
gogorichie added a commit that referenced this pull request Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is included in version 2.10.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant