server-ts: Solve build errors after merge

This commit is contained in:
Elian Doran 2024-03-30 11:09:45 +02:00
parent db2b33704f
commit 08f0c01eef
No known key found for this signature in database
7 changed files with 55 additions and 20 deletions

View File

@ -13,6 +13,7 @@ import BEtapiToken = require('./entities/betapi_token');
import cls = require('../services/cls');
import entityConstructor = require('../becca/entity_constructor');
import { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow } from './entities/rows';
import AbstractBeccaEntity = require('./entities/abstract_becca_entity');
const beccaLoaded = new Promise<void>((res, rej) => {
sqlInit.dbReady.then(() => {
@ -89,7 +90,7 @@ eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({ entity
if (beccaEntity) {
beccaEntity.updateFromRow(entityRow);
} else {
beccaEntity = new EntityClass();
beccaEntity = new EntityClass() as AbstractBeccaEntity<AbstractBeccaEntity<any>>;
beccaEntity.updateFromRow(entityRow);
beccaEntity.init();
}

View File

@ -102,6 +102,10 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
abstract getPojo(): {};
abstract init(): void;
abstract updateFromRow(row: unknown): void;
get isDeleted(): boolean {
// TODO: Not sure why some entities don't implement it.
return false;

View File

@ -37,10 +37,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
noteId?: number;
attachmentId?: string;
/** either noteId or revisionId to which this attachment belongs */
ownerId: string;
role: string;
mime: string;
title: string;
ownerId!: string;
role!: string;
mime!: string;
title!: string;
type?: keyof typeof attachmentRoleToNoteTypeMapping;
position?: number;
blobId?: string;
@ -54,6 +54,11 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
constructor(row: AttachmentRow) {
super();
this.updateFromRow(row);
this.decrypt();
}
updateFromRow(row: AttachmentRow): void {
if (!row.ownerId?.trim()) {
throw new Error("'ownerId' must be given to initialize a Attachment entity");
} else if (!row.role?.trim()) {
@ -76,8 +81,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
this.utcDateModified = row.utcDateModified;
this.utcDateScheduledForErasureSince = row.utcDateScheduledForErasureSince;
this.contentLength = row.contentLength;
}
this.decrypt();
init(): void {
// Do nothing.
}
copy(): BAttachment {

View File

@ -1657,6 +1657,10 @@ class BNote extends AbstractBeccaEntity<BNote> {
position
});
if (!content) {
throw new Error("Attempted to save an attachment with no content.");
}
attachment.setContent(content, {forceSave: true});
return attachment;

View File

@ -32,6 +32,10 @@ class BOption extends AbstractBeccaEntity<BOption> {
this.utcDateModified = row.utcDateModified;
}
init(): void {
// Do nothing.
}
beforeSaving() {
super.beforeSaving();

View File

@ -12,18 +12,26 @@ class BRecentNote extends AbstractBeccaEntity<BRecentNote> {
static get entityName() { return "recent_notes"; }
static get primaryKeyName() { return "noteId"; }
noteId: string;
notePath: string;
utcDateCreated: string;
noteId!: string;
notePath!: string;
utcDateCreated!: string;
constructor(row: RecentNoteRow) {
super();
this.updateFromRow(row);
}
updateFromRow(row: RecentNoteRow): void {
this.noteId = row.noteId;
this.notePath = row.notePath;
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
}
init(): void {
// Do nothing.
}
getPojo() {
return {
noteId: this.noteId,

View File

@ -29,22 +29,30 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
"utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; }
revisionId?: string;
noteId: string;
type: string;
mime: string;
isProtected: boolean;
title: string;
noteId!: string;
type!: string;
mime!: string;
isProtected!: boolean;
title!: string;
blobId?: string;
dateLastEdited?: string;
dateCreated: string;
dateCreated!: string;
utcDateLastEdited?: string;
utcDateCreated: string;
utcDateCreated!: string;
contentLength?: number;
content?: string;
constructor(row: RevisionRow, titleDecrypted = false) {
super();
this.updateFromRow(row);
if (this.isProtected && !titleDecrypted) {
const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
this.title = decryptedTitle || "[protected]";
}
}
updateFromRow(row: RevisionRow) {
this.revisionId = row.revisionId;
this.noteId = row.noteId;
this.type = row.type;
@ -58,11 +66,10 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
this.utcDateCreated = row.utcDateCreated;
this.utcDateModified = row.utcDateModified;
this.contentLength = row.contentLength;
}
if (this.isProtected && !titleDecrypted) {
const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
this.title = decryptedTitle || "[protected]";
}
init() {
// Do nothing.
}
getNote() {