apiKey.js 980 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const DatabaseModel = require("./DatabaseModel.js").DatabaseModel;
  2. function ApiKeyModel(privId, ipAddress) {
  3. this.created = new Date();
  4. this.ipAddress = ipAddress;
  5. this.apiKey = privId;
  6. }
  7. Object.setPrototypeOf(ApiKeyModel.prototype, DatabaseModel.prototype);
  8. ApiKeyModel.prototype.getTableName = function() {
  9. return "apiKey";
  10. }
  11. ApiKeyModel.prototype.createOrUpdateBase = async function(dbHelper) {
  12. await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'apiKey' (
  13. created datetime not null,
  14. apiKey string,
  15. ipAddress string
  16. )`);
  17. }
  18. ApiKeyModel.prototype.describe = function() {
  19. return {
  20. "ipAddress": this.ipAddress,
  21. "created": this.created.getTime(),
  22. "apiKey": this.apiKey
  23. };
  24. }
  25. ApiKeyModel.prototype.fromDb = function(dbObj) {
  26. this.created = new Date(dbObj['created']);
  27. this.ipAddress = dbObj['ipAddress'];
  28. this.apiKey = dbObj['apiKey'];
  29. }
  30. module.exports.ApiKeyModel = ApiKeyModel;