Skip to content

Commit

Permalink
feat: added cover to patch note settings (#261)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
slaveeks and e11sy authored Jul 1, 2024
1 parent 07e5e4a commit 4ce9724
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/presentation/http/router/noteSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ describe('NoteSettings API', () => {
await global.db.insertNoteSetting({
noteId: note.id,
isPublic: true,
cover: 'image.png',
});

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

if (expectedStatusCode === 200) {
expect(response?.json().isPublic).toBe(false);
expect(response?.json().cover).toBe('new-image.png');
}
});

Expand Down
8 changes: 6 additions & 2 deletions src/presentation/http/router/noteSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
* Patch noteSettings by note id
*/
fastify.patch<{
Body: Pick<NoteSettings, 'customHostname' | 'isPublic'>;
Body: Pick<NoteSettings, 'customHostname' | 'isPublic' | 'cover'>;
Params: {
notePublicId: NotePublicId;
};
Expand All @@ -243,6 +243,9 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
isPublic: {
type: 'boolean',
},
cover: {
type: 'string',
},
},
},
response: {
Expand All @@ -260,11 +263,12 @@ const NoteSettingsRouter: FastifyPluginCallback<NoteSettingsRouterOptions> = (fa
/**
* @todo validate data
*/
const { customHostname, isPublic } = request.body;
const { customHostname, isPublic, cover } = request.body;

const updatedNoteSettings = await noteSettingsService.patchNoteSettingsByNoteId(noteId, {
customHostname,
isPublic,
cover,
});

if (updatedNoteSettings === null) {
Expand Down
4 changes: 3 additions & 1 deletion src/tests/utils/database-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type NoteSettingsMockCreationAttributes = {
customHostname?: NoteSettings['customHostname'];
isPublic: NoteSettings['isPublic'];
invitationHash?: NoteSettings['invitationHash'];
cover?: NoteSettings['cover'];
};

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

noteSettings.invitationHash = invitationHash;

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}')`);
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}')`);

return noteSettings;
}
Expand Down

0 comments on commit 4ce9724

Please sign in to comment.