2018-04-02 05:38:24 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
2018-04-03 08:46:46 +08:00
|
|
|
const dateUtils = require('../services/date_utils');
|
2018-04-02 05:38:24 +08:00
|
|
|
|
2018-08-23 05:37:06 +08:00
|
|
|
/**
|
|
|
|
* ApiToken is an entity representing token used to authenticate against Trilium API from client applications. Currently used only by Trilium Sender.
|
|
|
|
*
|
|
|
|
* @param {string} apiTokenId - primary key
|
|
|
|
* @param {string} token
|
|
|
|
* @param {boolean} isDeleted - true if API token is deleted
|
|
|
|
* @param {string} dateCreated
|
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
2018-04-02 05:38:24 +08:00
|
|
|
class ApiToken extends Entity {
|
2018-08-17 05:00:04 +08:00
|
|
|
static get entityName() { return "api_tokens"; }
|
2018-04-02 05:38:24 +08:00
|
|
|
static get primaryKeyName() { return "apiTokenId"; }
|
2018-05-23 10:22:15 +08:00
|
|
|
static get hashedProperties() { return ["apiTokenId", "token", "dateCreated", "isDeleted"]; }
|
2018-04-02 05:38:24 +08:00
|
|
|
|
|
|
|
beforeSaving() {
|
|
|
|
if (!this.isDeleted) {
|
|
|
|
this.isDeleted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.dateCreated) {
|
2018-04-03 08:46:46 +08:00
|
|
|
this.dateCreated = dateUtils.nowDate();
|
2018-04-02 05:38:24 +08:00
|
|
|
}
|
2018-08-06 14:59:26 +08:00
|
|
|
|
|
|
|
super.beforeSaving();
|
2018-04-02 05:38:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ApiToken;
|