mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-05-04 04:33:10 +00:00
Initial Commit
This commit is contained in:
commit
f3e2f01bd7
150 changed files with 13612 additions and 0 deletions
86
lib/org-limit.ts
Normal file
86
lib/org-limit.ts
Normal file
|
@ -0,0 +1,86 @@
|
|||
import { auth } from "@clerk/nextjs";
|
||||
|
||||
import { db } from "@/lib/db";
|
||||
import { MAX_FREE_BOARDS } from "@/constants/boards";
|
||||
|
||||
export const incrementAvailableCount = async () => {
|
||||
const { orgId } = auth();
|
||||
|
||||
if (!orgId) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
const orgLimit = await db.orgLimit.findUnique({
|
||||
where: { orgId },
|
||||
});
|
||||
|
||||
if (orgLimit) {
|
||||
await db.orgLimit.update({
|
||||
where: { orgId },
|
||||
data: { count: orgLimit.count + 1 },
|
||||
});
|
||||
} else {
|
||||
await db.orgLimit.create({
|
||||
data: { orgId, count: 1 },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const decreaseAvailableCount = async () => {
|
||||
const { orgId } = auth();
|
||||
|
||||
if (!orgId) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
const orgLimit = await db.orgLimit.findUnique({
|
||||
where: { orgId },
|
||||
});
|
||||
|
||||
if (orgLimit) {
|
||||
await db.orgLimit.update({
|
||||
where: { orgId },
|
||||
data: { count: orgLimit.count > 0 ? orgLimit.count - 1 : 0 },
|
||||
});
|
||||
} else {
|
||||
await db.orgLimit.create({
|
||||
data: { orgId, count: 1 },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const hasAvailableCount = async () => {
|
||||
const { orgId } = auth();
|
||||
|
||||
if (!orgId) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
const orgLimit = await db.orgLimit.findUnique({
|
||||
where: { orgId },
|
||||
});
|
||||
|
||||
if (!orgLimit || orgLimit.count < MAX_FREE_BOARDS) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const getAvailableCount = async () => {
|
||||
const { orgId } = auth();
|
||||
|
||||
if (!orgId) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const orgLimit = await db.orgLimit.findUnique({
|
||||
where: { orgId },
|
||||
});
|
||||
|
||||
if (!orgLimit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return orgLimit.count;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue