Files
formbricks-formbricks/apps/web/lib/cache/organization.ts
Piyush Gupta 1af1a92fec feat: granular team roles (#3975)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
Co-authored-by: Johannes <johannes@formbricks.com>
2024-11-08 06:03:14 +00:00

43 lines
901 B
TypeScript

import { revalidateTag } from "next/cache";
interface RevalidateProps {
id?: string;
userId?: string;
environmentId?: string;
count?: boolean;
}
export const organizationCache = {
tag: {
byId(id: string) {
return `organizations-${id}`;
},
byUserId(userId: string) {
return `users-${userId}-organizations`;
},
byEnvironmentId(environmentId: string) {
return `environments-${environmentId}-organizations`;
},
byCount() {
return "organizations-count";
},
},
revalidate({ id, userId, environmentId, count }: RevalidateProps): void {
if (id) {
revalidateTag(this.tag.byId(id));
}
if (userId) {
revalidateTag(this.tag.byUserId(userId));
}
if (environmentId) {
revalidateTag(this.tag.byEnvironmentId(environmentId));
}
if (count) {
revalidateTag(this.tag.byCount());
}
},
};