Skip to content

Commit

Permalink
πŸ”’ Make sure if pro got expired return null for pro features from API …
Browse files Browse the repository at this point in the history
…(#yoginth/eng-100-make-sure-if-pro-got-expired-return-null-for-pro-features)

Summary: Handling pro feature access based on subscription status.

Highlights:

β€’ Added `proStatus` to the database transaction for profile data.
β€’ Introduced `isPro` variable to check if the user has a pro subscription.
β€’ Modified `status` and `theme` in the response to return null if `isPro` is not valid.

Read more: https://pierre.co/hey/hey/yoginth/eng-100-make-sure-if-pro-got-expired-return-null-for-pro-features
  • Loading branch information
Yoginth authored and Pierre committed Sep 27, 2024
1 parent 78fb24a commit 7364e36
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions apps/api/src/routes/profile/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,25 @@ export const get = [
.json({ result: JSON.parse(cachedData), success: true });
}

const [profilePermission, profileStatus, profileTheme] =
const [profilePermission, proStatus, profileStatus, profileTheme] =
await prisma.$transaction([
prisma.profilePermission.findFirst({
where: {
permissionId: SUSPENDED_PERMISSION_ID,
profileId: id as string
}
}),
prisma.pro.findFirst({ where: { id: id as string } }),
prisma.profileStatus.findFirst({ where: { id: id as string } }),
prisma.profileTheme.findFirst({ where: { id: id as string } })
]);

const isPro = proStatus?.id;
const response: ProfileDetails = {
isSuspended:
profilePermission?.permissionId === SUSPENDED_PERMISSION_ID,
status: profileStatus || null,
theme: (profileTheme as ProfileTheme) || null
status: isPro ? profileStatus || null : null,
theme: isPro ? (profileTheme as ProfileTheme) || null : null
};

await setRedis(cacheKey, response);
Expand Down

0 comments on commit 7364e36

Please sign in to comment.