Repository navigation
aryan/save data on phone - #40
Open
AryanNair-24 wants to merge 11 commits into
Open
AryanNair-24 wants to merge 11 commits into
AryanNair-24 wants to merge 11 commits into
Conversation
…created_at and updated_at fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Closes issue #33
Adds a local SQLite layer (expo-sqlite) so downloaded lists, unfinished visits and visits waiting to send survive closing the app or losing signal.
db.ts: one shared connection, versioned migrations (PRAGMA user_version), and tables for the catalogue, drafts and the visit queue. Every table is keyed byworker_id.catalogue.ts: save/load for programmes, form definitions, regions, villages, farms and supply items. Each list is replaced in one transaction, so a failed save keeps the previous list.drafts.ts: create, load, list, save and discard drafts, plus add/remove photo paths.uuidandrecorded_atare set once at creation and never rewritten.updated_atis bumped on every edit and used to order drafts.queue.ts:enqueueDraftvalidates the draft, freezes the request body, inserts the queued visit and its photos, and deletes the draft in one transaction. Repeated taps or reopening the app return the existing visit instead of queueing twice. Also adds queue reads and per-step status tracking (visit created, photo uploaded, photo registered, errors, attempts). A visit only becomessentonce creation is confirmed and every photo is registered.How to test it
cd frontend && npm installnpm test(all tests should pass)npx tsc --noEmit(no errors in the files above)getDb()and confirm the tables exist and data survives a force-quit.Checklist
Notes for the reviewer
workerId: string. I'm assumingString(user.id)from theUserSerializer.discardDraftandremoveDraftPhotoreturn.recorded_atis the visit start time, sent in the request body.visit_created_atmarks the creation step as confirmed.updated_atexists on drafts only.enqueueDraftaccepts a draft with no delivery rows, and fully blank rows are dropped rather than rejected. If a visit must have at least one delivery, that's one extra check required inenqueueDraft.sentas soon as its creation is confirmed, since there are no photos left to register.Project,RegionandSitecome from the shared types file.VillageandSupplyItemare defined incatalogue.tsbecause the shared file doesn't have them yet.sendingafter an app kill needs resetting toqueuedby the sender.