Skip to content

Commit

Permalink
CRUD Operations for tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
MugemaneBertin2001 committed Sep 12, 2024
1 parent 73b4c1b commit ad04193
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 422 deletions.
40 changes: 33 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"homepage": "https://github.com/atlp-rwanda/atlp-pulse-backend#readme",
"dependencies": {
"@apollo/server": "^4.11.0",
"@faker-js/faker": "^9.0.0",
"@graphql-tools/merge": "^8.3.3",
"@graphql-tools/schema": "^9.0.10",
"@graphql-tools/utils": "^10.0.4",
Expand All @@ -67,11 +68,12 @@
"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",
"graphql-upload-ts": "^2.1.2",
"graphql-tag": "^2.12.6",
"graphql-upload-ts": "^2.1.2",
"graphql-ws": "^5.11.2",
"jsonwebtoken": "^9.0.2",
"mongodb": "^4.17.1",
Expand All @@ -90,6 +92,7 @@
"@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
19 changes: 12 additions & 7 deletions src/models/ticket.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose, { Schema } from 'mongoose';
import mongoose, { Schema } from 'mongoose'

const ticketSchema = new Schema(
{
Expand All @@ -7,6 +7,11 @@ const ticketSchema = new Schema(
ref: 'User',
required: true,
},
assignee: {
type: mongoose.Types.ObjectId,
ref: 'User',
required: false,
},
subject: {
type: String,
required: true,
Expand Down Expand Up @@ -45,13 +50,13 @@ const ticketSchema = new Schema(
toJSON: { virtuals: true },
timestamps: true,
}
);
)

ticketSchema.pre('find', function (next) {
this.sort('-createdAt');
next();
});
this.sort('-createdAt')
next()
})

const Ticket = mongoose.model('Ticket', ticketSchema);
const Ticket = mongoose.model('Ticket', ticketSchema)

export default Ticket;
export default Ticket
16 changes: 11 additions & 5 deletions src/resolvers/coordinatorResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const manageStudentResolvers = {
getUsers: async (_: any, { orgToken }: any, context: Context) => {
try {
// coordinator validation
;(await checkUserLoggedIn(context))(['admin', 'manager', 'coordinator'])
;(await checkUserLoggedIn(context))([
'superAdmin',
'admin',
'manager',
'coordinator',
])

// get the organization if someone logs in
const org: InstanceType<typeof Organization> =
Expand All @@ -94,6 +99,7 @@ const manageStudentResolvers = {
try {
// coordinator validation
const { userId, role }: any = (await checkUserLoggedIn(context))([
'superAdmin',
'admin',
'manager',
'coordinator',
Expand Down Expand Up @@ -363,7 +369,7 @@ const manageStudentResolvers = {
if (team && user) {
if (team.cohort.program.organization.name !== org?.name) {
throw new Error(
' You logged into an organization that doesn\'t have such a team'
" You logged into an organization that doesn't have such a team"
)
}
const programId = team.cohort.program.id
Expand Down Expand Up @@ -881,7 +887,7 @@ async function sendEmailOnMembershipActions(
_id: org.id,
})
if (!organization) {
throw new Error('You don\'t have an organization yet')
throw new Error("You don't have an organization yet")
}
if (organization.admin.includes(userId) && organization.name == org.name) {
const link: any = process.env.FRONTEND_LINK + '/login/org'
Expand All @@ -901,7 +907,7 @@ async function sendEmailOnMembershipActions(
if (role === 'manager') {
const program: any = await Program.findOne({ manager: userId })
if (!program) {
throw new Error('You dont\'t have a program yet')
throw new Error("You dont't have a program yet")
}
if (program.organization._id.toString() == org?.id.toString()) {
const content = getOrganizationTemplate(
Expand All @@ -925,7 +931,7 @@ async function sendEmailOnMembershipActions(
if (role === 'coordinator') {
const cohort: any = await Cohort.findOne({ coordinator: userId })
if (!cohort) {
throw new Error('You don\'t have a coordinator yet')
throw new Error("You don't have a coordinator yet")
}
const program: any = await Program.findOne({
_id: cohort.program,
Expand Down
Loading

0 comments on commit ad04193

Please sign in to comment.