Skip to content

Commit

Permalink
Added the ttl and coordinator delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Ishimwe committed Sep 18, 2024
1 parent ca6165f commit cb2a994
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Octokit } from '@octokit/rest'
import { checkloginAttepmts } from '../helpers/logintracker'
import { Rating } from '../models/ratings'
import { Invitation } from '../models/invitation.model'
import { pushNotification } from '../utils/notification/pushNotification'
const octokit = new Octokit({ auth: `${process.env.GH_TOKEN}` })

const SECRET: string = process.env.SECRET ?? 'test_secret'
Expand Down Expand Up @@ -499,7 +500,6 @@ const resolvers: any = {

async deleteUser(_: any, { input }: any, context: { userId: any }) {
const requester = await User.findById(context.userId)
console.log(input)
if (!requester) {
throw new Error('Requester does not exist')
}
Expand All @@ -510,7 +510,30 @@ const resolvers: any = {
if (!userToDelete) {
throw new Error('User to be deleted does not exist')
}

if (userToDelete.role === 'coordinator') {
const hasCohort = await Cohort.findOne({ coordinator: input.id })
if (hasCohort) {
await Cohort.findOneAndReplace(
{ coordinator: input.id },
{ coordinator: null }
)
await pushNotification(
context.userId,
`You have deleted the coordinator of ${hasCohort.name}, Assign the new coordinator`,
context.userId
)
}
} else if (userToDelete.role === 'ttl') {
const hasTeam = await Team.findOne({ ttl: input.id })
if (hasTeam) {
await Team.findOneAndReplace({ ttl: input.id }, { ttl: null })
await pushNotification(
context.userId,
`You have deleted the TTL of ${Team.name}, Assign the new TTL`,
context.userId
)
}
}
await User.findByIdAndDelete(input.id)
await Profile.deleteOne({ user: input.id })
return { message: 'User deleted successfully' }
Expand Down

0 comments on commit cb2a994

Please sign in to comment.