Skip to content

Commit 4ce9724

Browse files
slaveekse11sy
andauthored
feat: added cover to patch note settings (#261)
* feat: added cover to patch note settings * Update src/presentation/http/router/noteSettings.ts Co-authored-by: e11sy <[email protected]> * Update src/presentation/http/router/noteSettings.ts Co-authored-by: e11sy <[email protected]> * fix: eslint * feat: added cover to test note-settings patching --------- Co-authored-by: e11sy <[email protected]>
1 parent 07e5e4a commit 4ce9724

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/presentation/http/router/noteSettings.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ describe('NoteSettings API', () => {
480480
await global.db.insertNoteSetting({
481481
noteId: note.id,
482482
isPublic: true,
483+
cover: 'image.png',
483484
});
484485

485486
/** Create test team if user is in team */
@@ -505,6 +506,7 @@ describe('NoteSettings API', () => {
505506
},
506507
body: {
507508
isPublic: false,
509+
cover: 'new-image.png',
508510
},
509511
url: `/note-settings/${note.publicId}`,
510512
});
@@ -513,6 +515,7 @@ describe('NoteSettings API', () => {
513515

514516
if (expectedStatusCode === 200) {
515517
expect(response?.json().isPublic).toBe(false);
518+
expect(response?.json().cover).toBe('new-image.png');
516519
}
517520
});
518521

src/presentation/http/router/noteSettings.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
216216
* Patch noteSettings by note id
217217
*/
218218
fastify.patch<{
219-
Body: Pick<NoteSettings, 'customHostname' | 'isPublic'>;
219+
Body: Pick<NoteSettings, 'customHostname' | 'isPublic' | 'cover'>;
220220
Params: {
221221
notePublicId: NotePublicId;
222222
};
@@ -243,6 +243,9 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
243243
isPublic: {
244244
type: 'boolean',
245245
},
246+
cover: {
247+
type: 'string',
248+
},
246249
},
247250
},
248251
response: {
@@ -260,11 +263,12 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
260263
/**
261264
* @todo validate data
262265
*/
263-
const { customHostname, isPublic } = request.body;
266+
const { customHostname, isPublic, cover } = request.body;
264267

265268
const updatedNoteSettings = await noteSettingsService.patchNoteSettingsByNoteId(noteId, {
266269
customHostname,
267270
isPublic,
271+
cover,
268272
});
269273

270274
if (updatedNoteSettings === null) {

src/tests/utils/database-helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type NoteSettingsMockCreationAttributes = {
6969
customHostname?: NoteSettings['customHostname'];
7070
isPublic: NoteSettings['isPublic'];
7171
invitationHash?: NoteSettings['invitationHash'];
72+
cover?: NoteSettings['cover'];
7273
};
7374

7475
/**
@@ -207,10 +208,11 @@ export default class DatabaseHelpers {
207208
public async insertNoteSetting(noteSettings: NoteSettingsMockCreationAttributes): Promise<NoteSettingsMockCreationAttributes> {
208209
const customHostname = noteSettings.customHostname ?? null;
209210
const invitationHash = noteSettings.invitationHash ?? createInvitationHash();
211+
const cover = noteSettings.cover ?? null;
210212

211213
noteSettings.invitationHash = invitationHash;
212214

213-
await this.orm.connection.query(`INSERT INTO public.note_settings ("note_id", "custom_hostname", "is_public", "invitation_hash") VALUES (${noteSettings.noteId}, '${customHostname}', ${noteSettings.isPublic}, '${invitationHash}')`);
215+
await this.orm.connection.query(`INSERT INTO public.note_settings ("note_id", "custom_hostname", "is_public", "invitation_hash", "cover") VALUES (${noteSettings.noteId}, '${customHostname}', ${noteSettings.isPublic}, '${invitationHash}', '${cover}')`);
214216

215217
return noteSettings;
216218
}

0 commit comments

Comments
 (0)