Skip to content

Commit

Permalink
fix(api-service): return null if user does not exist (#7586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jainpawan21 authored Jan 25, 2025
1 parent 73e2232 commit 5cf537c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .source
1 change: 1 addition & 0 deletions apps/api/src/.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ PLAIN_CARDS_HMAC_SECRET_KEY='PLAIN_CARDS_HMAC_SECRET_KEY'

NOVU_INTERNAL_SECRET_KEY=
NOVU_SECRET_KEY='NOVU_SECRET_KEY'

# expressed in seconds or a string describing a time span [zeit/ms](https://github.com/zeit/ms.js). Eg: 60, "2 days", "10h", "7d"
SUBSCRIBER_WIDGET_JWT_EXPIRATION_TIME='15 days'
28 changes: 25 additions & 3 deletions apps/api/src/app/support/usecases/plain-cards.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export class PlainCardsUsecase {
private userRepository: UserRepository
) {}
async fetchCustomerDetails(command: PlainCardsCommand) {
const key = process.env.NOVU_REGION === 'eu-west-2' ? 'customer-details-eu' : 'customer-details-us';

const key = `customer-details-${process.env.NOVU_REGION}`;
if (!command?.customer?.externalId) {
return {
data: {},
Expand All @@ -51,7 +50,7 @@ export class PlainCardsUsecase {
},
{
componentText: {
text: 'This user is not yet registered on Novu',
text: 'This user is not yet registered in this region',
},
},
],
Expand All @@ -61,6 +60,29 @@ export class PlainCardsUsecase {
}

const organizations = await this.organizationRepository.findUserActiveOrganizations(command?.customer?.externalId);
if (!organizations) {
return {
data: {},
cards: [
{
key,
components: [
{
componentSpacer: {
spacerSize: 'S',
},
},
{
componentText: {
text: 'This user is not yet registered in this region',
},
},
],
},
],
};
}

const sessions = await this.userRepository.findUserSessions(command?.customer?.externalId);

return {
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/config/env.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const envValidators = {
API_ROOT_URL: url(),
NOVU_INVITE_TEAM_MEMBER_NUDGE_TRIGGER_IDENTIFIER: str({ default: undefined }),
SUBSCRIBER_WIDGET_JWT_EXPIRATION_TIME: str({ default: '15 days' }),
NOVU_REGION: str({ default: 'local' }),

// Novu Cloud third party services
...(processEnv.IS_SELF_HOSTED !== 'true' &&
Expand Down

0 comments on commit 5cf537c

Please sign in to comment.