From 08f0c01eefbba5ff8658edaeeede04df2fd76f0a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 30 Mar 2024 11:09:45 +0200 Subject: [PATCH] server-ts: Solve build errors after merge --- src/becca/becca_loader.ts | 3 ++- src/becca/entities/abstract_becca_entity.ts | 4 +++ src/becca/entities/battachment.ts | 17 ++++++++---- src/becca/entities/bnote.ts | 4 +++ src/becca/entities/boption.ts | 4 +++ src/becca/entities/brecent_note.ts | 14 +++++++--- src/becca/entities/brevision.ts | 29 +++++++++++++-------- 7 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/becca/becca_loader.ts b/src/becca/becca_loader.ts index e13641ba9..507828ad5 100644 --- a/src/becca/becca_loader.ts +++ b/src/becca/becca_loader.ts @@ -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((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>; beccaEntity.updateFromRow(entityRow); beccaEntity.init(); } diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 8b30d2b64..874fecd99 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -102,6 +102,10 @@ abstract class AbstractBeccaEntity> { 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; diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index c048c9ed6..f70cff9e2 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -37,10 +37,10 @@ class BAttachment extends AbstractBeccaEntity { 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 { 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 { this.utcDateModified = row.utcDateModified; this.utcDateScheduledForErasureSince = row.utcDateScheduledForErasureSince; this.contentLength = row.contentLength; + } - this.decrypt(); + init(): void { + // Do nothing. } copy(): BAttachment { diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 17f7315d1..cc251ffd0 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -1657,6 +1657,10 @@ class BNote extends AbstractBeccaEntity { position }); + if (!content) { + throw new Error("Attempted to save an attachment with no content."); + } + attachment.setContent(content, {forceSave: true}); return attachment; diff --git a/src/becca/entities/boption.ts b/src/becca/entities/boption.ts index 48abee024..b06a23431 100644 --- a/src/becca/entities/boption.ts +++ b/src/becca/entities/boption.ts @@ -32,6 +32,10 @@ class BOption extends AbstractBeccaEntity { this.utcDateModified = row.utcDateModified; } + init(): void { + // Do nothing. + } + beforeSaving() { super.beforeSaving(); diff --git a/src/becca/entities/brecent_note.ts b/src/becca/entities/brecent_note.ts index 0771a5e00..338dae3c5 100644 --- a/src/becca/entities/brecent_note.ts +++ b/src/becca/entities/brecent_note.ts @@ -12,18 +12,26 @@ class BRecentNote extends AbstractBeccaEntity { 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, diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index ba7cc00ba..48d131f0a 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -29,22 +29,30 @@ class BRevision extends AbstractBeccaEntity { "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 { 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() {