server-ts: Port betapi_token

This commit is contained in:
Elian Doran 2024-02-17 01:03:38 +02:00
parent 768aaf2d78
commit 2f15d79476
No known key found for this signature in database
3 changed files with 23 additions and 10 deletions

View File

@ -3,6 +3,7 @@ import NoteSet = require('../services/search/note_set');
import NotFoundError = require('../errors/not_found_error'); import NotFoundError = require('../errors/not_found_error');
import BOption = require('./entities/boption'); import BOption = require('./entities/boption');
import BNote = require('./entities/bnote'); import BNote = require('./entities/bnote');
import BEtapiToken = require('./entities/betapi_token');
/** /**
* Becca is a backend cache of all notes, branches, and attributes. * Becca is a backend cache of all notes, branches, and attributes.
@ -11,6 +12,7 @@ import BNote = require('./entities/bnote');
class Becca { class Becca {
notes!: Record<string, BNote>; notes!: Record<string, BNote>;
options!: Record<string, BOption>; options!: Record<string, BOption>;
etapiTokens!: Record<string, BEtapiToken>;
constructor() { constructor() {
this.reset(); this.reset();
@ -28,7 +30,6 @@ class Becca {
/** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */ /** @type {Object.<String, BAttribute[]>} Points from attribute type-name to list of attributes */
this.attributeIndex = {}; this.attributeIndex = {};
this.options = {}; this.options = {};
/** @type {Object.<String, BEtapiToken>} */
this.etapiTokens = {}; this.etapiTokens = {};
this.dirtyNoteSetCache(); this.dirtyNoteSetCache();

View File

@ -1,5 +1,7 @@
"use strict"; "use strict";
import { EtapiTokenRow } from "./rows";
const dateUtils = require('../../services/date_utils'); const dateUtils = require('../../services/date_utils');
const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js');
@ -19,7 +21,14 @@ class BEtapiToken extends AbstractBeccaEntity {
static get primaryKeyName() { return "etapiTokenId"; } static get primaryKeyName() { return "etapiTokenId"; }
static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; } static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; }
constructor(row) { etapiTokenId!: string;
name!: string;
tokenHash!: string;
utcDateCreated!: string;
utcDateModified!: string;
isDeleted!: boolean;
constructor(row: EtapiTokenRow) {
super(); super();
if (!row) { if (!row) {
@ -30,18 +39,12 @@ class BEtapiToken extends AbstractBeccaEntity {
this.init(); this.init();
} }
updateFromRow(row) { updateFromRow(row: EtapiTokenRow) {
/** @type {string} */
this.etapiTokenId = row.etapiTokenId; this.etapiTokenId = row.etapiTokenId;
/** @type {string} */
this.name = row.name; this.name = row.name;
/** @type {string} */
this.tokenHash = row.tokenHash; this.tokenHash = row.tokenHash;
/** @type {string} */
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
/** @type {string} */
this.utcDateModified = row.utcDateModified || this.utcDateCreated; this.utcDateModified = row.utcDateModified || this.utcDateCreated;
/** @type {boolean} */
this.isDeleted = !!row.isDeleted; this.isDeleted = !!row.isDeleted;
if (this.etapiTokenId) { if (this.etapiTokenId) {
@ -75,4 +78,4 @@ class BEtapiToken extends AbstractBeccaEntity {
} }
} }
module.exports = BEtapiToken; export = BEtapiToken;

View File

@ -42,4 +42,13 @@ export interface OptionRow {
value: string; value: string;
isSynced: boolean; isSynced: boolean;
utcDateModified: string; utcDateModified: string;
}
export interface EtapiTokenRow {
etapiTokenId: string;
name: string;
tokenHash: string;
utcDateCreated?: string;
utcDateModified?: string;
isDeleted: boolean;
} }