Skip to content

Commit b9375ed

Browse files
MugemaneBertin2001ceelogre
authored andcommitted
Fix/missing secret env (#402)
* Added missing secret in env * test: deployment * feat: run the action on push --------- Co-authored-by: ceelogre <[email protected]>
1 parent 14bfcde commit b9375ed

15 files changed

+3192
-2078
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@typescript-eslint/no-explicit-any": 0,
2424
"@typescript-eslint/no-non-null-assertion": 0,
2525
"no-useless-catch": 0,
26-
"@typescript-eslint/explicit-module-boundary-types": "off"
26+
"@typescript-eslint/explicit-module-boundary-types": "off",
27+
"@typescript-eslint/no-unused-vars": "off"
2728
}
2829
}

package-lock.json

Lines changed: 2415 additions & 1794 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"dotenv": "^16.0.1",
7171
"ejs": "^3.1.8",
7272
"express": "^4.18.1",
73-
"faker": "^6.6.6",
7473
"generate-password": "^1.7.0",
7574
"graphql": "^16.5.0",
7675
"graphql-subscriptions": "^2.0.0",
@@ -96,7 +95,6 @@
9695
"@types/chai": "^4.3.3",
9796
"@types/cors": "^2.8.17",
9897
"@types/express": "^4.17.6",
99-
"@types/faker": "^6.6.9",
10098
"@types/jsonwebtoken": "^8.5.8",
10199
"@types/mocha": "^8.0.3",
102100
"@types/node": "^13.13.52",

src/helpers/user.helpers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ export const generateTokenOrganization = (name: string) => {
1515
return jwt.sign({ name }, SECRET, { expiresIn: '336h' })
1616
}
1717

18-
export const genericToken=(playLoad:any)=>{
19-
return jwt.sign({...playLoad},SECRET)
20-
}
21-
18+
export const genericToken = (playLoad: any) => {
19+
return jwt.sign({ ...playLoad }, SECRET)
20+
}
2221

2322
export const emailExpression =
2423
/^(([^<>()[\]\\.,;:\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,}))$/

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import invitationSchema from './schema/invitation.schema'
5353
import TableViewInvitationResolver from './resolvers/TableViewInvitationResolver'
5454
import eventSchema from './schema/event.schema'
5555
import './utils/cron-jobs/team-jobs'
56+
import CommunitySchema from './schema/community.schema'
57+
import CommunityResolver from './resolvers/community.resolver'
5658
import faMutation from './resolvers/2fa.resolvers';
5759

5860
const PORT: number = parseInt(process.env.PORT!) || 4000
@@ -69,6 +71,7 @@ export const typeDefs = mergeTypeDefs([
6971
notificationSchema,
7072
statisticsSchema,
7173
eventSchema,
74+
CommunitySchema,
7275
organizationSchema
7376
])
7477

