Merge pull request #566 from documenso/feat/plan-limits

feat: plan limits
This commit is contained in:
Lucas Smith
2023-10-17 14:30:18 +11:00
committed by GitHub
35 changed files with 755 additions and 291 deletions

View File

@ -1,5 +1,3 @@
import { Role, User } from '@documenso/prisma/client';
const isAdmin = (user: User) => user.roles.includes(Role.ADMIN);
export { isAdmin };
export const isAdmin = (user: User) => user.roles.includes(Role.ADMIN);

View File

@ -33,7 +33,8 @@
"pdf-lib": "^1.17.1",
"react": "18.2.0",
"stripe": "^12.7.0",
"ts-pattern": "^5.0.5"
"ts-pattern": "^5.0.5",
"zod": "^3.21.4"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",

View File

@ -9,9 +9,7 @@ export const getUsersWithSubscriptionsCount = async () => {
return await prisma.user.count({
where: {
Subscription: {
some: {
status: SubscriptionStatus.ACTIVE,
},
status: SubscriptionStatus.ACTIVE,
},
},
});

View File

@ -0,0 +1,9 @@
import { NextRequest } from 'next/server';
export const toNextRequest = (req: Request) => {
const headers = Object.fromEntries(req.headers.entries());
return new NextRequest(req, {
headers: headers,
});
};

View File

@ -0,0 +1,28 @@
import { NextApiResponse } from 'next';
import { NextResponse } from 'next/server';
type NarrowedResponse<T> = T extends NextResponse
? NextResponse
: T extends NextApiResponse<infer U>
? NextApiResponse<U>
: never;
export const withStaleWhileRevalidate = <T>(
res: NarrowedResponse<T>,
cacheInSeconds = 60,
staleCacheInSeconds = 300,
) => {
if ('headers' in res) {
res.headers.set(
'Cache-Control',
`public, s-maxage=${cacheInSeconds}, stale-while-revalidate=${staleCacheInSeconds}`,
);
} else {
res.setHeader(
'Cache-Control',
`public, s-maxage=${cacheInSeconds}, stale-while-revalidate=${staleCacheInSeconds}`,
);
}
return res;
};

View File

@ -7,7 +7,7 @@ export type GetSubscriptionByUserIdOptions = {
};
export const getSubscriptionByUserId = async ({ userId }: GetSubscriptionByUserIdOptions) => {
return prisma.subscription.findFirst({
return await prisma.subscription.findFirst({
where: {
userId,
},