diff --git a/src/graphql/resolvers.ts b/src/graphql/resolvers.ts index 513d060..2962352 100644 --- a/src/graphql/resolvers.ts +++ b/src/graphql/resolvers.ts @@ -33,20 +33,15 @@ export const resolvers = { }), getStatsRange: async ( _parent: unknown, - data: { startDate: string; endDate: string } + data: { startDate: Date; endDate: Date } // _ctx: unknown ) => { const { startDate, endDate } = data; - - if (startDate === "" || endDate === "") { - return null; - } - return await prisma.dailyStats.findMany({ where: { createdAt: { - gt: new Date(startDate), - lte: new Date(endDate) + gt: startDate, + lte: endDate } }, orderBy: { @@ -65,12 +60,21 @@ export const resolvers = { data: { groupID: number } // _ctx: unknown ) => { - const { groupID } = data; - return await prisma.groups.findUnique({ + const groupIDInt = BigInt(data.groupID); + + const group = await prisma.groups.findUnique({ where: { - telegramID: groupID + telegramID: groupIDInt } }); + + if (group === null) { + const groups = await prisma.groups.findMany({ + orderBy: { name: "asc" } + }); + } + + return group; } }, Mutation: { @@ -173,7 +177,7 @@ export const resolvers = { addGroup: async ( _parent: unknown, data: { - groupID: number; + groupID: string; groupName: string; groupUsername: string; mutationKey?: string; @@ -181,6 +185,7 @@ export const resolvers = { // _ctx: unknown ) => { const { groupID, groupName, groupUsername, mutationKey } = data; + const groupIDInt = BigInt(groupID); if (env !== "development") { if (!mutationKey) { @@ -193,7 +198,7 @@ export const resolvers = { } const existingGroup = await prisma.groups.findUnique({ - where: { telegramID: groupID } + where: { telegramID: groupIDInt } }); if (existingGroup !== null) { @@ -214,7 +219,7 @@ export const resolvers = { return await prisma.groups.create({ data: { - telegramID: groupID, + telegramID: groupIDInt, name: groupName } }); @@ -225,6 +230,7 @@ export const resolvers = { // _ctx: unknown ) => { const { groupID, linksDeleted, mutationKey } = data; + const groupIDInt = BigInt(groupID); if (env !== "development") { if (!mutationKey) { @@ -237,7 +243,7 @@ export const resolvers = { } return await prisma.groups.update({ - where: { telegramID: groupID }, + where: { telegramID: groupIDInt }, data: { linksDeleted: { increment: linksDeleted } } }); }, diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 039fcbf..0e44ebf 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -9,19 +9,19 @@ const typeDefs = /* GraphQL */ ` getTodayStats: DailyStats! getStatsRange(startDate: String!, endDate: String!): [DailyStats] getTotalStats: TotalStats! - getGroupStats(groupID: BigInt!): Groups + getGroupStats(groupID: String!): Groups } type Mutation { init(mutationKey: String): String! cronJob(mutationKey: String): TotalStats! addGroup( - groupID: BigInt! + groupID: String! groupName: String! groupUsername: String mutationKey: String ): Groups! incrementGroup( - groupID: BigInt! + groupID: String! linksDeleted: Int! mutationKey: String ): Groups! diff --git a/src/prisma/generated/internal/class.ts b/src/prisma/generated/internal/class.ts index 4086a03..c1ebff0 100644 --- a/src/prisma/generated/internal/class.ts +++ b/src/prisma/generated/internal/class.ts @@ -23,7 +23,7 @@ const config: runtime.GetPrismaClientConfig = { "value": "prisma-client" }, "output": { - "value": "/home/lucid/work/WKC/no-twitter-bot-stats/src/prisma/generated", + "value": "/home/lucid/work/cove-gitea/no-twitter-bot-stats/src/prisma/generated", "fromEnvVar": null }, "config": { @@ -37,7 +37,7 @@ const config: runtime.GetPrismaClientConfig = { } ], "previewFeatures": [], - "sourceFilePath": "/home/lucid/work/WKC/no-twitter-bot-stats/src/prisma/schema.prisma", + "sourceFilePath": "/home/lucid/work/cove-gitea/no-twitter-bot-stats/src/prisma/schema.prisma", "isCustomOutput": true }, "relativePath": "..",