const db = require("../db.js"); var CryptoJS = require('crypto-js'); const CARDS_SEARCH_CRITERIA = { 'lt': 'card;', 'gt': 'card:' }; class CardsRepository { getByID(id) { return db.get('card:' + id); } getAll() { return db.read(CARDS_SEARCH_CRITERIA); } getCardsByUser(userid) { return db.search(['user', userid],CARDS_SEARCH_CRITERIA); } insert(id, data) { return db.put('card:' + id, data); } verify(data) { let { user } = data; if (!user) throw Error("This data are corrupted!"); return { user }; } } let cardsRepository = null; function getSingleton() { return cardsRepository = (cardsRepository === null ? new CardsRepository(): userRepository); } module.exports = getSingleton();