From c1385c218a027c0581213013d7f4ecc755b01451 Mon Sep 17 00:00:00 2001 From: GloireMutaliko21 <mufunyig@gmail.com> Date: Wed, 27 Nov 2024 12:35:06 +0200 Subject: [PATCH] fix: improve by coderabbit --- packages/core/src/subscription/subscription.controller.ts | 4 +++- packages/core/src/subscription/subscription.service.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/subscription/subscription.controller.ts b/packages/core/src/subscription/subscription.controller.ts index 5da80038fcb..27f342ded05 100644 --- a/packages/core/src/subscription/subscription.controller.ts +++ b/packages/core/src/subscription/subscription.controller.ts @@ -47,6 +47,7 @@ export class SubscriptionController extends CrudController<Subscription> { description: 'Record not found' }) @Get(':id') + @UseValidationPipe() async findById( @Param('id', UUIDValidationPipe) id: ID, @Query() params: OptionParams<Subscription> @@ -63,7 +64,7 @@ export class SubscriptionController extends CrudController<Subscription> { status: HttpStatus.BAD_REQUEST, description: 'Invalid input, The response body may contain clues as to what went wrong' }) - @HttpCode(HttpStatus.ACCEPTED) + @HttpCode(HttpStatus.CREATED) @Post() @UseValidationPipe({ whitelist: true }) async create(@Body() entity: CreateSubscriptionDTO): Promise<ISubscription> { @@ -81,6 +82,7 @@ export class SubscriptionController extends CrudController<Subscription> { }) @HttpCode(HttpStatus.ACCEPTED) @Delete('/:id') + @UseValidationPipe({ whitelist: true }) async delete( @Param('id', UUIDValidationPipe) id: ID, @Query() options: SubscriptionFindInputDTO diff --git a/packages/core/src/subscription/subscription.service.ts b/packages/core/src/subscription/subscription.service.ts index d09657aa865..80457dd91f8 100644 --- a/packages/core/src/subscription/subscription.service.ts +++ b/packages/core/src/subscription/subscription.service.ts @@ -63,11 +63,11 @@ export class SubscriptionService extends TenantAwareCrudService<Subscription> { */ async unsubscribe(id: ID, options?: ISubscriptionFindInput): Promise<DeleteResult> { try { - const { entity, entityId } = options; + const { entity, entityId } = options || {}; const userId = RequestContext.currentUserId(); return await super.delete({ id, userId, entity, entityId }); } catch (error) { - throw new BadRequestException(error); + throw new BadRequestException('Failed to unsubscribe from entity', error); } } }