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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,22 +29,30 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
"utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; } "utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; }
revisionId?: string; revisionId?: string;
noteId: string; noteId!: string;
type: string; type!: string;
mime: string; mime!: string;
isProtected: boolean; isProtected!: boolean;
title: string; title!: string;
blobId?: string; blobId?: string;
dateLastEdited?: string; dateLastEdited?: string;
dateCreated: string; dateCreated!: string;
utcDateLastEdited?: string; utcDateLastEdited?: string;
utcDateCreated: string; utcDateCreated!: string;
contentLength?: number; contentLength?: number;
content?: string; content?: string;
constructor(row: RevisionRow, titleDecrypted = false) { constructor(row: RevisionRow, titleDecrypted = false) {
super(); 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.revisionId = row.revisionId;
this.noteId = row.noteId; this.noteId = row.noteId;
this.type = row.type; this.type = row.type;
@ -58,11 +66,10 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
this.utcDateCreated = row.utcDateCreated; this.utcDateCreated = row.utcDateCreated;
this.utcDateModified = row.utcDateModified; this.utcDateModified = row.utcDateModified;
this.contentLength = row.contentLength; 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() { getNote() {