Skip to content

Commit

Permalink
[Fix] fix the eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tushar504 committed Nov 5, 2024
1 parent 617ebc8 commit 7ffc28b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
5 changes: 3 additions & 2 deletions src/domain/service/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoteList> {
const offset = (page - 1) * this.noteListPortionSize;

return {
items: await this.noteRepository.getNoteListByParentNote(parentNoteId, offset, this.noteListPortionSize),
};
Expand Down
2 changes: 1 addition & 1 deletion src/presentation/http/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
8 changes: 4 additions & 4 deletions src/presentation/http/middlewares/note/useNoteResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/presentation/http/router/noteList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ describe('GET /notes?page', () => {
});
});


describe('GET /notes/:parentNoteId?page', () => {
test.each([
/**
Expand Down Expand Up @@ -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,
Expand All @@ -244,7 +243,7 @@ describe('GET /notes/:parentNoteId?page', () => {
cover: 'DZnvqi63.png',
isPublic: true,
});

await global.db.insertNoteRelation({
parentId: parentNote.id,
noteId: note.id,
Expand Down Expand Up @@ -272,4 +271,3 @@ describe('GET /notes/:parentNoteId?page', () => {
}
});
});

25 changes: 13 additions & 12 deletions src/presentation/http/router/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,11 +18,10 @@ interface NoteListRouterOptions {
noteService: NoteService;

/**
* Note Settings service instance
*/
* Note Settings service instance
*/
noteSettingsService: NoteSettingsService;


}

/**
Expand Down Expand Up @@ -113,7 +112,7 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
fastify.get<{
Params: {
parentNoteId: NoteInternalId;
}
};
Querystring: {
page: number;
};
Expand All @@ -129,13 +128,15 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
notePublicId: {
$ref: 'NoteSchema#/properties/id',
},
}, querystring: {
},
querystring: {
page: {
type: 'number',
minimum: 1,
maximum: 30,
},
}, response: {
},
response: {
'2xx': {
description: 'Query notelist',
properties: {
Expand All @@ -149,14 +150,15 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (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);
/**
Expand All @@ -169,8 +171,7 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
};

return reply.send(noteListPublic);
})

});

done();
};
Expand Down
2 changes: 1 addition & 1 deletion src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function init(orm: Orm, s3Config: S3StorageConfig): Promise<Reposit
/**
* Create associations between note and relations table
*/
noteStorage.createAssociationWithNoteRelationsModel(noteRelationshipStorage.model)
noteStorage.createAssociationWithNoteRelationsModel(noteRelationshipStorage.model);
noteRelationshipStorage.createAssociationWithNoteModel(noteStorage.model);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/repository/note.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export default class NoteRepository {
public async getNotesByIds(noteIds: NoteInternalId[]): Promise<Note[]> {
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
*/
Expand Down
13 changes: 6 additions & 7 deletions src/repository/storage/postgres/orm/sequelize/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -357,7 +357,7 @@ export default class NoteSequelizeStorage {

return notes;
}

/**
* Gets note list by parent note id
* @param parentId - parent note id
Expand All @@ -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'],
Expand Down

0 comments on commit 7ffc28b

Please sign in to comment.