smaller refactorings continued

This commit is contained in:
azivner
2018-04-01 17:38:24 -04:00
parent 15d951b04e
commit 96dab5d51e
14 changed files with 122 additions and 109 deletions

25
src/entities/api_token.js Normal file
View File

@@ -0,0 +1,25 @@
"use strict";
const Entity = require('./entity');
const utils = require('../services/utils');
class ApiToken extends Entity {
static get tableName() { return "api_tokens"; }
static get primaryKeyName() { return "apiTokenId"; }
beforeSaving() {
if (!this.apiTokenId) {
this.apiTokenId = utils.newApiTokenId();
}
if (!this.isDeleted) {
this.isDeleted = false;
}
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}
}
}
module.exports = ApiToken;

View File

@@ -13,6 +13,14 @@ class Branch extends Entity {
}
beforeSaving() {
if (!this.branchId) {
this.branchId = utils.newBranchId();
}
if (!this.isDeleted) {
this.isDeleted = false;
}
this.dateModified = utils.nowDate()
}
}

View File

@@ -5,6 +5,7 @@ const NoteImage = require('../entities/note_image');
const Branch = require('../entities/branch');
const Label = require('../entities/label');
const RecentNote = require('../entities/recent_note');
const ApiToken = require('../entities/api_token');
const repository = require('../services/repository');
function createEntityFromRow(row) {
@@ -25,6 +26,9 @@ function createEntityFromRow(row) {
else if (row.branchId && row.notePath) {
entity = new RecentNote(row);
}
else if (row.apiTokenId) {
entity = new ApiToken(row);
}
else if (row.branchId) {
entity = new Branch(row);
}

View File

@@ -8,6 +8,14 @@ class Image extends Entity {
static get primaryKeyName() { return "imageId"; }
beforeSaving() {
if (!this.imageId) {
this.imageId = utils.newImageId();
}
if (!this.isDeleted) {
this.isDeleted = false;
}
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}

View File

@@ -131,6 +131,10 @@ class Note extends Entity {
}
beforeSaving() {
if (!this.noteId) {
this.noteId = utils.newNoteId();
}
if (this.isJson()) {
this.content = JSON.stringify(this.jsonContent, null, '\t');
}
@@ -139,6 +143,10 @@ class Note extends Entity {
protected_session.encryptNote(this);
}
if (!this.isDeleted) {
this.isDeleted = false;
}
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}

View File

@@ -17,6 +17,14 @@ class NoteImage extends Entity {
}
beforeSaving() {
if (!this.noteImageId) {
this.noteImageId = utils.newNoteImageId();
}
if (!this.isDeleted) {
this.isDeleted = false;
}
if (!this.dateCreated) {
this.dateCreated = utils.nowDate();
}

View File

@@ -2,6 +2,7 @@
const Entity = require('./entity');
const protected_session = require('../services/protected_session');
const utils = require('../services/utils');
const repository = require('../services/repository');
class NoteRevision extends Entity {
@@ -21,6 +22,10 @@ class NoteRevision extends Entity {
}
beforeSaving() {
if (!this.noteRevisionId) {
this.noteRevisionId = utils.newNoteRevisionId();
}
if (this.isProtected) {
protected_session.encryptNoteRevision(this);
}