SRV-27 — Data imports — products, resellers, users, stock
Excel/CSV import jobs with templates, dry-run validation report, idempotent apply and error rows export.
| Field | Details |
|---|---|
| Task code | SRV-27 |
| Phase | P1 — V1 build & integration |
| Product scope | V1 |
| Status | Done (Mon 19 Oct 2026) |
| Start | Mon 19 Oct 2026 |
| Due | Mon 19 Oct 2026 |
| Responsible | Anis — Full-stack developer |
| Co-responsible | — |
| Effort | 0.5 person-day(s) planned · 3 from scratch · size XS |
| Area · app | Server · server |
| Depends on | SRV-11, SRV-14 |
| Unblocks | DSH-12, SRV-41 |
| Milestones | — |
Summary
Excel/CSV import jobs with templates, dry-run validation report, idempotent apply and error rows export.
Description
Go-live needs HOCO's existing products, resellers, users and stock loaded without hand entry (cahier §13.2; ADM-06, CAT-06), and catalog maintenance needs Excel imports afterwards. This task implements ImportJob for four types — products (with variants, the three customer-type prices, VAT, attributes and image URLs), resellers (with customer type, normalised phone and duplicate detection), users (staff and delegates with roles and zones) and stock (initial levels per warehouse posted as movements) — with downloadable XLSX templates, an upload through files (IMPORT_FILE), a dry-run validation report per row (errors and warnings), an idempotent apply keyed on natural keys (product reference + variant SKU, reseller phone, user phone or email, SKU + warehouse), and an error-rows export. Endpoints are admin.imports.create/get and admin.products.import. Out of scope: the import UI (BO-32 in DSH-04, BO-67 in DSH-12) and API sync with HOCO's stock system (V2).
Subtasks
| # | Subtask | Owner |
|---|---|---|
| 1 | Import framework: ImportJob lifecycle (QUEUED, RUNNING, SUCCEEDED, FAILED), worker processor, progress, IMPORT audit entry | Anis |
| 2 | XLSX templates per type with data-validation lists (brands, categories, customer types, wilayas, roles) and an instructions sheet | Anis |
| 3 | Row parser and validator per type reusing module Zod schemas; dry-run report with error and warning per row and column | Anis |
| 4 | Products import: create/update by reference + SKU, three prices with PriceChange entries, VAT, attributes validated against AttributeDefinition, image URLs fetched into storage | Anis |
| 5 | Resellers import: phone normalisation, duplicate detection against existing records, customer type, wilaya/commune codes, delegate assignment, source IMPORT | Anis |
| 6 | Users import: staff and delegates with roles and zones, password-setup link sent by SMS or email | Anis |
| 7 | Stock import: initial levels per SKU and warehouse posted as RECEIPT or ADJUSTMENT movements with reason « Import initial » | Anis |
| 8 | Idempotent apply (same file twice = no change) and error-rows XLSX export | Anis |
Deliverables
- apps/server/src/modules/integrations/imports/{framework.ts,templates/,products.ts,resellers.ts,users.ts,stock.ts,router.ts}
- packages/contracts/src/admin/imports.ts
- Template files served from /admin/imports/templates/{type}.xlsx
Acceptance criteria
- A dry run never writes business data and reports every invalid row with its column and message (ADM-06)
- Applying the same products file twice leaves the database unchanged the second time (CAT-06)
- A reseller row whose phone already exists is reported as a duplicate and updates nothing unless the update mode is chosen (CRM-03)
- A stock import creates one movement per row and the levels match the file (STK-04)
- A 5 000-row products file completes in under 5 minutes on staging
Requirements covered
| Requirement | Title | Release |
|---|---|---|
| ADM-06 | Initial imports: products, resellers, user accounts, stock | V1 |
| CAT-06 | Product import/export (Excel/CSV) with a validation report | V1 |
Screens
API surface
| Endpoint group | Operations |
|---|---|
| Administration, settings & audit | 22 |
| Catalog & pricing | 19 |
Test measures
- Fixture files with valid, invalid and duplicate rows per type; assertions on the report and on data
- Idempotency test applying the same file twice
- Dry run with a real HOCO export during LCH-01 preparation
Risks
- HOCO's spreadsheets do not match the templates — a mapping step in the wizard and an early sample file request after PRJ-03
KPI
- Delivered by Mon 19 Oct 2026 within 0.5 person-day(s).
- Every acceptance criterion above demonstrated before hand-off; linked requirements' acceptance criteria pass.
- Zero open critical defects, permission gaps or data-integrity regressions at sign-off.
Generated from content/plan/tasks.json by scripts/generate-team-tasks.mjs. Dates are computed by the scheduler (Sunday–Thursday weeks, holidays excluded) — change the plan, not this page.
SRV-25 — Analytics, reports & exports
KPI and chart queries with permission-aware filters, daily aggregates, the essential report catalogue and async PDF/XLSX/CSV exports.
SRV-41 — API refinements found while building the back-office
Close the contract and API gaps the back-office pages hit, so the screens work as their specs say instead of through workarounds.