Skip to content

Commit

Permalink
initial session
Browse files Browse the repository at this point in the history
  • Loading branch information
PineND committed Oct 28, 2024
1 parent 8f16396 commit 1604307
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 9 deletions.
58 changes: 54 additions & 4 deletions apps/backend/src/modules/rating/controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
import { RatingType } from '@repo/common';
import { RatingModel, RatingType } from '@repo/common';
import {
CreateRatingInput,
DeleteRatingInput,
Mutation,
Query,
Rating,
RatingSummary,
UpdateRatingInput,
} from "../../generated-types/graphql";

export async function getRatingsByClass(): Promise<null> {
export const getRating = async (name: string, subject: string, number: string) => {
if (!context.user._id) throw new Error("Unauthorized");

const rating = mongoose.model("schedule", scheduleSchema)
return null;
}

export async function createRating(rating: RatingType): Promise<null> {
rating;
export const getUserRatings = async () => {

}

export const createRating = async (context: any, input: CreateRatingInput) => {
if (!context.user._id) throw new Error("Unauthorized");
if (input.value < 1 || input.value > 5) {
throw new Error("Rating must be between 1 and 5");
}

};
// export const getSchedule = async (context: any, id: string) => {
// const schedule = await ScheduleModel.findOne({
// _id: id,
// $or: [{ public: true }, { createdBy: context.user._id }],
// });

// if (!schedule) throw new Error("Not found");

// return await formatSchedule(schedule);
// };

// export const createSchedule = async (
// context: any,
// input: CreateScheduleInput
// ) => {
// if (!context.user._id) throw new Error("Unauthorized");

// const term = await TermModel.findOne({
// name: `${input.year} ${input.semester}`,
// });

// if (!term) throw new Error("Invalid term");

// const schedule = await ScheduleModel.create({
// ...input,
// createdBy: context.user._id,
// });

// return await formatSchedule(schedule);
// };
32 changes: 32 additions & 0 deletions apps/backend/src/modules/rating/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
getRating,
getUserRatings,
createRating
} from "./controller";

import { RatingModule } from "./generated-types/module-types";

const resolvers: RatingModule.Resolvers = {
Query: {
rating: async (_, { name: name, subject: subject, number: number }) => {
const ratingSummary = await getRating(name, subject, number);
return ratingSummary as RatingModule.RatingSummary;
},
user_ratings: async (_, { subject: subject, number: number }, context) => {
const ratings = await getUserRatings(context, subject, number);
return ratings as RatingModule.Rating[];
}
},
Mutation: {
createRating: async(_, { rating }, context) => {
const ratingSummary = await createRating(rating, context);
return ratingSummary as RatingModule.RatingSummary;
},
deleteRating: async(_, { subject: subject, number: number }, context) => {
const ratingSummary = await deleteRating(subject, number, context);
return ratingSummary as RatingModule.RatingSummary;
}
}
}

export default resolvers;
8 changes: 4 additions & 4 deletions apps/backend/src/modules/rating/typedefs/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type RatingSummary {
}
type Rating {
class: Class!
name: String!
question: String!
value: Int!
}
type Query {
Expand All @@ -28,12 +28,12 @@ type Query {
}
type CreateRatingInput {
class: String!
name: String!
question: String!
value: Int!
}
type Mutation {
createRating(rating: CreateRatingInput): @auth
deleteRating(): @auth
createRating(rating: CreateRatingInput): RatingSummary! @auth
deleteRating(subject: String!, number: String!): RatingSummary! @auth
}
`;

Expand Down
1 change: 0 additions & 1 deletion packages/common/src/models/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ export const RatingModel = mongoose.model(
ratingSchema,
"crowdsource_rating"
);

export type RatingType = InferSchemaType<typeof ratingSchema>;

0 comments on commit 1604307

Please sign in to comment.