const db = require("../db.js"); class DecksDal { getDecksByUser(userID){ return db.search(['user', userID]); } insertDeckByUser(userID, cards){ //TODO if 'userID' has all 'cards' continue, otherwise error return db.put('deck:' + userID, cards); } deleteDeckByUser(userID, deckID) { return db.del(deckID); } verify(data) { let { user } = data; if (!user) throw Error("You have to login before saving a deck!"); return { user }; } } let decksDal = null; function getSingleton() { return decksDal = (decksDal === null ? new DecksDal(): decksDal); } module.exports = getSingleton();