Skip to content

Commit

Permalink
feat(ft-view-gradings): admin able to veiw grading
Browse files Browse the repository at this point in the history
  • Loading branch information
nkurunziza1 committed Nov 3, 2023
1 parent 629bc7a commit 47012ee
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/resolvers/grading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,54 @@ import { LoggedUserModel } from "../models/AuthUser";
import { AuthenticationError } from "apollo-server-core";
import scoreTypesModel from "../models/scoreTypesModel";


const gradingResolver = {
Query: {
viewSingleGrading: async (_: any, { gradingId }: any, context: any) => {
try {
const userWithRole = await LoggedUserModel.findById(
context.currentUser?._id
).populate("role");

if (
!userWithRole ||
!["admin", "superAdmin"].includes(
(userWithRole.role as any)?.roleName
)
) {
throw new AuthenticationError("Only superAdmin can create a grading");
}
const grading = await gradingModel.findById(gradingId);
return grading;
} catch (error: any) {
throw new Error(`Error fetching single grading: ${error.message}`);
}
},

viewAllGradings: async (
_: any,
{ page, pageSize, searchParams }: any,
context: any
) => {
try {
const userWithRole = await LoggedUserModel.findById(
context.currentUser?._id
).populate("role");

if (
!userWithRole ||
!["admin", "superAdmin"].includes(
(userWithRole.role as any)?.roleName
)
) {
throw new AuthenticationError("Only superAdmin can create a grading");
}
const gradings = await gradingModel.find();
return gradings;
} catch (error: any) {
throw new Error(`Error fetching gradings: ${error.message}`);
}
},
},
Mutation: {
async createGrading(_: any, { gradingInput }: any, context: any) {
try {
Expand All @@ -21,7 +67,7 @@ const gradingResolver = {
throw new AuthenticationError("Only superAdmin can create a grading");
}

const { title, description, grades, assessment } = gradingInput;
const { title, description, grades, assessment } = gradingInput;

for (const grade of grades) {
if (
Expand Down Expand Up @@ -56,7 +102,7 @@ const gradingResolver = {
}
}

let newGrade = new gradingModel({
let newGrade = new gradingModel({
title,
assessment,
description,
Expand Down
20 changes: 20 additions & 0 deletions src/schema/gradingSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,28 @@ export const gradingTypeDefs = gql`
scale: ScaleInput
attribute: String!
}
input gradingSearch {
name: String,
scale: String,
attribute: String,
}
type GradingList {
gradings: [Grading]
}
type Query {
viewAllGradings(
page: Int
pageSize: Int
searchParams: gradingSearch
): Grading
viewSingleGrading(gradingId: ID!): Grading
}
type Mutation {
createGrading(gradingInput: GradingInput!): Grading!
}
`;

0 comments on commit 47012ee

Please sign in to comment.