Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"no-useless-catch": 0,
"@typescript-eslint/explicit-module-boundary-types": "off"
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
4,209 changes: 2,415 additions & 1,794 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"dotenv": "^16.0.1",
"ejs": "^3.1.8",
"express": "^4.18.1",
"faker": "^6.6.6",
"generate-password": "^1.7.0",
"graphql": "^16.5.0",
"graphql-subscriptions": "^2.0.0",
Expand All @@ -96,7 +95,6 @@
"@types/chai": "^4.3.3",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.6",
"@types/faker": "^6.6.9",
"@types/jsonwebtoken": "^8.5.8",
"@types/mocha": "^8.0.3",
"@types/node": "^13.13.52",
Expand Down
7 changes: 3 additions & 4 deletions src/helpers/user.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export const generateTokenOrganization = (name: string) => {
return jwt.sign({ name }, SECRET, { expiresIn: '336h' })
}

export const genericToken=(playLoad:any)=>{
return jwt.sign({...playLoad},SECRET)
}

export const genericToken = (playLoad: any) => {
return jwt.sign({ ...playLoad }, SECRET)
}

export const emailExpression =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import invitationSchema from './schema/invitation.schema'
import TableViewInvitationResolver from './resolvers/TableViewInvitationResolver'
import eventSchema from './schema/event.schema'
import './utils/cron-jobs/team-jobs'
import CommunitySchema from './schema/community.schema'
import CommunityResolver from './resolvers/community.resolver'
import faMutation from './resolvers/2fa.resolvers';

const PORT: number = parseInt(process.env.PORT!) || 4000
Expand All @@ -69,6 +71,7 @@ export const typeDefs = mergeTypeDefs([
notificationSchema,
statisticsSchema,
eventSchema,
CommunitySchema,
organizationSchema
])

Expand All @@ -91,7 +94,7 @@ export const resolvers = mergeResolvers([
Sessionresolvers,
organizationResolvers,
StatisticsResolvers,

CommunityResolver,
invitationResolvers,
TableViewInvitationResolver,
faMutation,
Expand Down
39 changes: 39 additions & 0 deletions src/models/question.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import mongoose, { Document, Schema } from 'mongoose'

interface IAnswer {
content: string
author: mongoose.Types.ObjectId // Reference to User
question: mongoose.Types.ObjectId
createdAt?: Date // Optional if not needed
}

interface IQuestion extends Document {
title: string
content: string
author: mongoose.Types.ObjectId // Reference to User
createdAt?: Date // Optional if not needed
answers: IAnswer[]
}

const answerSchema = new Schema<IAnswer>({
content: { type: String, required: true },
question: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Question',
required: true,
},
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
createdAt: { type: Date, default: Date.now },
})

const questionSchema = new Schema<IQuestion>({
title: { type: String, required: true },
content: { type: String, required: true },
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
createdAt: { type: Date, default: Date.now },
answers: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Answer' }],
})
const Answer = mongoose.model<IAnswer>('Answer', answerSchema)
const Question = mongoose.model<IQuestion>('Question', questionSchema)

export { Question, IQuestion, IAnswer, Answer }
63 changes: 39 additions & 24 deletions src/resolvers/cohort.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const resolvers = {
},
})
).filter((item) => {
const org = (item.program as InstanceType<typeof Program>)?.organization
const org = (item.program as InstanceType<typeof Program>)
?.organization
return item.program !== null && org !== null
})
} catch (error) {
Expand All @@ -74,41 +75,55 @@ const resolvers = {
})
}
},
getUserCohorts: async(_:any, { orgToken }: {orgToken: string}, context: Context)=>{
const { userId, role} = (await checkUserLoggedIn(context))([RoleOfUser.COORDINATOR, RoleOfUser.TTL, RoleOfUser.TRAINEE])
getUserCohorts: async (
_: any,
{ orgToken }: { orgToken: string },
context: Context
) => {
const { userId, role } = (await checkUserLoggedIn(context))([
RoleOfUser.COORDINATOR,
RoleOfUser.TTL,
RoleOfUser.TRAINEE,
])
const user = await User.findById(userId)
if(!user){
throw new GraphQLError("No such user found",{
if (!user) {
throw new GraphQLError('No such user found', {
extensions: {
code: "USER_NOT_FOUND"
}
code: 'USER_NOT_FOUND',
},
})
}
const org= await checkLoggedInOrganization(orgToken)
if(!org){
throw new GraphQLError("No such organization found",{
const org = await checkLoggedInOrganization(orgToken)
if (!org) {
throw new GraphQLError('No such organization found', {
extensions: {
code: "ORG_NOT_FOUND"
}
code: 'ORG_NOT_FOUND',
},
})
}
switch(role){
case RoleOfUser.COORDINATOR:

switch (role) {
case RoleOfUser.COORDINATOR: {
const coordinatorCohorts = await Cohort.find({
coordinator: user._id,
organization: org._id
}).populate(['coordinator','phase','program'])
organization: org._id,
}).populate(['coordinator', 'phase', 'program'])

return coordinatorCohorts
}
case RoleOfUser.TTL:
case RoleOfUser.TRAINEE:
const cohort = await Cohort.findOne(user?.cohort)
.populate(['coordinator','phase','program'])
return [ cohort ]
case RoleOfUser.TRAINEE: {
const cohort = await Cohort.findOne(user?.cohort).populate([
'coordinator',
'phase',
'program',
])
return [cohort]
}
default:
return []
}
}
},
},

Mutation: {
Expand Down Expand Up @@ -136,8 +151,8 @@ const resolvers = {
orgToken,
} = args

// some validations
; (await checkUserLoggedIn(context))([
// some validations
;(await checkUserLoggedIn(context))([
RoleOfUser.SUPER_ADMIN,
RoleOfUser.ADMIN,
RoleOfUser.MANAGER,
Expand Down Expand Up @@ -183,7 +198,7 @@ const resolvers = {
endDate &&
isAfter(new Date(startDate.toString()), new Date(endDate.toString()))
) {
throw new GraphQLError('End Date can\'t be before Start Date', {
throw new GraphQLError("End Date can't be before Start Date", {
extensions: {
code: 'VALIDATION_ERROR',
},
Expand Down
Loading
Loading