|
@@ -0,0 +1,42 @@
|
|
|
+const db = require("../db.js");
|
|
|
+var CryptoJS = require('crypto-js');
|
|
|
+
|
|
|
+
|
|
|
+class CardsRepository {
|
|
|
+ getByID(id) {
|
|
|
+ return db.get('card:' + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ getAllCards() {
|
|
|
+ const results = [];
|
|
|
+ return new Promise((res,rej) => {
|
|
|
+ db.createReadStream({
|
|
|
+ 'lt': 'card;',
|
|
|
+ 'gt': 'card:'
|
|
|
+ })
|
|
|
+ .on('data', function (data) {
|
|
|
+ console.log(data);
|
|
|
+ results.push(data);
|
|
|
+ })
|
|
|
+ .on('error', function (err) {
|
|
|
+ rej(err);
|
|
|
+ })
|
|
|
+ .on('close', function () {
|
|
|
+ res(results);
|
|
|
+ })
|
|
|
+ .on('end', function () {
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ insert(id, data) {
|
|
|
+ return db.put('card:' + id, data);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+let cardsRepository = null;
|
|
|
+function getSingleton() {
|
|
|
+ return cardsRepository = (cardsRepository === null ? new CardsRepository(): userRepository);
|
|
|
+}
|
|
|
+module.exports = getSingleton();
|