Skip to content

Commit

Permalink
changes to work with new noteSettings format
Browse files Browse the repository at this point in the history
  • Loading branch information
kloV148 committed Dec 5, 2023
1 parent 1bb2048 commit f7347ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/domain/service/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +48,7 @@ export default class NoteSettingsService {
return await this.noteSettingsRepository.addNoteSettings({
noteId: noteId,
isPublic: isPublic,
invitationHash: createInvitationHash(),
});
}

Expand Down
11 changes: 11 additions & 0 deletions src/repository/storage/postgres/orm/sequelize/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class NoteSettingsModel extends Model<InferAttributes<NoteSettingsModel>,
* Is note public
*/
public declare isPublic: CreationOptional<NoteSettings['isPublic']>;

/**
* Invitation hash
*/
public declare invitationHash: NoteSettings['invitationHash'];
}

/**
Expand Down Expand Up @@ -88,6 +93,10 @@ export default class NoteSettingsSequelizeStorage {
allowNull: false,
defaultValue: true,
},
invitationHash: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: this.tableName,
sequelize: this.database,
Expand Down Expand Up @@ -169,12 +178,14 @@ export default class NoteSettingsSequelizeStorage {
noteId,
customHostname,
isPublic,
invitationHash,
}: NoteSettingsCreationAttributes
): Promise<NoteSettings> {
const settings = await this.model.create({
noteId,
customHostname,
isPublic,
invitationHash,
});

return settings;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils/insert-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function insertNotes(db: SequelizeOrm): Promise<void> {
*/
async function insertNoteSettings(db: SequelizeOrm): Promise<void> {
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}')`);
}
}

Expand Down

0 comments on commit f7347ef

Please sign in to comment.