From c7f741040ab1bf81d85f1368b3fb8d72f8b44f74 Mon Sep 17 00:00:00 2001 From: SteffenGorenflo Date: Tue, 9 Jun 2015 14:25:59 +0200 Subject: [PATCH] #35 use promises and #38 decorate errors with boom --- src/util/util.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/util/util.ts b/src/util/util.ts index 47106bc..605b30f 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -174,6 +174,12 @@ class Util { }); }; + /** + * Same function as getObjectOf but with a returned promise + * @param keyValue + * @param list + * @returns {any} + */ retrieveSingleValue = (keyValue:any, list:string) => { return new Promise((resolve, reject) => { @@ -191,6 +197,25 @@ class Util { }) }; + /** + * Query a design document (list) with the given key and returns a promise. + * @param keyValue + * @param list + * @returns {any} + */ + retrieveAllValues = (keyValue:any, list:string) => { + return new Promise((resolve, reject) => { + + this.db.list(list, {key: keyValue}, (err, data) => { + + if (err) { + return reject(this.boom.wrap(err)); + } + resolve(data); + }); + }) + }; + /** * Create document with Timestamp. *