@@ -91,7 +94,7 @@ export const resolvers = mergeResolvers([
9194
Sessionresolvers,
9295
organizationResolvers,
9396
StatisticsResolvers,
94-
97+
CommunityResolver,
9598
invitationResolvers,
9699
TableViewInvitationResolver,
97100
faMutation,

src/models/question.model.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import mongoose, { Document, Schema } from 'mongoose'
2+
3+
interface IAnswer {
4+
content: string
5+
author: mongoose.Types.ObjectId // Reference to User
6+
question: mongoose.Types.ObjectId
7+
createdAt?: Date // Optional if not needed
8+
}
9+
10+
interface IQuestion extends Document {
11+
title: string
12+
content: string
13+
author: mongoose.Types.ObjectId // Reference to User
14+
createdAt?: Date // Optional if not needed
15+
answers: IAnswer[]
16+
}
17+
18+
const answerSchema = new Schema<IAnswer>({
19+
content: { type: String, required: true },
20+
question: {
21+
type: mongoose.Schema.Types.ObjectId,
22+
ref: 'Question',
23+
required: true,
24+
},
25+
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
26+
createdAt: { type: Date, default: Date.now },
27+
})
28+
29+
const questionSchema = new Schema<IQuestion>({
30+
title: { type: String, required: true },
31+
content: { type: String, required: true },
32+
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
33+
createdAt: { type: Date, default: Date.now },
34+
answers: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Answer' }],
35+
})
36+
const Answer = mongoose.model<IAnswer>('Answer', answerSchema)
37+
const Question = mongoose.model<IQuestion>('Question', questionSchema)
38+
39+
export { Question, IQuestion, IAnswer, Answer }

src/resolvers/cohort.resolvers.ts

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ const resolvers = {
6262
},
6363
})
6464
).filter((item) => {
65-
const org = (item.program as InstanceType<typeof Program>)?.organization
65+
const org = (item.program as InstanceType<typeof Program>)
66+
?.organization
6667
return item.program !== null && org !== null
6768
})
6869
} catch (error) {
@@ -74,41 +75,55 @@ const resolvers = {
7475
})
7576
}
7677
},
77-
getUserCohorts: async(_:any, { orgToken }: {orgToken: string}, context: Context)=>{
78-
const { userId, role} = (await checkUserLoggedIn(context))([RoleOfUser.COORDINATOR, RoleOfUser.TTL, RoleOfUser.TRAINEE])
78+
getUserCohorts: async (
79+
_: any,
80+
{ orgToken }: { orgToken: string },
81+
context: Context
82+
) => {
83+
const { userId, role } = (await checkUserLoggedIn(context))([
84+
RoleOfUser.COORDINATOR,
85+
RoleOfUser.TTL,
86+
RoleOfUser.TRAINEE,
87+
])
7988
const user = await User.findById(userId)
80-
if(!user){
81-
throw new GraphQLError("No such user found",{
89+
if (!user) {
90+
throw new GraphQLError('No such user found', {
8291
extensions: {
83-
code: "USER_NOT_FOUND"
84-
}
92+
code: 'USER_NOT_FOUND',
93+
},
8594
})
8695
}
87-
const org= await checkLoggedInOrganization(orgToken)
88-
if(!org){
89-
throw new GraphQLError("No such organization found",{
96+
const org = await checkLoggedInOrganization(orgToken)
97+
if (!org) {
98+
throw new GraphQLError('No such organization found', {
9099
extensions: {
91-
code: "ORG_NOT_FOUND"
92-
}
100+
code: 'ORG_NOT_FOUND',
101+
},
93102
})
94103
}
95-
switch(role){
96-
case RoleOfUser.COORDINATOR:
104+
105+
switch (role) {
106+
case RoleOfUser.COORDINATOR: {
97107
const coordinatorCohorts = await Cohort.find({
98108
coordinator: user._id,
99-
organization: org._id
100-
}).populate(['coordinator','phase','program'])
109+
organization: org._id,
110+
}).populate(['coordinator', 'phase', 'program'])
101111

102112
return coordinatorCohorts
113+
}
103114
case RoleOfUser.TTL:
104-
case RoleOfUser.TRAINEE:
105-
const cohort = await Cohort.findOne(user?.cohort)
106-
.populate(['coordinator','phase','program'])
107-
return [ cohort ]
115+
case RoleOfUser.TRAINEE: {
116+
const cohort = await Cohort.findOne(user?.cohort).populate([
117+
'coordinator',
118+
'phase',
119+
'program',
120+
])
121+
return [cohort]
122+
}
108123
default:
109124
return []
110125
}
111-
}
126+
},
112127
},
113128

114129
Mutation: {
@@ -136,8 +151,8 @@ const resolvers = {
136151
orgToken,
137152
} = args
138153

139-
// some validations
140-
; (await checkUserLoggedIn(context))([
154+
// some validations
155+
;(await checkUserLoggedIn(context))([
141156
RoleOfUser.SUPER_ADMIN,
142157
RoleOfUser.ADMIN,
143158
RoleOfUser.MANAGER,
@@ -183,7 +198,7 @@ const resolvers = {
183198
endDate &&
184199
isAfter(new Date(startDate.toString()), new Date(endDate.toString()))
185200
) {
186-
throw new GraphQLError('End Date can\'t be before Start Date', {
201+
throw new GraphQLError("End Date can't be before Start Date", {
187202
extensions: {
188203
code: 'VALIDATION_ERROR',
189204
},

0 commit comments

Comments
 (0)