From 7ffc28bd187fd56f24b49480defaf8bb9fa7c0cf Mon Sep 17 00:00:00 2001 From: Tushar Ahire Date: Tue, 5 Nov 2024 15:16:43 +0530 Subject: [PATCH] [Fix] fix the eslint issues --- src/domain/service/note.ts | 5 ++-- src/presentation/http/http-api.ts | 2 +- .../http/middlewares/note/useNoteResolver.ts | 8 +++--- src/presentation/http/router/noteList.test.ts | 6 ++--- src/presentation/http/router/noteList.ts | 25 ++++++++++--------- src/repository/index.ts | 2 +- src/repository/note.repository.ts | 4 +-- .../storage/postgres/orm/sequelize/note.ts | 13 +++++----- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index cb92e483..602430e5 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -236,15 +236,16 @@ export default class NoteService { items: await this.noteRepository.getNoteListByUserId(userId, offset, this.noteListPortionSize), }; } - + /** * Returns note list by parent note id - * @param parentId - id of the parent note + * @param parentNoteId - id of the parent note * @param page - number of current page * @returns list of the notes ordered by time of last visit */ public async getNoteListByParentNote(parentNoteId: NoteInternalId, page: number): Promise { const offset = (page - 1) * this.noteListPortionSize; + return { items: await this.noteRepository.getNoteListByParentNote(parentNoteId, offset, this.noteListPortionSize), }; diff --git a/src/presentation/http/http-api.ts b/src/presentation/http/http-api.ts index 6376db8c..e607e4d8 100644 --- a/src/presentation/http/http-api.ts +++ b/src/presentation/http/http-api.ts @@ -207,7 +207,7 @@ export default class HttpApi implements Api { await this.server?.register(NoteListRouter, { prefix: '/notes', noteService: domainServices.noteService, - noteSettingsService: domainServices.noteSettingsService + noteSettingsService: domainServices.noteSettingsService, }); await this.server?.register(JoinRouter, { diff --git a/src/presentation/http/middlewares/note/useNoteResolver.ts b/src/presentation/http/middlewares/note/useNoteResolver.ts index 6ae3e200..2c1cc817 100644 --- a/src/presentation/http/middlewares/note/useNoteResolver.ts +++ b/src/presentation/http/middlewares/note/useNoteResolver.ts @@ -35,13 +35,13 @@ export default function useNoteResolver(noteService: NoteService): { const publicId = requestData.notePublicId as NotePublicId; return await noteService.getNoteByPublicId(publicId); - } - else if (hasProperty(requestData, 'parentNoteId') && notEmpty(requestData.parentNoteId)) { + } else if (hasProperty(requestData, 'parentNoteId') && notEmpty(requestData.parentNoteId)) { const noteId = requestData.parentNoteId as NoteInternalId; - return await noteService.getNoteById(noteId) + + return await noteService.getNoteById(noteId); } } - + return { noteResolver: async function noteIdResolver(request, reply) { let note: Note | undefined; diff --git a/src/presentation/http/router/noteList.test.ts b/src/presentation/http/router/noteList.test.ts index 66b1cf16..edb11ed0 100644 --- a/src/presentation/http/router/noteList.test.ts +++ b/src/presentation/http/router/noteList.test.ts @@ -145,7 +145,6 @@ describe('GET /notes?page', () => { }); }); - describe('GET /notes/:parentNoteId?page', () => { test.each([ /** @@ -233,7 +232,7 @@ describe('GET /notes/:parentNoteId?page', () => { cover: 'DZnvqi63.png', isPublic: true, }); - + for (let i = 0; i < portionSize; i++) { const note = await global.db.insertNote({ creatorId: creator.id, @@ -244,7 +243,7 @@ describe('GET /notes/:parentNoteId?page', () => { cover: 'DZnvqi63.png', isPublic: true, }); - + await global.db.insertNoteRelation({ parentId: parentNote.id, noteId: note.id, @@ -272,4 +271,3 @@ describe('GET /notes/:parentNoteId?page', () => { } }); }); - diff --git a/src/presentation/http/router/noteList.ts b/src/presentation/http/router/noteList.ts index c4d5c847..7a95ffc2 100644 --- a/src/presentation/http/router/noteList.ts +++ b/src/presentation/http/router/noteList.ts @@ -6,7 +6,7 @@ import useMemberRoleResolver from '../middlewares/noteSettings/useMemberRoleReso import type NoteSettingsService from '@domain/service/noteSettings.js'; import { definePublicNote, type NotePublic } from '@domain/entities/notePublic.js'; import type { NoteListPublic } from '@domain/entities/noteList.js'; -import { NoteInternalId } from '@domain/entities/note.js'; +import type { NoteInternalId } from '@domain/entities/note.js'; /** * Interface for the noteList router. @@ -18,11 +18,10 @@ interface NoteListRouterOptions { noteService: NoteService; /** - * Note Settings service instance - */ + * Note Settings service instance + */ noteSettingsService: NoteSettingsService; - } /** @@ -113,7 +112,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o fastify.get<{ Params: { parentNoteId: NoteInternalId; - } + }; Querystring: { page: number; }; @@ -129,13 +128,15 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o notePublicId: { $ref: 'NoteSchema#/properties/id', }, - }, querystring: { + }, + querystring: { page: { type: 'number', minimum: 1, maximum: 30, }, - }, response: { + }, + response: { '2xx': { description: 'Query notelist', properties: { @@ -149,14 +150,15 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o }, }, }, - }, preHandler: [ + }, + preHandler: [ noteResolver, noteSettingsResolver, memberRoleResolver, ], }, async (request, reply) => { - const { parentNoteId } = await request.params; - const { page } = await request.query; + const { parentNoteId } = request.params; + const { page } = request.query; const noteList = await noteService.getNoteListByParentNote(parentNoteId, page); /** @@ -169,8 +171,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o }; return reply.send(noteListPublic); - }) - + }); done(); }; diff --git a/src/repository/index.ts b/src/repository/index.ts index 35ff6811..f90aec6f 100644 --- a/src/repository/index.ts +++ b/src/repository/index.ts @@ -139,7 +139,7 @@ export async function init(orm: Orm, s3Config: S3StorageConfig): Promise { return await this.storage.getNotesByIds(noteIds); } - + /** * Gets note list by parent note id - * @param parentId - parent note id + * @param parentNoteId - parent note id * @param offset - number of skipped notes * @param limit - number of notes to get */ diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index c620c39a..c00e5a9b 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -6,7 +6,6 @@ import { UserModel } from '@repository/storage/postgres/orm/sequelize/user.js'; import type { NoteSettingsModel } from './noteSettings.js'; import type { NoteVisitsModel } from './noteVisits.js'; import type { NoteRelationsModel } from './noteRelations.js'; -import { DomainError } from '@domain/entities/DomainError.js'; import type { NoteHistoryModel } from './noteHistory.js'; /* eslint-disable @typescript-eslint/naming-convention */ @@ -164,8 +163,9 @@ export default class NoteSequelizeStorage { this.model.hasMany(this.relationsModel, { foreignKey: 'parentId', as: 'noteRelations', - }) + }); } + /** * Insert note to database * @param options - note creation options @@ -357,7 +357,7 @@ export default class NoteSequelizeStorage { return notes; } - + /** * Gets note list by parent note id * @param parentId - parent note id @@ -377,17 +377,16 @@ export default class NoteSequelizeStorage { where: { parentId }, attributes: ['noteId'], }); - + const noteIds = childNotes.map(relation => relation.noteId); - - + const reply = await this.model.findAll({ where: { id: { [Op.in]: noteIds, }, }, - include:[{ + include: [{ model: this.settingsModel, as: 'noteSettings', attributes: ['cover'],