decksDal.js 677 B

123456789101112131415161718192021222324252627282930
  1. const db = require("../db.js");
  2. class DecksDal {
  3. getDecksByUser(userID){
  4. return db.search(['user', userID]);
  5. }
  6. insertDeckByUser(userID, cards){
  7. //TODO if 'userID' has all 'cards' continue, otherwise error
  8. return db.put('deck:' + userID, cards);
  9. }
  10. deleteDeckByUser(userID, deckID) {
  11. return db.del(deckID);
  12. }
  13. verify(data) {
  14. let { user } = data;
  15. if (!user) throw Error("You have to login before saving a deck!");
  16. return { user };
  17. }
  18. }
  19. let decksDal = null;
  20. function getSingleton() {
  21. return decksDal = (decksDal === null ? new DecksDal(): decksDal);
  22. }
  23. module.exports = getSingleton();