-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(routes): get all notes by parent note id #282
Changes from 3 commits
2ad6cd6
617ebc8
7ffc28b
e614623
ad8b82b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import type { FastifyPluginCallback } from 'fastify'; | ||
import type NoteService from '@domain/service/note.js'; | ||
import useNoteResolver from '../middlewares/note/useNoteResolver.js'; | ||
import useNoteSettingsResolver from '../middlewares/noteSettings/useNoteSettingsResolver.js'; | ||
import useMemberRoleResolver from '../middlewares/noteSettings/useMemberRoleResolver.js'; | ||
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 type { NoteInternalId } from '@domain/entities/note.js'; | ||
|
||
/** | ||
* Interface for the noteList router. | ||
|
@@ -12,6 +17,11 @@ interface NoteListRouterOptions { | |
*/ | ||
noteService: NoteService; | ||
|
||
/** | ||
* Note Settings service instance | ||
*/ | ||
noteSettingsService: NoteSettingsService; | ||
|
||
} | ||
|
||
/** | ||
|
@@ -22,6 +32,25 @@ interface NoteListRouterOptions { | |
*/ | ||
const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, opts, done) => { | ||
const noteService = opts.noteService; | ||
const noteSettingsService = opts.noteSettingsService; | ||
|
||
/** | ||
* Prepare note id resolver middleware | ||
* It should be used in routes that accepts note public id | ||
*/ | ||
const { noteResolver } = useNoteResolver(noteService); | ||
|
||
/** | ||
* Prepare note settings resolver middleware | ||
* It should be used to use note settings in middlewares | ||
*/ | ||
const { noteSettingsResolver } = useNoteSettingsResolver(noteSettingsService); | ||
|
||
/** | ||
* Prepare user role resolver middleware | ||
* It should be used to use user role in middlewares | ||
*/ | ||
const { memberRoleResolver } = useMemberRoleResolver(noteSettingsService); | ||
|
||
/** | ||
* Get note list ordered by time of last visit | ||
|
@@ -77,6 +106,73 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o | |
return reply.send(noteListPublic); | ||
}); | ||
|
||
/** | ||
* Get note list by parent note | ||
*/ | ||
fastify.get<{ | ||
Params: { | ||
parentNoteId: NoteInternalId; | ||
}; | ||
Querystring: { | ||
page: number; | ||
}; | ||
}>('/:parentNoteId', { | ||
config: { | ||
policy: [ | ||
'authRequired', | ||
'notePublicOrUserInTeam', | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have updated the notResolver to consider parentId as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think that this is not a case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me know, which policies required here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think that we should check it without policy and send There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request you to review new changes |
||
}, | ||
schema: { | ||
params: { | ||
notePublicId: { | ||
$ref: 'NoteSchema#/properties/id', | ||
}, | ||
}, | ||
querystring: { | ||
page: { | ||
type: 'number', | ||
minimum: 1, | ||
maximum: 30, | ||
}, | ||
}, | ||
response: { | ||
'2xx': { | ||
description: 'Query notelist', | ||
properties: { | ||
items: { | ||
id: { type: 'string' }, | ||
content: { type: 'string' }, | ||
createdAt: { type: 'string' }, | ||
creatorId: { type: 'string' }, | ||
updatedAt: { type: 'string' }, | ||
}, | ||
}, | ||
Tushar504 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}, | ||
preHandler: [ | ||
noteResolver, | ||
noteSettingsResolver, | ||
memberRoleResolver, | ||
], | ||
}, async (request, reply) => { | ||
const { parentNoteId } = request.params; | ||
const { page } = request.query; | ||
|
||
const noteList = await noteService.getNoteListByParentNote(parentNoteId, page); | ||
/** | ||
* Wrapping Notelist for public use | ||
*/ | ||
const noteListItemsPublic: NotePublic[] = noteList.items.map(definePublicNote); | ||
|
||
const noteListPublic: NoteListPublic = { | ||
items: noteListItemsPublic, | ||
}; | ||
|
||
return reply.send(noteListPublic); | ||
}); | ||
|
||
done(); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,7 @@ export async function init(orm: Orm, s3Config: S3StorageConfig): Promise<Reposit | |
/** | ||
* Create associations between note and relations table | ||
*/ | ||
noteStorage.createAssociationWithNoteRelationsModel(noteRelationshipStorage.model); | ||
noteRelationshipStorage.createAssociationWithNoteModel(noteStorage.model); | ||
Comment on lines
+142
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this line needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need that association to use include clause(join table) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as i can see, we already linked noteRelationshipStorage with noteStorage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should i implement this getNoteListByParentNote() method in noteRelationshipStorage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, but do you actually need to make another assotiation in addition to the existing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is required, i refered other relationships implemenation(noteVisits, noteSetting) |
||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no tests for
userInTeam
policyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests, review it