MCPcopy Index your code
hub / github.com/sqlchat/sqlchat / getCurrentMonthUsage

Function getCurrentMonthUsage

src/pages/api/utils/usage.ts:5–23  ·  view source on GitHub ↗
(endUser: string)

Source from the content-addressed store, hash-verified

3const prisma = new PrismaClient();
4
5export const getCurrentMonthUsage = async (endUser: string): Promise<number> => {
6 const now = new Date();
7 const start = new Date(now.getFullYear(), now.getMonth(), 1);
8 const end = new Date(now.getFullYear(), now.getMonth() + 1, 1);
9 const aggregations = await prisma.usage.aggregate({
10 _sum: {
11 count: true,
12 },
13 where: {
14 endUser: endUser,
15 createdAt: {
16 gte: start,
17 lt: end,
18 },
19 },
20 });
21
22 return aggregations._sum.count || 0;
23};
24
25// We coerce individual usage to the begining of the day to reduce the usage records.
26export const addUsage = async (endUser: string, addition: number): Promise<number> => {

Callers 1

handlerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected