diff --git a/apps/backend/src/modules/index.ts b/apps/backend/src/modules/index.ts index 406f69a7d..7aca578af 100644 --- a/apps/backend/src/modules/index.ts +++ b/apps/backend/src/modules/index.ts @@ -6,6 +6,7 @@ import Common from "./common"; import Course from "./course"; import Enrollment from "./enrollment"; import GradeDistribution from "./grade-distribution"; +import Rating from "./rating"; import Schedule from "./schedule"; import Term from "./term"; import User from "./user"; @@ -20,6 +21,7 @@ const modules = [ Course, Class, Enrollment, + Rating, ]; export const resolvers = merge(modules.map((module) => module.resolver)); diff --git a/apps/backend/src/modules/rating/controller.ts b/apps/backend/src/modules/rating/controller.ts new file mode 100644 index 000000000..43beda99e --- /dev/null +++ b/apps/backend/src/modules/rating/controller.ts @@ -0,0 +1,9 @@ +import { RatingType } from '@repo/common'; + +export async function getRatingsByClass(): Promise { + return null; +} + +export async function createRating(rating: RatingType): Promise { + rating; +} diff --git a/apps/backend/src/modules/rating/formatter.ts b/apps/backend/src/modules/rating/formatter.ts new file mode 100644 index 000000000..e69de29bb diff --git a/apps/backend/src/modules/rating/index.ts b/apps/backend/src/modules/rating/index.ts new file mode 100644 index 000000000..0dea70a5c --- /dev/null +++ b/apps/backend/src/modules/rating/index.ts @@ -0,0 +1,7 @@ +import resolver from "./resolver"; +import typeDef from "./typedefs/rating"; + +export default { + resolver, + typeDef, +}; diff --git a/apps/backend/src/modules/rating/resolver.ts b/apps/backend/src/modules/rating/resolver.ts new file mode 100644 index 000000000..e69de29bb diff --git a/apps/backend/src/modules/rating/typedefs/rating.ts b/apps/backend/src/modules/rating/typedefs/rating.ts new file mode 100644 index 000000000..ff1870179 --- /dev/null +++ b/apps/backend/src/modules/rating/typedefs/rating.ts @@ -0,0 +1,40 @@ +import { gql } from "graphql-tag"; + +const typedef = gql` +type HistogramEntry { + value: Int! + count: Int! + class: String! +} +type ClassHistogram { + class: Class + histogram: [HistogramEntry!] +} +type RatingSummary { + name: String! + class_histogram: [ClassHistogram!] + overall_histogram: [HistogramEntry!] + totalCount: Int! + average: Float! +} +type Rating { + class: Class! + name: String! + value: Int! +} +type Query { + rating(name: String!, subject: String!, number: String!): RatingSummary! + user_ratings(subject: String!, number: String!): [Rating] @auth +} +type CreateRatingInput { + class: String! + name: String! + value: Int! +} +type Mutation { + createRating(rating: CreateRatingInput): @auth + deleteRating(): @auth +} +`; + +export default typedef; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 21b85d372..b87d7478f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "eslint": "^8.56.0", "patch-package": "^8.0.0", "prettier": "^3.3.3", - "turbo": "^2.0.9" + "turbo": "^2.2.3" }, "engines": { "node": ">=21.0.0", @@ -18892,25 +18892,25 @@ } }, "node_modules/turbo": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo/-/turbo-2.0.9.tgz", - "integrity": "sha512-QaLaUL1CqblSKKPgLrFW3lZWkWG4pGBQNW+q1ScJB5v1D/nFWtsrD/yZljW/bdawg90ihi4/ftQJ3h6fz1FamA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo/-/turbo-2.2.3.tgz", + "integrity": "sha512-5lDvSqIxCYJ/BAd6rQGK/AzFRhBkbu4JHVMLmGh/hCb7U3CqSnr5Tjwfy9vc+/5wG2DJ6wttgAaA7MoCgvBKZQ==", "bin": { "turbo": "bin/turbo" }, "optionalDependencies": { - "turbo-darwin-64": "2.0.9", - "turbo-darwin-arm64": "2.0.9", - "turbo-linux-64": "2.0.9", - "turbo-linux-arm64": "2.0.9", - "turbo-windows-64": "2.0.9", - "turbo-windows-arm64": "2.0.9" + "turbo-darwin-64": "2.2.3", + "turbo-darwin-arm64": "2.2.3", + "turbo-linux-64": "2.2.3", + "turbo-linux-arm64": "2.2.3", + "turbo-windows-64": "2.2.3", + "turbo-windows-arm64": "2.2.3" } }, "node_modules/turbo-darwin-64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-darwin-64/-/turbo-darwin-64-2.0.9.tgz", - "integrity": "sha512-owlGsOaExuVGBUfrnJwjkL1BWlvefjSKczEAcpLx4BI7Oh6ttakOi+JyomkPkFlYElRpjbvlR2gP8WIn6M/+xQ==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-darwin-64/-/turbo-darwin-64-2.2.3.tgz", + "integrity": "sha512-Rcm10CuMKQGcdIBS3R/9PMeuYnv6beYIHqfZFeKWVYEWH69sauj4INs83zKMTUiZJ3/hWGZ4jet9AOwhsssLyg==", "cpu": [ "x64" ], @@ -18920,9 +18920,9 @@ ] }, "node_modules/turbo-darwin-arm64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-darwin-arm64/-/turbo-darwin-arm64-2.0.9.tgz", - "integrity": "sha512-XAXkKkePth5ZPPE/9G9tTnPQx0C8UTkGWmNGYkpmGgRr8NedW+HrPsi9N0HcjzzIH9A4TpNYvtiV+WcwdaEjKA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-darwin-arm64/-/turbo-darwin-arm64-2.2.3.tgz", + "integrity": "sha512-+EIMHkuLFqUdJYsA3roj66t9+9IciCajgj+DVek+QezEdOJKcRxlvDOS2BUaeN8kEzVSsNiAGnoysFWYw4K0HA==", "cpu": [ "arm64" ], @@ -18932,9 +18932,9 @@ ] }, "node_modules/turbo-linux-64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-linux-64/-/turbo-linux-64-2.0.9.tgz", - "integrity": "sha512-l9wSgEjrCFM1aG16zItBsZ206ZlhSSx1owB8Cgskfv0XyIXRGHRkluihiaxkp+UeU5WoEfz4EN5toc+ICA0q0w==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-linux-64/-/turbo-linux-64-2.2.3.tgz", + "integrity": "sha512-UBhJCYnqtaeOBQLmLo8BAisWbc9v9daL9G8upLR+XGj6vuN/Nz6qUAhverN4Pyej1g4Nt1BhROnj6GLOPYyqxQ==", "cpu": [ "x64" ], @@ -18944,9 +18944,9 @@ ] }, "node_modules/turbo-linux-arm64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-linux-arm64/-/turbo-linux-arm64-2.0.9.tgz", - "integrity": "sha512-gRnjxXRne18B27SwxXMqL3fJu7jw/8kBrOBTBNRSmZZiG1Uu3nbnP7b4lgrA/bCku6C0Wligwqurvtpq6+nFHA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-linux-arm64/-/turbo-linux-arm64-2.2.3.tgz", + "integrity": "sha512-hJYT9dN06XCQ3jBka/EWvvAETnHRs3xuO/rb5bESmDfG+d9yQjeTMlhRXKrr4eyIMt6cLDt1LBfyi+6CQ+VAwQ==", "cpu": [ "arm64" ], @@ -18956,9 +18956,9 @@ ] }, "node_modules/turbo-windows-64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-windows-64/-/turbo-windows-64-2.0.9.tgz", - "integrity": "sha512-ZVo0apxUvaRq4Vm1qhsfqKKhtRgReYlBVf9MQvVU1O9AoyydEQvLDO1ryqpXDZWpcHoFxHAQc9msjAMtE5K2lA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-windows-64/-/turbo-windows-64-2.2.3.tgz", + "integrity": "sha512-NPrjacrZypMBF31b4HE4ROg4P3nhMBPHKS5WTpMwf7wydZ8uvdEHpESVNMOtqhlp857zbnKYgP+yJF30H3N2dQ==", "cpu": [ "x64" ], @@ -18968,9 +18968,9 @@ ] }, "node_modules/turbo-windows-arm64": { - "version": "2.0.9", - "resolved": "https://registry.npmjs.org/turbo-windows-arm64/-/turbo-windows-arm64-2.0.9.tgz", - "integrity": "sha512-sGRz7c5Pey6y7y9OKi8ypbWNuIRPF9y8xcMqL56OZifSUSo+X2EOsOleR9MKxQXVaqHPGOUKWsE6y8hxBi9pag==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/turbo-windows-arm64/-/turbo-windows-arm64-2.2.3.tgz", + "integrity": "sha512-fnNrYBCqn6zgKPKLHu4sOkihBI/+0oYFr075duRxqUZ+1aLWTAGfHZLgjVeLh3zR37CVzuerGIPWAEkNhkWEIw==", "cpu": [ "arm64" ], diff --git a/package.json b/package.json index 3720366ca..8381c4aaf 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "eslint": "^8.56.0", "patch-package": "^8.0.0", "prettier": "^3.3.3", - "turbo": "^2.0.9" + "turbo": "^2.2.3" }, "name": "berkeleytime" } diff --git a/packages/common/src/models/index.ts b/packages/common/src/models/index.ts index c73bcaa4f..7ecafc623 100644 --- a/packages/common/src/models/index.ts +++ b/packages/common/src/models/index.ts @@ -6,4 +6,5 @@ export * from "./term"; export * from "./course"; export * from "./course"; export * from "./section"; +export * from "./rating"; export * from "./grade-distribution"; diff --git a/packages/common/src/models/rating.ts b/packages/common/src/models/rating.ts new file mode 100644 index 000000000..91502a305 --- /dev/null +++ b/packages/common/src/models/rating.ts @@ -0,0 +1,52 @@ +import mongoose, { InferSchemaType, Schema } from "mongoose"; + +const ratingSchema = new Schema({ + _id: Schema.Types.ObjectId, + google_id: { + type: String, + trim: true, + required: true, + immutable: true, + select: false, + }, + email: { + type: String, + trim: true, + required: true, + immutable: true, + }, + class: { + type: Schema.Types.ObjectId, + ref: 'Class', + required: true, + immutable: true + }, + // likert int 1 -> 5 values + // boolean 0/1 values + // string properties assign hash code + value: { + type: Number, + required: true, + validate: { + validator: Number.isInteger, + } + }, + // indicate value type (granularity: specific questions) + value_type: { + type: String, + required: true, + } +}, { + timestamps: { + createdAt: "createdAt", + updatedAt: "updatedAt", + }, +}); + +export const RatingModel = mongoose.model( + "crowdsource_rating", + ratingSchema, + "crowdsource_rating" +); + +export type RatingType = InferSchemaType; \ No newline at end of file