Skip to content

Commit

Permalink
Merge pull request #221 from talentedunicorn/fix/support-docs-with-mi…
Browse files Browse the repository at this point in the history
…ssing-updated

Fix errors with documents missing updated field
  • Loading branch information
talentedunicorn authored Feb 18, 2024
2 parents b4c7d97 + 51e4308 commit 2ff2a91
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ const remove = async (id: string, rev: string) => {
};

const getTodos = async () => {
const todos = (await db.allDocs({ include_docs: true, descending: true })).rows.map((t) => t.doc);
return todos as PouchDB.Core.ExistingDocument<PouchDB.Core.AllDocsMeta & Todo>[];
const todos = (await db.allDocs({ include_docs: true, descending: true })).rows.map((t) => {
const doc = t.doc as Todo;
return { ...doc, updated: doc?.updated ?? doc?._id };
});
return todos;
};

const bulkInsert = async (todos: Todo[]) => {
Expand Down

0 comments on commit 2ff2a91

Please sign in to comment.