mirror of
https://github.com/linkwarden/linkwarden.git
synced 2026-06-28 14:55:49 +00:00
30 lines
743 B
TypeScript
30 lines
743 B
TypeScript
import { prisma } from "@linkwarden/prisma";
|
|
|
|
export async function countUnprocessedBillableLinks() {
|
|
const billedOwnerIds = process.env.STRIPE_SECRET_KEY
|
|
? (
|
|
await prisma.user.findMany({
|
|
where: {
|
|
OR: [
|
|
{ subscriptions: { is: { active: true } } },
|
|
{ parentSubscription: { is: { active: true } } },
|
|
],
|
|
},
|
|
select: { id: true },
|
|
})
|
|
).map((u) => u.id)
|
|
: undefined;
|
|
|
|
const count = await prisma.link.count({
|
|
where: {
|
|
lastPreserved: null,
|
|
NOT: { url: null },
|
|
...(billedOwnerIds && billedOwnerIds.length
|
|
? { collection: { ownerId: { in: billedOwnerIds } } }
|
|
: {}),
|
|
},
|
|
});
|
|
|
|
return count;
|
|
}
|