-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(api): Subscriber deletion side-effects #6872
Conversation
)?.[0]; | ||
|
||
expect(deletedSubscriber.deleted).to.equal(true); | ||
const subscriber = await subscriberRepository.findBySubscriberId(session.environment._id, '123'); |
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.
Simplify the E2E so that the findDeleted
can be removed.
@@ -51,10 +47,9 @@ describe('Remove Subscriber', function () { | |||
organizationId: session.organization._id, | |||
}) | |||
); | |||
throw new Error('Should not reach here'); | |||
expect(true, 'Should never reach this statement').to.be.false; |
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.
A small refactoring without throwing an error will trigger the catch block again and will provide a better message for the test results.
}), | ||
}); | ||
}), | ||
this.invalidateCache.invalidateQuery({ |
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.
Clear inbox entries from cache
_environmentId: subscriber._environmentId, | ||
_organizationId: subscriber._organizationId, | ||
subscriberId: subscriber.subscriberId, | ||
await this.subscriberRepository.withTransaction(async () => { |
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.
Delete all related records atomically. Postgres, I miss you!
@@ -157,55 +157,19 @@ export class SubscriberRepository extends BaseRepository<SubscriberDBModel, Subs | |||
); | |||
} | |||
|
|||
async delete(query: SubscriberDeleteQuery) { |
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.
Clean ups for unused methods
@@ -28,13 +28,6 @@ export class PreferencesRepository extends BaseRepository<PreferencesDBModel, Pr | |||
return this.mapEntity(item); | |||
} | |||
|
|||
async delete(query: PreferencesQuery) { | |||
const item = await this.findOne({ _id: query._id, _environmentId: query._environmentId }); |
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.
There is no need for an extra query when trying to delete a record. The number of affected rows returned by mongoose indicates if the record was found or not.
}); | ||
}); | ||
|
||
if (deletedSubscriberCount === 0) { |
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.
Usually, I prefer always returning a 2xx even if the record is already deleted but since this is a breaking change for the API, I preserved the previous 404 error.
apps/api/src/app/subscribers/usecases/remove-subscriber/remove-subscriber.spec.ts
Outdated
Show resolved
Hide resolved
1ace52f
to
c544a89
Compare
apps/api/src/app/subscribers/usecases/remove-subscriber/remove-subscriber.usecase.ts
Outdated
Show resolved
Hide resolved
apps/api/src/app/subscribers/usecases/remove-subscriber/remove-subscriber.usecase.ts
Outdated
Show resolved
Hide resolved
apps/api/src/app/subscribers/usecases/remove-subscriber/remove-subscriber.usecase.ts
Show resolved
Hide resolved
c544a89
to
e5f8b6c
Compare
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
cc62ac9
to
c75065f
Compare
c75065f
to
ce822b4
Compare
1. Simplify the delete method to delete a subscriber without fetching them first. 2. Remove unused methods
ce822b4
to
98bf829
Compare
libs/application-generic/src/usecases/upsert-preferences/upsert-preferences.usecase.ts
Outdated
Show resolved
Hide resolved
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.
💯
…t-preferences.usecase.ts Co-authored-by: Richard Fontein <32132657+rifont@users.noreply.github.com>
What changed? Why was the change needed?
Clear subscribers along with all their related data and their cached entries