Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/domain/service/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ export default class NoteService {
}

/**
* Returns note list by creator id
* Returns recent notes visited by user, ordered by time of last visit
* @param userId - id of the user
* @param page - number of current page
* @returns list of the notes ordered by time of last visit
*/
public async getNoteListByUserId(userId: User['id'], page: number): Promise<NoteList> {
public async getRecentNotesByUserId(userId: User['id'], page: number): Promise<NoteList> {
const offset = (page - 1) * this.noteListPortionSize;

return {
items: await this.noteRepository.getNoteListByUserId(userId, offset, this.noteListPortionSize),
items: await this.noteRepository.getRecentNotesByUserId(userId, offset, this.noteListPortionSize),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/presentation/http/router/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
const userId = request.userId as number;
const page = request.query.page;

const noteList = await noteService.getNoteListByUserId(userId, page);
const noteList = await noteService.getRecentNotesByUserId(userId, page);
/**
* Wrapping Notelist for public use
*/
Expand Down
6 changes: 3 additions & 3 deletions src/repository/note.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default class NoteRepository {
}

/**
* Gets note list by creator id
* Gets recent notes visited by user, ordered by time of last visit
* @param id - note creator id
* @param offset - number of skipped notes
* @param limit - number of notes to get
*/
public async getNoteListByUserId(id: number, offset: number, limit: number): Promise<Note[]> {
return await this.storage.getNoteListByUserId(id, offset, limit);
public async getRecentNotesByUserId(id: number, offset: number, limit: number): Promise<Note[]> {
return await this.storage.getRecentNotesByUserId(id, offset, limit);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/repository/storage/postgres/orm/sequelize/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ export default class NoteSequelizeStorage {
}

/**
* Gets note list by creator id
* Gets recent notes visited by user, ordered by time of last visit
* @param userId - id of certain user
* @param offset - number of skipped notes
* @param limit - number of notes to get
* @returns list of the notes
* @returns list of the notes ordered by last visit time
*/
public async getNoteListByUserId(userId: number, offset: number, limit: number): Promise<Note[]> {
public async getRecentNotesByUserId(userId: number, offset: number, limit: number): Promise<Note[]> {
if (this.visitsModel === null) {
throw new Error('NoteStorage: NoteVisit model should be defined');
}
Expand Down Expand Up @@ -356,18 +356,18 @@ export default class NoteSequelizeStorage {
// Fetch all notes and relations in a recursive query
const query = `
WITH RECURSIVE note_tree AS (
SELECT
SELECT
n.id AS "noteId",
n.content,
n.public_id AS "publicId",
nr.parent_id AS "parentId"
FROM ${String(this.database.literal(this.tableName).val)} n
LEFT JOIN ${String(this.database.literal('note_relations').val)} nr ON n.id = nr.note_id
WHERE n.id = :startNoteId

UNION ALL

SELECT
SELECT
n.id AS "noteId",
n.content,
n.public_id AS "publicId",
Expand Down
Loading