cards.js 722 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const db = require("../db.js");
  2. var CryptoJS = require('crypto-js');
  3. const CARDS_SEARCH_CRITERIA = {
  4. 'lt': 'card;',
  5. 'gt': 'card:'
  6. };
  7. class CardsRepository {
  8. getByID(id) {
  9. return db.get('card:' + id);
  10. }
  11. getAll() {
  12. return db.read(CARDS_SEARCH_CRITERIA);
  13. }
  14. getCardsByUser(userid) {
  15. return db.search(['user', userid],CARDS_SEARCH_CRITERIA);
  16. }
  17. insert(id, data) {
  18. return db.put('card:' + id, data);
  19. }
  20. verify(data) {
  21. let { user } = data;
  22. if (!user) throw Error("This data are corrupted!");
  23. return { user };
  24. }
  25. }
  26. let cardsRepository = null;
  27. function getSingleton() {
  28. return cardsRepository = (cardsRepository === null ? new CardsRepository(): userRepository);
  29. }
  30. module.exports = getSingleton();