Skip to content

Commit 36daf85

Browse files
committed
feat(#9835): createDoc function for PouchDB
Signed-off-by: Apoorva Pendse <[email protected]>
1 parent 7c48e94 commit 36daf85

File tree

1 file changed

+16
-0
lines changed
  • shared-libs/cht-datasource/src/local/libs

1 file changed

+16
-0
lines changed

shared-libs/cht-datasource/src/local/libs/doc.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,19 @@ export const fetchAndFilterUuids = (
175175
limit
176176
);
177177
};
178+
179+
/** @internal */
180+
const createDoc = async(db: PouchDB.Database, data:Record<string, unknown>) : Promise<Doc> => {
181+
const {id, ok} = await db.post(data);
182+
if (!ok) {
183+
throw new Error('Error creating document.');
184+
}
185+
const createdDoc = (db as PouchDB.Database<Doc>)
186+
.get(id)
187+
.then(doc => {
188+
return doc;
189+
}).catch(() => {
190+
throw new Error('Failed to fetch created document.');
191+
});
192+
return createdDoc;
193+
};

0 commit comments

Comments
 (0)