Skip to content

Commit

Permalink
Merge pull request #126 from CyriacduChatenet/fix/api-errors
Browse files Browse the repository at this point in the history
fix(api): endpoints errors
  • Loading branch information
CyriacduChatenet committed Jul 22, 2023
2 parents ba51831 + 1895106 commit e5e9508
Show file tree
Hide file tree
Showing 37 changed files with 565 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ export class ActivityClosingDayController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Create an activity closing day' })
@ApiCreatedResponse({ description: 'Activity closing day created successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiBadRequestResponse({ description: 'Unauthorized to create ActivityClosingDay' })
create(@Body() createActivityClosingDayDto: CreateActivityClosingDayDto) {
return this.activityClosingDayService.create(createActivityClosingDayDto);
}

@Get()
@ApiOperation({ summary: 'Get all activity closing days' })
@ApiOkResponse({ description: 'Successful operation' })
@ApiNotFoundResponse({ description: 'List of ActivityClosingDay not found' })
findAll(@Query() queries: ApiLimitResourceQuery) {
return this.activityClosingDayService.findAll(queries);
}
Expand All @@ -57,8 +58,7 @@ export class ActivityClosingDayController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Update an activity closing day' })
@ApiOkResponse({ description: 'Activity closing day updated successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to update ActivityClosingDay' })
update(@Param('id') id: string, @Body() updateActivityClosingDayDto: UpdateActivityClosingDayDto) {
return this.activityClosingDayService.update(id, updateActivityClosingDayDto);
}
Expand All @@ -70,7 +70,7 @@ export class ActivityClosingDayController {
@ApiOperation({ summary: 'Delete an activity closing day' })
@ApiOkResponse({ description: 'Activity closing day deleted successfully' })
@ApiNotFoundResponse({ description: 'Activity closing day not found' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to delete ActivityClosingDay' })
remove(@Param('id') id: string) {
return this.activityClosingDayService.remove(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,48 @@ export class ActivityClosingDayService {
try {
return await this.activityClosingDayRepository.createActivityClosingDay(createActivityClosingDayDto)
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: 'Unauthorized to create ActivityClosingDay',
error,
});
}
}

async findAll(queries: ApiLimitResourceQuery) {
try {
return await this.activityClosingDayRepository.findAllActivityClosingDay(queries);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException('List of ActivityClosingDay not found');
}
}

async findOne(id: string) {
try {
return await this.activityClosingDayRepository.findOneActivityClosingDay(id);
} catch (error) {
throw new UnauthorizedException(error);
throw new NotFoundException(`ActivityClosingDay not found with id: ${id}`);
}
}

async update(id: string, updateActivityClosingDayDto: UpdateActivityClosingDayDto) {
try {
return await this.activityClosingDayRepository.updateActivityClosingDay(id, updateActivityClosingDayDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to update ActivityClosingDay with id: ${id}`,
error,
});
}
}

async remove(id: string) {
try {
return await this.activityClosingDayRepository.removeActivityClosingDay(id);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to delete ActivityClosingDay with id: ${id}`,
error
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ActivityDetailController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Create an activity detail' })
@ApiCreatedResponse({ description: 'Activity detail created successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to create ActivityDetail' })
create(@Body() createActivityDetailDto: CreateActivityDetailDto) {
return this.activityDetailService.create(createActivityDetailDto);
}
Expand All @@ -32,6 +32,7 @@ export class ActivityDetailController {
@Throttle(1000, 60)
@ApiOperation({ summary: 'Get all activity details' })
@ApiOkResponse({ description: 'Successful operation' })
@ApiNotFoundResponse({ description: 'List of ActivityDetail not found' })
findAll(@Query() queries: ApiLimitResourceQuery) {
return this.activityDetailService.findAll(queries);
}
Expand All @@ -52,8 +53,7 @@ export class ActivityDetailController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Update an activity detail' })
@ApiOkResponse({ description: 'Activity detail updated successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to update ActivityDetail' })
update(
@Param('id') id: string,
@Body() updateActivityDetailDto: UpdateActivityDetailDto,
Expand All @@ -68,8 +68,7 @@ export class ActivityDetailController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete an activity detail' })
@ApiOkResponse({ description: 'Activity detail deleted successfully' })
@ApiNotFoundResponse({ description: 'Activity detail not found' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to delete ActivityDetail' })
remove(@Param('id') id: string) {
return this.activityDetailService.remove(id);
}
Expand Down
25 changes: 20 additions & 5 deletions apps/api/src/activity/activity-detail/activity-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,54 @@ export class ActivityDetailService {
try {
return await this.activityDetailRepository.createActivityDetail(createActivityDetailDto)
} catch (err) {
throw new UnauthorizedException(err);
throw new UnauthorizedException({
message: 'Unauthorized to create ActivityDetail',
err,
});
}
}

async findAll(queries: ApiLimitResourceQuery) {
try {
return await this.activityDetailRepository.findAllActivityDetail(queries);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: 'List of ActivityDetail not found',
error,
});
}
}

async findOne(id: string) {
try {
return await this.activityDetailRepository.findOneActivityDetail(id);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: `ActivityDetail not found with id: ${id}`,
error,
});
}
}

async update(id: string, updateActivityDetailDto: UpdateActivityDetailDto) {
try {
return await this.activityDetailRepository.updateActivityDetail(id, updateActivityDetailDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to update ActivityDetail with id: ${id}`,
error,
});
}
}

async remove(id: string) {
try {
return await this.activityDetailRepository.removeActivityDetail(id);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to remove ActivityDetail with id: ${id}`,
error,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ export class ActivityScheduleController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Create an activity schedule' })
@ApiCreatedResponse({ description: 'Activity schedule created successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to create ActivitySchedule' })
create(@Body() createActivityScheduleDto: CreateActivityScheduleDto) {
return this.activityScheduleService.create(createActivityScheduleDto);
}

@Get()
@ApiOperation({ summary: 'Get all activity schedules' })
@ApiOkResponse({ description: 'Successful operation' })
@ApiNotFoundResponse({ description: 'List of ActivitySchedule not found' })
findAll(@Query() queries: ApiLimitResourceQuery) {
return this.activityScheduleService.findAll(queries);
}
Expand All @@ -47,8 +48,7 @@ export class ActivityScheduleController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Update an activity schedule' })
@ApiOkResponse({ description: 'Activity schedule updated successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to update ActivitySchedule' })
update(
@Param('id') id: string,
@Body() updateActivityScheduleDto: UpdateActivityScheduleDto,
Expand All @@ -62,8 +62,7 @@ export class ActivityScheduleController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete an activity schedule' })
@ApiOkResponse({ description: 'Activity schedule deleted successfully' })
@ApiNotFoundResponse({ description: 'Activity schedule not found' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to delete ActivitySchedule' })
remove(@Param('id') id: string) {
return this.activityScheduleService.remove(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,54 @@ export class ActivityScheduleService {
try {
return await this.activityScheduleRepository.createActivitySchedule(createActivityScheduleDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: 'Unauthorized to create ActivitySchedule',
error,
});
}
}

async findAll(queries: ApiLimitResourceQuery) {
try {
return await this.activityScheduleRepository.findAllActivitySchedule(queries);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: 'List of ActivitySchedule not found',
error,
});
}
}

async findOne(id: string) {
try {
return await this.activityScheduleRepository.findOneActivitySchedule(id);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: `ActivitySchedule not found with id: ${id}`,
error,
});
}
}

async update(id: string, updateActivityScheduleDto: UpdateActivityScheduleDto) {
try {
return await this.activityScheduleRepository.updateActivitySchedule(id, updateActivityScheduleDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to update ActivitySchedule with id: ${id}`,
error,
});
}
}

async remove(id: string) {
try {
return await this.activityScheduleRepository.removeActivitySchedule(id);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to delete ActivitySchedule with id: ${id}`,
error,
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export class ActivityImageController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Create an activity image' })
@ApiCreatedResponse({ description: 'Activity image created successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to create ActivityImage' })
create(@Body() createActivityImageDto: CreateActivityImageDto) {
return this.activityImageService.create(createActivityImageDto);
}

@Get()
@ApiOperation({ summary: 'Get all activity images' })
@ApiOkResponse({ description: 'Successful operation' })
@ApiNotFoundResponse({ description: 'List of ActivityImage not found' })
findAll(@Query() queries: ApiLimitResourceQuery) {
return this.activityImageService.findAll(queries);
}
Expand All @@ -50,8 +51,7 @@ export class ActivityImageController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Update an activity image' })
@ApiOkResponse({ description: 'Activity image updated successfully' })
@ApiBadRequestResponse({ description: 'Invalid input data' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to update ActivityImage' })
update(
@Param('id') id: string,
@Body() updateActivityImageDto: UpdateActivityImageDto,
Expand All @@ -66,8 +66,7 @@ export class ActivityImageController {
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete an activity image' })
@ApiOkResponse({ description: 'Activity image deleted successfully' })
@ApiNotFoundResponse({ description: 'Activity image not found' })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@ApiUnauthorizedResponse({ description: 'Unauthorized to delete ActivityImage' })
remove(@Param('id') id: string) {
return this.activityImageService.remove(id);
}
Expand Down
25 changes: 20 additions & 5 deletions apps/api/src/activity/activity-image/activity-image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,54 @@ export class ActivityImageService {
try {
return await this.activityImageRepository.createActivityImage(createActivityImageDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: 'Unauthorized to create ActivityImage',
error,
});
}
}

async findAll(queries: ApiLimitResourceQuery) {
try {
return await this.activityImageRepository.findAllActivityImage(queries);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: 'List of ActivityImage not found',
error,
});
}
}

findOne(id: string) {
try {
return this.activityImageRepository.findOneActivityImage(id);
} catch (error) {
throw new NotFoundException(error);
throw new NotFoundException({
message: `ActivityImage not found with id: ${id}`,
error,
});
}
}

update(id: string, updateActivityImageDto: UpdateActivityImageDto) {
try {
return this.activityImageRepository.updateActivityImage(id, updateActivityImageDto);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to update ActivityImage with id: ${id}`,
error,
});
}
}

remove(id: string) {
try {
return this.activityImageRepository.removeActivityImage(id);
} catch (error) {
throw new UnauthorizedException(error);
throw new UnauthorizedException({
message: `Unauthorized to remove ActivityImage with id: ${id}`,
error,
});
}
}
}
Loading

2 comments on commit e5e9508

@vercel
Copy link

@vercel vercel bot commented on e5e9508 Jul 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e5e9508 Jul 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.