Skip to content

Commit

Permalink
feat: add delete for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Dec 9, 2024
1 parent 224aa46 commit f4b7f8c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modules/subscriptions/subscriptions.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from 'node:crypto';

Check failure on line 1 in src/modules/subscriptions/subscriptions.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/subscriptions/subscriptions.controller.ts#L1

Run autofix to sort these imports! (simple-import-sort/imports)

import { Body, Controller, Headers, Param, Patch, Post, UnauthorizedException } from '@nestjs/common';
import { Body, Controller, Delete, Headers, Param, Patch, Post, UnauthorizedException } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { ApiConfigService } from '../../../src/shared/services/api-config.service';
Expand Down Expand Up @@ -89,4 +89,9 @@ export class SubscriptionsController {
updateSubscription(@Param('id') id: string, @Body() props: UpdateSubscriptionDto) {
return this.subscriptionService.updateSubscription(id, props);
}

@Delete(':id')
deleteSubscription(@Param('id') id: string) {
return this.subscriptionService.deleteSubscription(id);
}
}
4 changes: 4 additions & 0 deletions src/modules/subscriptions/subscriptions.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ export class SubscriptionRepository {
create(entityLike: DeepPartial<SubscriptionEntity>) {
return this.repository.create(entityLike);
}

delete(id: string) {
return this.repository.delete(id);
}
}
12 changes: 12 additions & 0 deletions src/modules/subscriptions/subscriptions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ export class SubscriptionsService {

await this.subscriptionRepository.save(s);
}

async deleteSubscription(id: string) {
const s = await this.subscriptionRepository.findOne({ where: { _id: new ObjectId(id) } });

if (!s) {
throw new NotFoundException('subscription not found');
}

await this.subscriptionRepository.delete(id);

await this.redis.call('CF.DEL', 'SUBSCRIPTIONS', s.subscriber);
}
}

0 comments on commit f4b7f8c

Please sign in to comment.