Skip to content

Commit

Permalink
rebased on develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Ishimwe committed Sep 18, 2024
1 parent e13852e commit 984dc05
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 @@ -27,6 +27,7 @@ import { checkloginAttepmts } from '../helpers/logintracker'
import { Rating } from '../models/ratings'
import { Invitation } from '../models/invitation.model'
import isAssigned from '../helpers/isAssignedToProgramOrCohort'
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 @@ -509,7 +510,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 @@ -520,7 +520,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 984dc05

Please sign in to comment.