Skip to content
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

refactor note endpoint(s) #5835

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ export class ProgramsServiceApiService {
): Promise<Note> {
return this.apiService.post(
environment.url_121_service_api,
`/programs/${programId}/notes`,
`/programs/${programId}/registrations/${referenceId}/note`,
{
referenceId,
text: note,
},
);
Expand All @@ -246,7 +245,7 @@ export class ProgramsServiceApiService {
getNotes(programId: number, referenceId: string): Promise<Note[]> {
return this.apiService.get(
environment.url_121_service_api,
`/programs/${programId}/notes/${referenceId}`,
`/programs/${programId}/registrations/${referenceId}/notes`,
null,
false,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ export class ProjectApiService extends DomainApiService {
}): Promise<unknown> {
return this.httpWrapperService.perform121ServiceRequest<Project>({
method: 'POST',
endpoint: `${BASE_ENDPOINT}/${projectId().toString()}/notes`,
endpoint: `${BASE_ENDPOINT}/${projectId().toString()}/registrations/${registrationReferenceId()}/note`,
body: {
referenceId: registrationReferenceId(),
text: note,
},
});
Expand Down
5 changes: 1 addition & 4 deletions services/121-service/src/notes/dto/note.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, Length } from 'class-validator';
import { IsString } from 'class-validator';

export class CreateNoteDto {
@ApiProperty({ example: '910c50be-f131-4b53-b06b-6506a40a2734' })
@Length(5, 200)
public readonly referenceId: string;
@ApiProperty({ example: 'note here' })
@IsString()
public readonly text: string;
Expand Down
17 changes: 9 additions & 8 deletions services/121-service/src/notes/notes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ export class NoteController {
'ReferenceId is not known - NOTE: this endpoint is scoped, depending on program configuration it only returns/modifies data the logged in user has access to.',
})
@ApiParam({ name: 'programId', required: true, type: 'integer' })
@Post(':programId/notes')
@ApiParam({ name: 'referenceId', required: true, type: 'string' })
@Post(':programId/registrations/:referenceId/note')
public async createNote(
@Req() req,
@Param('programId', ParseIntPipe) programId: number,
@Param('referenceId') referenceId: string,
@Body() createNote: CreateNoteDto,
): Promise<void> {
const userId = req.user.id;
await this.noteService.createNote(
createNote.referenceId,
referenceId,
createNote.text,
userId,
programId,
Expand All @@ -70,13 +72,12 @@ export class NoteController {
type: [ResponseNoteDto],
})
@ApiParam({ name: 'programId', required: true, type: 'integer' })
@ApiParam({ name: 'referenceId', required: true })
@Get(':programId/notes/:referenceId')
@ApiParam({ name: 'referenceId', required: true, type: 'string' })
@Get(':programId/registrations/:referenceId/notes')
public async retrieveNotes(
@Param() params,
@Param('programId', ParseIntPipe)
programId: number,
@Param('programId', ParseIntPipe) programId: number,
@Param('referenceId') referenceId: string,
): Promise<ResponseNoteDto[]> {
return await this.noteService.retrieveNotes(params.referenceId, programId);
return await this.noteService.retrieveNotes(referenceId, programId);
}
}
6 changes: 3 additions & 3 deletions services/121-service/test/helpers/program.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ export async function postNote(
accessToken: string,
): Promise<request.Response> {
return await getServer()
.post(`/programs/${programId}/notes`)
.post(`/programs/${programId}/registrations/${referenceId}/note`)
.set('Cookie', [accessToken])
.send({ referenceId, text });
.send({ text });
}

export async function getNotes(
Expand All @@ -478,7 +478,7 @@ export async function getNotes(
accessToken: string,
): Promise<request.Response> {
return await getServer()
.get(`/programs/${programId}/notes/${referenceId}`)
.get(`/programs/${programId}/registrations/${referenceId}/notes`)
.set('Cookie', [accessToken]);
}

Expand Down
Loading