Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trainee dashboard #381

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/resolvers/2fa.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const resolvers = {
const geoData = await logGeoActivity(user, clientIpAdress)
const organizationName = user.organizations[0];
if (organizationName) {
const location = geoData.city && geoData.country_name ? `${geoData.city}-${geoData.country_name}` : null;
const location = geoData && geoData.city && geoData.country_name ? `${geoData.city}-${geoData.country_name}` : null;
await loginsCount(organizationName, location);
}

Expand Down
30 changes: 14 additions & 16 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function loginsCount(organizationName: any, recentLocation: any) {
const resolvers: any = {
Query: {
async getOrganizations(_: any, __: any, context: Context) {
;(await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])
; (await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])

return Organization.find()
},
Expand Down Expand Up @@ -168,7 +168,7 @@ const resolvers: any = {
{ organisation, username }: any,
context: Context
) {
;(await checkUserLoggedIn(context))([
; (await checkUserLoggedIn(context))([
RoleOfUser.ADMIN,
RoleOfUser.COORDINATOR,
'trainee',
Expand All @@ -180,7 +180,7 @@ const resolvers: any = {
name: organisation,
})
if (!organisationExists)
throw new Error("This Organization doesn't exist")
throw new Error('This Organization doesn\'t exist')

organisation = organisationExists.gitHubOrganisation

Expand Down Expand Up @@ -403,7 +403,6 @@ const resolvers: any = {
extensions: { code: 'AccountNotFound' },
})
}

// Check if account is active
if (user.status?.status !== 'active') {
throw new GraphQLError(
Expand Down Expand Up @@ -452,12 +451,11 @@ const resolvers: any = {
{ expiresIn: '2h' }
)

const geoData = await logGeoActivity(user, clientIpAdress) // Log activity

const geoData: any = undefined
const organizationName = user.organizations[0]
if (organizationName) {
const location =
geoData.city && geoData.country_name
geoData && geoData.city && geoData.country_name
? `${geoData.city}-${geoData.country_name}`
: null
await loginsCount(organizationName, location)
Expand Down Expand Up @@ -554,9 +552,9 @@ const resolvers: any = {
]
const org = await checkLoggedInOrganization(orgToken)
const roleExists = allRoles.includes(name)
if (!roleExists) throw new Error("This role doesn't exist")
if (!roleExists) throw new Error('This role doesn\'t exist')
const userExists = await User.findById(id)
if (!userExists) throw new Error("User doesn't exist")
if (!userExists) throw new Error('User doesn\'t exist')

const getAllUsers = await User.find({
role: RoleOfUser.ADMIN,
Expand Down Expand Up @@ -793,7 +791,7 @@ const resolvers: any = {
context: Context
) {
// check if requester is super admin
;(await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])
; (await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])
const orgExists = await Organization.findOne({ name: name })
if (action == 'approve') {
if (!orgExists) {
Expand Down Expand Up @@ -863,7 +861,7 @@ const resolvers: any = {
context: Context
) {
// the below commented line help to know if the user is an superAdmin to perform an action of creating an organization
;(await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])
; (await checkUserLoggedIn(context))([RoleOfUser.SUPER_ADMIN])
if (action == 'new') {
const orgExists = await Organization.findOne({ name: name })
if (orgExists) {
Expand Down Expand Up @@ -928,7 +926,7 @@ const resolvers: any = {
{ name, gitHubOrganisation }: any,
context: Context
) {
;(await checkUserLoggedIn(context))([
; (await checkUserLoggedIn(context))([
RoleOfUser.ADMIN,
RoleOfUser.SUPER_ADMIN,
])
Expand Down Expand Up @@ -1021,15 +1019,15 @@ const resolvers: any = {
},

async deleteOrganization(_: any, { id }: any, context: Context) {
;(await checkUserLoggedIn(context))([
; (await checkUserLoggedIn(context))([
RoleOfUser.ADMIN,
RoleOfUser.SUPER_ADMIN,
])

const organizationExists = await Organization.findOne({ _id: id })

if (!organizationExists)
throw new Error("This Organization doesn't exist")
throw new Error('This Organization doesn\'t exist')
await Cohort.deleteMany({ organization: id })
await Team.deleteMany({ organization: id })
await Phase.deleteMany({ organization: id })
Expand Down Expand Up @@ -1107,7 +1105,7 @@ const resolvers: any = {
if (password === confirmPassword) {
const user: any = await User.findOne({ email })
if (!user) {
throw new Error("User doesn't exist! ")
throw new Error('User doesn\'t exist! ')
}
user.password = password
await user.save()
Expand All @@ -1127,7 +1125,7 @@ const resolvers: any = {
if (newPassword === confirmPassword) {
const user: any = await User.findById(userId)
if (!user) {
throw new Error("User doesn't exist! ")
throw new Error('User doesn\'t exist! ')
}

if (bcrypt.compareSync(currentPassword, user.password)) {
Expand Down
4 changes: 3 additions & 1 deletion src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const Schema = gql`
description: String
}

type Rating {
type Rating {
id: ID!
user: User!
sprint: Int!
Expand All @@ -205,6 +205,8 @@ const Schema = gql`
cohort: Cohort!
average: String
feedbacks: [RatingMessageTemp]
createdAt: String
updatedAt: String
}

type AddRating {
Expand Down
Loading