mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Fix most type errors in becca
This commit is contained in:
parent
26388ad3b6
commit
2f96dc2d9d
@ -88,11 +88,17 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
|||||||
return this.getPojo();
|
return this.getPojo();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract hasStringContent(): boolean;
|
hasStringContent(): boolean {
|
||||||
|
// FIXME: Not sure why some entities don't implement it.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
abstract getPojo(): {};
|
abstract getPojo(): {};
|
||||||
|
|
||||||
abstract get isDeleted(): boolean;
|
get isDeleted(): boolean {
|
||||||
|
// FIXME: Not sure why some entities don't implement it.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves entity - executes SQL, but doesn't commit the transaction on its own
|
* Saves entity - executes SQL, but doesn't commit the transaction on its own
|
||||||
|
@ -36,7 +36,7 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
|
|||||||
noteId?: number;
|
noteId?: number;
|
||||||
attachmentId?: string;
|
attachmentId?: string;
|
||||||
/** either noteId or revisionId to which this attachment belongs */
|
/** either noteId or revisionId to which this attachment belongs */
|
||||||
ownerId?: string;
|
ownerId: string;
|
||||||
role: string;
|
role: string;
|
||||||
mime: string;
|
mime: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { BlobRow } from "./rows";
|
import { BlobRow } from "./rows";
|
||||||
|
|
||||||
|
// FIXME: Why this does not extend the abstract becca?
|
||||||
class BBlob {
|
class BBlob {
|
||||||
static get entityName() { return "blobs"; }
|
static get entityName() { return "blobs"; }
|
||||||
static get primaryKeyName() { return "blobId"; }
|
static get primaryKeyName() { return "blobId"; }
|
||||||
|
@ -180,7 +180,9 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const childBranch of note.getChildBranches()) {
|
for (const childBranch of note.getChildBranches()) {
|
||||||
childBranch.deleteBranch(deleteId, taskContext);
|
if (childBranch) {
|
||||||
|
childBranch.deleteBranch(deleteId, taskContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// first delete children and then parent - this will show up better in recent changes
|
// first delete children and then parent - this will show up better in recent changes
|
||||||
@ -220,11 +222,17 @@ class BBranch extends AbstractBeccaEntity<BBranch> {
|
|||||||
if (this.notePosition === undefined || this.notePosition === null) {
|
if (this.notePosition === undefined || this.notePosition === null) {
|
||||||
let maxNotePos = 0;
|
let maxNotePos = 0;
|
||||||
|
|
||||||
for (const childBranch of this.parentNote.getChildBranches()) {
|
if (this.parentNote) {
|
||||||
if (maxNotePos < childBranch.notePosition
|
for (const childBranch of this.parentNote.getChildBranches()) {
|
||||||
&& childBranch.noteId !== '_hidden' // hidden has a very large notePosition to always stay last
|
if (!childBranch) {
|
||||||
) {
|
continue;
|
||||||
maxNotePos = childBranch.notePosition;
|
}
|
||||||
|
|
||||||
|
if (maxNotePos < childBranch.notePosition
|
||||||
|
&& childBranch.noteId !== '_hidden' // hidden has a very large notePosition to always stay last
|
||||||
|
) {
|
||||||
|
maxNotePos = childBranch.notePosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class BEtapiToken extends AbstractBeccaEntity<BEtapiToken> {
|
|||||||
etapiTokenId!: string;
|
etapiTokenId!: string;
|
||||||
name!: string;
|
name!: string;
|
||||||
tokenHash!: string;
|
tokenHash!: string;
|
||||||
isDeleted!: boolean;
|
private _isDeleted!: boolean;
|
||||||
|
|
||||||
constructor(row: EtapiTokenRow) {
|
constructor(row: EtapiTokenRow) {
|
||||||
super();
|
super();
|
||||||
@ -35,13 +35,17 @@ class BEtapiToken extends AbstractBeccaEntity<BEtapiToken> {
|
|||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isDeleted() {
|
||||||
|
return this._isDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
updateFromRow(row: EtapiTokenRow) {
|
updateFromRow(row: EtapiTokenRow) {
|
||||||
this.etapiTokenId = row.etapiTokenId;
|
this.etapiTokenId = row.etapiTokenId;
|
||||||
this.name = row.name;
|
this.name = row.name;
|
||||||
this.tokenHash = row.tokenHash;
|
this.tokenHash = row.tokenHash;
|
||||||
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
|
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
|
||||||
this.utcDateModified = row.utcDateModified || this.utcDateCreated;
|
this.utcDateModified = row.utcDateModified || this.utcDateCreated;
|
||||||
this.isDeleted = !!row.isDeleted;
|
this._isDeleted = !!row.isDeleted;
|
||||||
|
|
||||||
if (this.etapiTokenId) {
|
if (this.etapiTokenId) {
|
||||||
this.becca.etapiTokens[this.etapiTokenId] = this;
|
this.becca.etapiTokens[this.etapiTokenId] = this;
|
||||||
|
@ -203,8 +203,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
return this.children && this.children.length > 0;
|
return this.children && this.children.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {BBranch[]} */
|
getChildBranches(): (BBranch | null)[] {
|
||||||
getChildBranches() {
|
|
||||||
return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
|
return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,7 +756,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
|
|
||||||
this.parents = this.parentBranches
|
this.parents = this.parentBranches
|
||||||
.map(branch => branch.parentNote)
|
.map(branch => branch.parentNote)
|
||||||
.filter(note => !!note);
|
.filter(note => !!note) as BNote[];
|
||||||
}
|
}
|
||||||
|
|
||||||
sortChildren() {
|
sortChildren() {
|
||||||
@ -771,7 +770,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId);
|
const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId);
|
||||||
const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId);
|
const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId);
|
||||||
|
|
||||||
return (aBranch?.notePosition - bBranch?.notePosition) || 0;
|
return ((aBranch?.notePosition || 0) - (bBranch?.notePosition || 0)) || 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -900,7 +899,7 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
const {searchResultNoteIds} = searchService.searchFromNote(this);
|
const {searchResultNoteIds} = searchService.searchFromNote(this);
|
||||||
|
|
||||||
const becca = this.becca;
|
const becca = this.becca;
|
||||||
return searchResultNoteIds
|
return (searchResultNoteIds as string[]) // FIXME: remove cast once search is converted
|
||||||
.map(resultNoteId => becca.notes[resultNoteId])
|
.map(resultNoteId => becca.notes[resultNoteId])
|
||||||
.filter(note => !!note);
|
.filter(note => !!note);
|
||||||
}
|
}
|
||||||
@ -1445,9 +1444,9 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
cloneTo(parentNoteId: string) {
|
cloneTo(parentNoteId: string) {
|
||||||
const cloningService = require('../../services/cloning');
|
const cloningService = require('../../services/cloning');
|
||||||
|
|
||||||
const branch = this.becca.getNote(parentNoteId).getParentBranches()[0];
|
const branch = this.becca.getNote(parentNoteId)?.getParentBranches()[0];
|
||||||
|
|
||||||
return cloningService.cloneNoteToBranch(this.noteId, branch.branchId);
|
return cloningService.cloneNoteToBranch(this.noteId, branch?.branchId);
|
||||||
}
|
}
|
||||||
|
|
||||||
isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) {
|
isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) {
|
||||||
@ -1603,6 +1602,11 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
|||||||
|
|
||||||
for (const noteAttachment of this.getAttachments()) {
|
for (const noteAttachment of this.getAttachments()) {
|
||||||
const revisionAttachment = noteAttachment.copy();
|
const revisionAttachment = noteAttachment.copy();
|
||||||
|
|
||||||
|
if (!revision.revisionId) {
|
||||||
|
throw new Error("Revision ID is missing.");
|
||||||
|
}
|
||||||
|
|
||||||
revisionAttachment.ownerId = revision.revisionId;
|
revisionAttachment.ownerId = revision.revisionId;
|
||||||
revisionAttachment.setContent(noteAttachment.getContent(), { forceSave: true });
|
revisionAttachment.setContent(noteAttachment.getContent(), { forceSave: true });
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user