access.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const DatabaseModel = require("./DatabaseModel.js").DatabaseModel;
  2. const TYPE = {
  3. unknown: 0,
  4. ldapAccount: 1,
  5. email: 2,
  6. link: 3
  7. };
  8. const ACCESS_TO = {
  9. unknown: 0,
  10. item: 1,
  11. tag: 2,
  12. meta: 3
  13. };
  14. function AccessModel() {
  15. DatabaseModel.call(this);
  16. this.id = null;
  17. this.type = TYPE.unknown;
  18. this.typeData = "";
  19. this.accessTo = ACCESS_TO.unknown;
  20. this.accessToData = "";
  21. }
  22. AccessModel.prototype = Object.create(DatabaseModel.prototype);
  23. AccessModel.prototype.getTableName = function() {
  24. return "access";
  25. }
  26. AccessModel.prototype.createOrUpdateBase = async function(dbHelper) {
  27. await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'access' (
  28. id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  29. type TINYINT NOT NULL,
  30. typeData STRING NOT NULL,
  31. accessTo TINYINT NOT NULL,
  32. accessToData STRING NOT NULL
  33. )`);
  34. }
  35. AccessModel.prototype.describe = function() {
  36. return {
  37. "id": this.id,
  38. "type": this.type,
  39. "typeData": this.typeData,
  40. "accessTo": this.accessTo,
  41. "accessToData": this.accessToData
  42. };
  43. }
  44. AccessModel.prototype.versionColumn = function() { return "loginDateTime"; }
  45. AccessModel.prototype.fromDb = function(dbObj) {
  46. this.id = dbObj["sessionId"];
  47. this.type = dbObj["type"];
  48. this.typeData = dbObj["typeData"];
  49. this.accessTo = dbObj["accessTo"];
  50. this.accessToData = dbObj["accessToData"];
  51. }
  52. module.exports.AccessModel = AccessModel;