From f7347ef47cd2cd5f52a8bb682b899e6694b752a9 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 5 Dec 2023 19:16:29 +0300 Subject: [PATCH] changes to work with new noteSettings format --- src/domain/service/noteSettings.ts | 2 ++ .../storage/postgres/orm/sequelize/noteSettings.ts | 11 +++++++++++ src/tests/utils/insert-data.ts | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/domain/service/noteSettings.ts b/src/domain/service/noteSettings.ts index 5da46018..7ca79c75 100644 --- a/src/domain/service/noteSettings.ts +++ b/src/domain/service/noteSettings.ts @@ -4,6 +4,7 @@ import type NoteSettingsRepository from '@repository/noteSettings.repository.js' import type TeamRepository from '@repository/team.repository.js'; import type { MemberRole, Team, TeamMember, TeamMemberCreationAttributes } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; +import { createInvitationHash } from '@infrastructure/utils/invitationHash.js'; /** * Service responsible for Note Settings @@ -47,6 +48,7 @@ export default class NoteSettingsService { return await this.noteSettingsRepository.addNoteSettings({ noteId: noteId, isPublic: isPublic, + invitationHash: createInvitationHash(), }); } diff --git a/src/repository/storage/postgres/orm/sequelize/noteSettings.ts b/src/repository/storage/postgres/orm/sequelize/noteSettings.ts index 2c36ba01..b6669aed 100644 --- a/src/repository/storage/postgres/orm/sequelize/noteSettings.ts +++ b/src/repository/storage/postgres/orm/sequelize/noteSettings.ts @@ -28,6 +28,11 @@ export class NoteSettingsModel extends Model, * Is note public */ public declare isPublic: CreationOptional; + + /** + * Invitation hash + */ + public declare invitationHash: NoteSettings['invitationHash']; } /** @@ -88,6 +93,10 @@ export default class NoteSettingsSequelizeStorage { allowNull: false, defaultValue: true, }, + invitationHash: { + type: DataTypes.STRING, + allowNull: false, + }, }, { tableName: this.tableName, sequelize: this.database, @@ -169,12 +178,14 @@ export default class NoteSettingsSequelizeStorage { noteId, customHostname, isPublic, + invitationHash, }: NoteSettingsCreationAttributes ): Promise { const settings = await this.model.create({ noteId, customHostname, isPublic, + invitationHash, }); return settings; diff --git a/src/tests/utils/insert-data.ts b/src/tests/utils/insert-data.ts index 59500510..4b819805 100644 --- a/src/tests/utils/insert-data.ts +++ b/src/tests/utils/insert-data.ts @@ -44,7 +44,7 @@ async function insertNotes(db: SequelizeOrm): Promise { */ async function insertNoteSettings(db: SequelizeOrm): Promise { for (const noteSetting of noteSettings) { - await db.connection.query(`INSERT INTO public.note_settings (id, "note_id", "custom_hostname", "is_public") VALUES (${noteSetting.id}, '${noteSetting.note_id}', '${noteSetting.custom_hostname}', ${noteSetting.is_public})`); + await db.connection.query(`INSERT INTO public.note_settings (id, "note_id", "custom_hostname", "is_public", "invitation_hash") VALUES (${noteSetting.id}, '${noteSetting.note_id}', '${noteSetting.custom_hostname}', ${noteSetting.is_public}, '${noteSetting.invitation_hash}')`); } }