Expanded groups scheme. Expanded addGroups mutation. Refactored addGroups mutation to update username and title of a group when used. Added an incrementGroups mutation that updates the new deletedLinks row in the scheme.
This commit is contained in:
@@ -105,10 +105,31 @@ export const resolvers = {
|
||||
},
|
||||
addGroup: async (
|
||||
_parent: unknown,
|
||||
data: { groupID: number; groupName: string }
|
||||
data: { groupID: number; groupName: string; groupUsername: string }
|
||||
// _ctx: unknown
|
||||
) => {
|
||||
const { groupID, groupName } = data;
|
||||
const { groupID, groupName, groupUsername } = data;
|
||||
|
||||
const existingGroup = await prisma.groups.findFirst({
|
||||
where: { telegramID: groupID }
|
||||
});
|
||||
|
||||
if (existingGroup !== null) {
|
||||
if (
|
||||
existingGroup.name !== groupName ||
|
||||
existingGroup.username !== groupUsername
|
||||
) {
|
||||
return await prisma.groups.update({
|
||||
where: {
|
||||
telegramID: existingGroup.telegramID
|
||||
},
|
||||
data: { name: groupName, username: groupUsername || "" }
|
||||
});
|
||||
}
|
||||
|
||||
return existingGroup;
|
||||
}
|
||||
|
||||
return await prisma.groups.create({
|
||||
data: {
|
||||
telegramID: groupID,
|
||||
@@ -116,6 +137,18 @@ export const resolvers = {
|
||||
}
|
||||
});
|
||||
},
|
||||
incrementGroup: async (
|
||||
_parent: unknown,
|
||||
data: { groupID: number; linksDeleted: number }
|
||||
// _ctx: unknown
|
||||
) => {
|
||||
const { groupID, linksDeleted } = data;
|
||||
|
||||
return await prisma.groups.update({
|
||||
where: { telegramID: groupID },
|
||||
data: { linksDeleted: { increment: linksDeleted } }
|
||||
});
|
||||
},
|
||||
increment: async (
|
||||
_parent: unknown,
|
||||
data: { link: boolean; command: boolean; trigger: boolean }
|
||||
|
||||
@@ -13,13 +13,16 @@ const typeDefs = /* GraphQL */ `
|
||||
type Mutation {
|
||||
init: String!
|
||||
cronJob: TotalStats!
|
||||
addGroup(groupID: Int, groupName: String): Groups!
|
||||
addGroup(groupID: BigInt, groupName: String, groupUsername: String): Groups!
|
||||
incrementGroup(groupID: BigInt, linksDeleted: Int): Groups!
|
||||
increment(link: Boolean, command: Boolean, trigger: Boolean): DailyStats!
|
||||
}
|
||||
|
||||
type Groups {
|
||||
telegramID: Int
|
||||
telegramID: BigInt
|
||||
name: String
|
||||
username: String
|
||||
linksDeleted: BigInt
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user