Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HyTekCoop committed Oct 21, 2023
1 parent 7f39c6f commit 59ed895
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/domain/entities/noteList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Note } from '@domain/entities/note.js';

/**
* Note list entity
*/
export type NoteList = {
items: Note[];
};
6 changes: 3 additions & 3 deletions src/domain/service/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default class NoteListService {
}

/**
* Gets note list by creator id
* Returns note list by creator id
*
* @param id - note creator id
* @returns { Promise<NoteList | null> } note
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(id: number): Promise<NoteList | null> {
public async getNoteListByCreatorId(id: number): Promise<NoteList> {
return await this.repository.getNoteListByCreatorId(id);
}
}
12 changes: 0 additions & 12 deletions src/presentation/http/router/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
const { userId } = request;
const noteList = await noteListService.getNoteListByCreatorId(userId as number);

/**
* Check if note list does not exist
*/
if (!noteList) {
const response: ErrorResponse = {
code: StatusCodes.NOT_FOUND,
message: 'Note list not found',
};

return reply.send(response);
}

return reply.send(noteList);
});

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 @@ -74,9 +74,9 @@ export default class NoteRepository {
* Gets note list by creator id
*
* @param id - note creator id
* @returns { Promise<NoteList | null> } note
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(id: number): Promise<NoteList | null> {
public async getNoteListByCreatorId(id: number): Promise<NoteList> {
return await this.storage.getNoteListByCreatorId(id);
}
}
8 changes: 2 additions & 6 deletions src/repository/storage/postgres/orm/sequelize/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,15 @@ export default class NoteSequelizeStorage {
* Gets note list by creator id
*
* @param creatorId - note creator id
* @returns { Promise<NoteList | null> } note
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(creatorId: number): Promise<NoteList | null> {
public async getNoteListByCreatorId(creatorId: number): Promise<NoteList> {
const noteList = await this.model.findAll({
where: {
creatorId,
},
});

if (noteList.length === 0) {
return null;
}

return {
items: noteList,
};
Expand Down

0 comments on commit 59ed895

Please sign in to comment.