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

#242-CRUD Operations for tickets #287

Merged
merged 1 commit into from
Sep 27, 2024
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
33 changes: 33 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions 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,6 +68,7 @@
"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 @@ -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
61 changes: 39 additions & 22 deletions src/resolvers/coordinatorResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ const manageStudentResolvers = {
try {
// coordinator validation
;(await checkUserLoggedIn(context))([
'superAdmin',
'admin',
'manager',
'coordinator',
'ttl',
])

// get the organization if someone logs in
const org: InstanceType<typeof Organization> =
await checkLoggedInOrganization(orgToken)

Expand All @@ -94,42 +93,59 @@ const manageStudentResolvers = {
})
}
},

getTrainees: async (_: any, { orgToken }: any, context: Context) => {
try {
// coordinator validation
const { userId, role }: any = (await checkUserLoggedIn(context))([
'superAdmin',
'admin',
'manager',
'coordinator',
'ttl',
])

// get the organization if someone logs in
const org: InstanceType<typeof Organization> =
await checkLoggedInOrganization(orgToken)
// console.log("User info:",User);

return (
await User.find({
role: 'trainee',
organizations: org.name,
}).populate({
path: 'team',
const query: any = {
role: 'trainee',
organizations: org.name,
}

let teamId: Types.ObjectId | undefined

if (role === 'ttl') {
const userTeam = await Team.findOne({
members: new Types.ObjectId(userId),
})
if (!userTeam) {
return []
}

teamId = userTeam._id
query['team'] = teamId
}
const trainees = await User.find(query).populate({
path: 'team',
strictPopulate: false,
populate: {
path: 'cohort',
strictPopulate: false,
populate: {
path: 'cohort',
path: 'program',
strictPopulate: false,
populate: {
path: 'program',
path: 'organization',
strictPopulate: false,
populate: {
path: 'organization',
strictPopulate: false,
},
},
},
})
).filter((user: any) => {
},
})
if (role === 'ttl') {
return trainees
}

return trainees.filter((user: any) => {
if (role === 'admin') {
return (
user.team?.cohort?.program?.organization.name == org?.name &&
Expand All @@ -154,6 +170,7 @@ const manageStudentResolvers = {
) == userId
)
}
return false
})
} catch (error) {
const { message } = error as { message: any }
Expand Down Expand Up @@ -192,14 +209,14 @@ const manageStudentResolvers = {
path: 'cohort',

strictPopulate: false,
//

populate: {
path: 'program',
strictPopulate: false,
//

populate: {
path: 'organization',
//

strictPopulate: false,
},
},
Expand Down
Loading
Loading