-
Notifications
You must be signed in to change notification settings - Fork 2
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
10 naming #25
base: main
Are you sure you want to change the base?
10 naming #25
Changes from 6 commits
3d872c5
a9d954f
ce9cc38
481c5da
b0de70a
c4176ce
5c90e51
a2d989b
edbd119
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,6 +1,6 @@ | ||
export * from './auth.decorators'; | ||
export * from './event.decorators'; | ||
export * from './notes.decorators'; | ||
export * from './note.decorators'; | ||
export * from './search.decorators'; | ||
export * from './task.decorators'; | ||
export * from './user.decorators'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import { JwtGuard } from 'src/auth/guard'; | |
import { GetUser } from 'src/decorators'; | ||
import { | ||
AddEventExceptionApi, | ||
CreateEventByCurrentUserApi, | ||
AddEventApi, | ||
DeleteEventApi, | ||
DeleteExceptionApi, | ||
EditEventApi, | ||
|
@@ -54,7 +54,7 @@ export class EventController { | |
async getUserEvents( | ||
@GetUser('id') userId: number, | ||
): Promise<ReturnEventDTO[]> { | ||
return await this.eventService.fetchUserEvents(userId); | ||
return await this.eventService.fetchUser(userId); | ||
} | ||
|
||
@Get('dates') | ||
|
@@ -74,7 +74,7 @@ export class EventController { | |
@Get(':id') | ||
@GetEventByIdApi() | ||
async getEventById(@Param('id') eventId: number): Promise<ReturnEventDTO> { | ||
return await this.eventService.fetchById(eventId); | ||
return await this.eventService.fetch(eventId); | ||
} | ||
|
||
@Get('except/:id') | ||
|
@@ -86,12 +86,12 @@ export class EventController { | |
} | ||
|
||
@Post() | ||
@CreateEventByCurrentUserApi() | ||
async createEventByCurrentUser( | ||
@AddEventApi() | ||
async addEvent( | ||
@GetUser('id') userId: number, | ||
@Body() eventDto: CreateEventDTO, | ||
): Promise<ReturnEventDTO> { | ||
return await this.eventService.createEvent(userId, eventDto); | ||
return await this.eventService.add(userId, eventDto); | ||
} | ||
|
||
@Post('exceptions/:id') | ||
|
@@ -100,7 +100,7 @@ export class EventController { | |
@Param('id') eventId: number, | ||
@Body() exceptionDto: CreateEventExceptionDTO, | ||
): Promise<ReturnEventExceptionDTO> { | ||
return await this.eventService.createException(eventId, exceptionDto); | ||
return await this.eventService.addException(eventId, exceptionDto); | ||
} | ||
|
||
@Patch(':id') | ||
|
@@ -109,7 +109,7 @@ export class EventController { | |
@Param('id') eventId: number, | ||
@Body() editEventDto: EditEventDTO, | ||
): Promise<ReturnEventDTO> { | ||
return await this.eventService.editById(eventId, editEventDto); | ||
return await this.eventService.edit(eventId, editEventDto); | ||
} | ||
|
||
@Patch('exceptions/:id') | ||
|
@@ -118,7 +118,7 @@ export class EventController { | |
@Param('id') exceptionId: number, | ||
@Body() editExceptionDto: EditEventExceptionDTO, | ||
): Promise<ReturnEventExceptionDTO> { | ||
return await this.eventService.editExceptionById( | ||
return await this.eventService.editException( | ||
exceptionId, | ||
editExceptionDto, | ||
); | ||
|
@@ -128,13 +128,13 @@ export class EventController { | |
@Delete(':id') | ||
@DeleteEventApi() | ||
async deleteEvent(@Param('id') eventId: number): Promise<void> { | ||
await this.eventService.deleteById(eventId); | ||
await this.eventService.delete(eventId); | ||
} | ||
|
||
@HttpCode(HttpStatus.NO_CONTENT) | ||
@Delete('exceptions/:id') | ||
@DeleteExceptionApi() | ||
async deleteException(@Param('id') exceptionId: number): Promise<void> { | ||
await this.eventService.removeExceptionById(exceptionId); | ||
await this.eventService.deleteException(exceptionId); | ||
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. deleteException in this case is clear, because we know that we want to delete one so it is obvious that we need for example id |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ export class EventService { | |
private readonly exceptionRepository: Repository<EventExceptionEntity>, | ||
) {} | ||
|
||
async fetchById(eventId: number): Promise<ReturnEventDTO> { | ||
async fetch(eventId: number): Promise<ReturnEventDTO> { | ||
const event = await this.eventRepository.findOne({ | ||
where: { id: eventId }, | ||
relations: { recurrencePattern: true }, | ||
|
@@ -42,7 +42,7 @@ export class EventService { | |
return event; | ||
} | ||
|
||
async fetchUserEvents(userId: number): Promise<ReturnEventDTO[]> { | ||
async fetchUser(userId: number): Promise<ReturnEventDTO[]> { | ||
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. Wrong naming convention in my opinion, service method returns Events, not a User, I think something like "fetchByUser" would be more descriptive 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 agree |
||
return this.eventRepository.find({ | ||
where: { createdById: userId }, | ||
relations: { recurrencePattern: true, eventExceptions: true }, | ||
|
@@ -182,7 +182,7 @@ export class EventService { | |
return exception; | ||
} | ||
|
||
async createEvent( | ||
async add( | ||
userId: number, | ||
eventDto: CreateEventDTO, | ||
): Promise<ReturnEventDTO> { | ||
|
@@ -194,7 +194,7 @@ export class EventService { | |
return event; | ||
} | ||
|
||
async createException( | ||
async addException( | ||
eventId: number, | ||
exceptionDto: CreateEventExceptionDTO, | ||
): Promise<ReturnEventExceptionDTO> { | ||
|
@@ -206,7 +206,7 @@ export class EventService { | |
return exception; | ||
} | ||
|
||
async editById( | ||
async edit( | ||
eventId: number, | ||
editEventDto: EditEventDTO, | ||
): Promise<ReturnEventDTO> { | ||
|
@@ -228,7 +228,7 @@ export class EventService { | |
return eventToUpdate; | ||
} | ||
|
||
async editExceptionById( | ||
async editException( | ||
exceptionId: number, | ||
editExceptionDto: EditEventExceptionDTO, | ||
): Promise<ReturnEventExceptionDTO> { | ||
|
@@ -245,11 +245,11 @@ export class EventService { | |
return exceptionToUpdate; | ||
} | ||
|
||
async deleteById(eventId: number): Promise<void> { | ||
async delete(eventId: number): Promise<void> { | ||
await this.eventRepository.delete({ id: eventId }); | ||
} | ||
|
||
async removeExceptionById(exceptionId: number): Promise<void> { | ||
async deleteException(exceptionId: number): Promise<void> { | ||
await this.exceptionRepository.delete({ id: exceptionId }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './notes.dto'; | ||
export * from './note.dto'; | ||
export * from './editNote.dto'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,16 @@ import { | |
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { NoteService } from './notes.service'; | ||
import { NoteService } from './note.service'; | ||
import { editNoteDTO, NoteDTO } from './dto'; | ||
import { JwtGuard } from '../../auth/guard'; | ||
import { GetUser } from '../../decorators'; | ||
import { UserEntity } from 'src/database/entities/user.entity'; | ||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; | ||
import { | ||
AddNoteApi, | ||
EditNoteByIdApi, | ||
FetchUserNotesApi, | ||
EditNoteApi as EditNoteApi, | ||
GetUserNotesApi as GetUserNotesApi, | ||
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. Wait, why there is 'as'? |
||
} from '../../decorators/OpenAPI'; | ||
|
||
@UseGuards(JwtGuard) | ||
|
@@ -27,20 +27,20 @@ export class NoteController { | |
constructor(private notesService: NoteService) {} | ||
|
||
@Get() | ||
@FetchUserNotesApi() | ||
fetchUserNotes(@GetUser() user: UserEntity) { | ||
return this.notesService.fetchUserNotes(user); | ||
@GetUserNotesApi() | ||
getUserNotes(@GetUser() user: UserEntity): Promise<NoteDTO[]> { | ||
return this.notesService.fetchUser(user); | ||
} | ||
|
||
@Post(':id') | ||
@Post() | ||
@AddNoteApi() | ||
addNote(@GetUser() user: UserEntity, @Body() noteDto: NoteDTO) { | ||
return this.notesService.addNote(user, noteDto); | ||
addNote(@GetUser() user: UserEntity, @Body() noteDto: NoteDTO): Promise<NoteDTO> { | ||
return this.notesService.add(user, noteDto); | ||
} | ||
|
||
@Patch(':id') | ||
@EditNoteByIdApi() | ||
editNoteById(@Param('id') id: number, @Body() noteDto: editNoteDTO) { | ||
return this.notesService.editNoteById(id, noteDto); | ||
@EditNoteApi() | ||
editNote(@Param('id') id: number, @Body() noteDto: editNoteDTO): Promise<void> { | ||
return this.notesService.edit(id, noteDto); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,22 @@ export class NoteService { | |
private noteRepository: Repository<NoteEntity>, | ||
) {} | ||
|
||
async fetchUserNotes(user: UserEntity) { | ||
async fetchUser(user: UserEntity): Promise<NoteDTO[]> { | ||
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. Same here |
||
return this.noteRepository.find({ | ||
relations: ['user'], | ||
where: { user }, | ||
}); | ||
} | ||
|
||
async addNote(user: UserEntity, noteDto: NoteDTO) { | ||
async add(user: UserEntity, noteDto: NoteDTO): Promise<NoteDTO> { | ||
if (!user) | ||
throw new HttpException('User not found', HttpStatus.NOT_FOUND); | ||
const newNote = this.noteRepository.create({ ...noteDto, user }); | ||
|
||
return this.noteRepository.save(newNote); | ||
} | ||
|
||
async editNoteById(id: number, noteDto: editNoteDTO) { | ||
return this.noteRepository.update({ id }, { ...noteDto }); | ||
async edit(id: number, noteDto: editNoteDTO): Promise<void> { | ||
this.noteRepository.update({ id }, { ...noteDto }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,8 @@ import { | |
AddTaskApi, | ||
DeleteTaskApi, | ||
EditTaskApi, | ||
GetAllUserTasksApi, | ||
GetUserTaskApi, | ||
GetUserTasksApi as GetUserTasksApi, | ||
GetTaskByIdApi as GetTaskbyIdApi, | ||
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. Again unnecessary 'as' |
||
} from '../../decorators/OpenAPI'; | ||
|
||
@UseGuards(JwtGuard) | ||
|
@@ -34,21 +34,21 @@ import { | |
export class TaskController { | ||
constructor(private readonly taskService: TaskService) {} | ||
|
||
@Get('/user/all') | ||
@GetAllUserTasksApi() | ||
async getAllUserTasks( | ||
@Get() | ||
@GetUserTasksApi() | ||
async getUserTasks( | ||
@GetUser() user: UserEntity, | ||
): Promise<ReturnTaskDTO[]> { | ||
return await this.taskService.getAllUserTasks(user); | ||
return await this.taskService.fetchUser(user); | ||
} | ||
|
||
@Get('/user/:id') | ||
@GetUserTaskApi() | ||
async getUserTask( | ||
@Get(':id') | ||
@GetTaskbyIdApi() | ||
async getTaskById( | ||
@GetUser() user: UserEntity, | ||
@Param('id', ParseIntPipe) taskId: number, | ||
): Promise<ReturnTaskDTO> { | ||
const task = await this.taskService.getUserTask(user, taskId); | ||
const task = await this.taskService.fetch(user, taskId); | ||
if (!task) { | ||
throw new NotFoundException('Task not found'); | ||
} | ||
|
@@ -62,7 +62,7 @@ export class TaskController { | |
@GetUser() user: UserEntity, | ||
@Body() createTaskDTO: CreateTaskDTO, | ||
): Promise<ReturnTaskDTO> { | ||
return await this.taskService.addTask(user, createTaskDTO); | ||
return await this.taskService.add(user, createTaskDTO); | ||
} | ||
|
||
@Patch(':id') | ||
|
@@ -76,7 +76,7 @@ export class TaskController { | |
throw new BadRequestException('ID is not valid in URL and body'); | ||
} | ||
|
||
const task = await this.taskService.editTask(user, editTask); | ||
const task = await this.taskService.edit(user, editTask); | ||
if (!task) { | ||
throw new NotFoundException('Task not found'); | ||
} | ||
|
@@ -90,7 +90,7 @@ export class TaskController { | |
@GetUser() user: UserEntity, | ||
@Param('id', ParseIntPipe) taskId: number, | ||
): Promise<void> { | ||
const isTaskRemoved = await this.taskService.deleteTask(user, taskId); | ||
const isTaskRemoved = await this.taskService.delete(user, taskId); | ||
if (!isTaskRemoved) throw new NotFoundException('Task not found'); | ||
return; | ||
} | ||
|
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.
fetchById because we don't know if we fetch all or not.
You could use [serviceName].fetchAll or fetchOne and albo fetchById