Skip to content

Commit

Permalink
Merge pull request #265 from internxt/feat/check-if-user-exists-or-ha…
Browse files Browse the repository at this point in the history
…s-subscription
  • Loading branch information
sg-gs authored Feb 1, 2024
2 parents 7a06da7 + 015213a commit d910aa0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,66 @@ export class UserController {
}
}

@UseGuards(ThrottlerGuard)
@Throttle({
long: {
ttl: 3600,
limit: 5,
},
})
@Get('/user/:email')
@HttpCode(201)
@ApiOperation({
summary:
'Get the user data by email and check if the user has subscription',
})
@ApiOkResponse({
description: 'Get the user data by email',
})
@ApiBadRequestResponse({ description: 'Missing required fields' })
@ApiParam({
name: 'email',
type: String,
})
async getUserByEmail(
@Param('email') email: User['email'],
@Res({ passthrough: true }) res: Response,
) {
try {
const user = await this.userUseCases.getUserByUsername(email);
if (!user) {
throw new NotFoundException();
}

const userHasSubscriptions =
await this.userUseCases.hasUserBeenSubscribedAnyTime(
user.email,
user.bridgeUser,
user.userId,
);

return res
.status(200)
.json({ user: user, hasSubscriptions: userHasSubscriptions });
} catch (err) {
let errorMessage = err.message;

if (err instanceof NotFoundException) {
res.status(HttpStatus.NOT_FOUND);
} else {
new Logger().error(
`[AUTH/GET-USER-BY-EMAIL] ERROR: ${(err as Error).message}, STACK: ${
(err as Error).stack
}`,
);
res.status(HttpStatus.INTERNAL_SERVER_ERROR);
errorMessage = 'Internal Server Error';
}

return { error: errorMessage };
}
}

@UseGuards(ThrottlerGuard)
@Throttle({
long: {
Expand Down

0 comments on commit d910aa0

Please sign in to comment.