From 9c286d08050f8c80ba198801e4b57b8ef4894860 Mon Sep 17 00:00:00 2001 From: Leonardo Lodi Date: Tue, 30 Jul 2024 16:45:56 +0100 Subject: [PATCH 1/5] Feat: add course unique constraint field for cohort model --- .../migration.sql | 2 ++ .../migration.sql | 8 ++++++ prisma/schema.prisma | 1 + prisma/seed.js | 5 +++- src/controllers/cohort.js | 26 ++++++++++++++++--- src/domain/cohort.js | 4 ++- src/utils/errors.js | 1 + 7 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql create mode 100644 prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql diff --git a/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql b/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql new file mode 100644 index 00000000..23e81131 --- /dev/null +++ b/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Cohort" ADD COLUMN "course" TEXT; diff --git a/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql b/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql new file mode 100644 index 00000000..2f938c2d --- /dev/null +++ b/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[course]` on the table `Cohort` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "Cohort_course_key" ON "Cohort"("course"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2f5b35bb..737406b9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -45,6 +45,7 @@ model Profile { model Cohort { id Int @id @default(autoincrement()) name String? + course String? @unique users User[] deliveryLogs DeliveryLog[] startDate DateTime? @db.Date diff --git a/prisma/seed.js b/prisma/seed.js index 04f2c829..03c0d61e 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -51,7 +51,10 @@ async function createPost(userId, content) { async function createCohort() { const cohort = await prisma.cohort.create({ - data: {} + data: { + name: 'Cohort 1', + course: 'Software Development' + } }) console.info('Cohort created', cohort) diff --git a/src/controllers/cohort.js b/src/controllers/cohort.js index 91e8fd5a..7e0cf96b 100644 --- a/src/controllers/cohort.js +++ b/src/controllers/cohort.js @@ -5,11 +5,26 @@ import ERR from '../utils/errors.js' import { dateRegex } from '../utils/regexMatchers.js' export const create = async (req, res) => { - const { startDate, endDate } = req.body + const { name, course, startDate, endDate } = req.body - if (!startDate || !endDate) { + const foundCohorts = await getAllCohorts() + + const courseInUse = foundCohorts.some((cohort) => + cohort.course + .split(' ') + .join('') + .toLowerCase() + .includes(course.split(' ').join('').toLowerCase()) + ) + + if (courseInUse) { + return sendMessageResponse(res, 409, { error: ERR.COURSE_IN_USE }) + } + + if (!name || !course || !startDate || !endDate) { return sendMessageResponse(res, 400, { error: ERR.DATE_REQUIRED }) } + if (!dateRegex.test(startDate) || !dateRegex.test(endDate)) { return sendMessageResponse(res, 400, { error: ERR.DATE_FORMATTING }) } @@ -19,7 +34,12 @@ export const create = async (req, res) => { startDate, endDate ) - const createdCohort = await createCohort(parsedStartDate, parsedEndDate) + const createdCohort = createCohort( + name, + course, + parsedStartDate, + parsedEndDate + ) return sendDataResponse(res, 201, createdCohort) } catch (e) { diff --git a/src/domain/cohort.js b/src/domain/cohort.js index b4fdf1d2..9efb2eaf 100644 --- a/src/domain/cohort.js +++ b/src/domain/cohort.js @@ -4,9 +4,11 @@ import dbClient from '../utils/dbClient.js' * Create a new Cohort in the database * @returns {Cohort} */ -export async function createCohort(startDate, endDate) { +export async function createCohort(name, course, startDate, endDate) { const createdCohort = await dbClient.cohort.create({ data: { + name, + course, startDate, endDate }, diff --git a/src/utils/errors.js b/src/utils/errors.js index cb79c245..bc2bcfa4 100644 --- a/src/utils/errors.js +++ b/src/utils/errors.js @@ -18,6 +18,7 @@ export default { 'An error occurred while creating the delivery log.', DATE_FORMATTING: 'Invalid date format. Please use yyyy/mm/dd.', DATE_REQUIRED: 'Date is required', + COURSE_IN_USE: 'This cohort course is already in use', EMAIL_IN_USE: 'This email address is already in use', UNABLE_TO_CREATE_USER: 'Unable to create new user', MISSING_AUTH_HEADER: 'No authorisation header', From 7d58261170f44b8da58842bed5811fa10374f199 Mon Sep 17 00:00:00 2001 From: Leonardo Lodi Date: Tue, 30 Jul 2024 17:30:54 +0100 Subject: [PATCH 2/5] Fix: filter course field by prisma queries --- src/controllers/cohort.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/controllers/cohort.js b/src/controllers/cohort.js index 7e0cf96b..886bf02b 100644 --- a/src/controllers/cohort.js +++ b/src/controllers/cohort.js @@ -3,19 +3,16 @@ import { sendDataResponse, sendMessageResponse } from '../utils/responses.js' import * as validation from '../utils/validationFunctions.js' import ERR from '../utils/errors.js' import { dateRegex } from '../utils/regexMatchers.js' +import dbClient from '../utils/dbClient.js' export const create = async (req, res) => { const { name, course, startDate, endDate } = req.body - const foundCohorts = await getAllCohorts() - - const courseInUse = foundCohorts.some((cohort) => - cohort.course - .split(' ') - .join('') - .toLowerCase() - .includes(course.split(' ').join('').toLowerCase()) - ) + const courseInUse = await dbClient.cohort.findUnique({ + where: { + course: course + } + }) if (courseInUse) { return sendMessageResponse(res, 409, { error: ERR.COURSE_IN_USE }) From dc26b8ec2e5e3402d1ea0193060fa910ec9559f1 Mon Sep 17 00:00:00 2001 From: Leonardo Lodi Date: Wed, 31 Jul 2024 10:43:27 +0100 Subject: [PATCH 3/5] Feat: add course, module, unit and exercise models --- prisma/schema.prisma | 52 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2f5b35bb..45d38c23 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -44,7 +44,9 @@ model Profile { model Cohort { id Int @id @default(autoincrement()) - name String? + cohort String? + course Course? @relation(fields: [courseId], references: [id]) + courseId Int? @unique users User[] deliveryLogs DeliveryLog[] startDate DateTime? @db.Date @@ -53,6 +55,54 @@ model Cohort { updatedAt DateTime? @updatedAt } +model Course { + id Int @id @default(autoincrement()) + course String + modules Module[] + cohorts Cohort[] + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt +} + +model Module { + id Int @id @default(autoincrement()) + module String + units Unit[] + courses Course[] + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt +} + +model Unit { + id Int @id @default(autoincrement()) + unit String + module Module @relation(fields: [moduleId], references: [id]) + moduleId Int @unique + exercises Exercise[] + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt +} + +model Exercise { + id Int @id @default(autoincrement()) + exercise String + description String + githubRepo String + tags Tag[] + unit Unit @relation(fields: [unitId], references: [id]) + unitId Int @unique + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt +} + +model Tag { + id Int @id @default(autoincrement()) + tag String + exercises Exercise[] + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt +} + model Post { id Int @id @default(autoincrement()) content String From d61f612f5ed3c5d1887c3fa0ceddf45001a7354d Mon Sep 17 00:00:00 2001 From: Leonardo Lodi Date: Wed, 31 Jul 2024 15:55:20 +0100 Subject: [PATCH 4/5] Fix: change model structure --- .../migration.sql | 2 - .../migration.sql | 8 --- .../migration.sql | 65 ++++++++++-------- prisma/schema.prisma | 66 +++++++++++-------- prisma/seed.js | 2 +- src/controllers/cohort.js | 6 +- src/controllers/course.js | 27 ++++++++ src/controllers/user.js | 4 +- src/domain/cohort.js | 5 +- src/routes/course.js | 10 +++ src/server.js | 2 + 11 files changed, 124 insertions(+), 73 deletions(-) delete mode 100644 prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql delete mode 100644 prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql rename prisma/migrations/{20240731094804_create_cohort_models_relations => 20240731134520_add_student_exercise_relation}/migration.sql (68%) create mode 100644 src/controllers/course.js create mode 100644 src/routes/course.js diff --git a/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql b/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql deleted file mode 100644 index 23e81131..00000000 --- a/prisma/migrations/20240730152514_add_course_field_to_cohort_model/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Cohort" ADD COLUMN "course" TEXT; diff --git a/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql b/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql deleted file mode 100644 index 2f938c2d..00000000 --- a/prisma/migrations/20240730153421_add_unique_constraint_to_course_field_from_cohort_model/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[course]` on the table `Cohort` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateIndex -CREATE UNIQUE INDEX "Cohort_course_key" ON "Cohort"("course"); diff --git a/prisma/migrations/20240731094804_create_cohort_models_relations/migration.sql b/prisma/migrations/20240731134520_add_student_exercise_relation/migration.sql similarity index 68% rename from prisma/migrations/20240731094804_create_cohort_models_relations/migration.sql rename to prisma/migrations/20240731134520_add_student_exercise_relation/migration.sql index f8f6801e..1b39fc70 100644 --- a/prisma/migrations/20240731094804_create_cohort_models_relations/migration.sql +++ b/prisma/migrations/20240731134520_add_student_exercise_relation/migration.sql @@ -1,24 +1,7 @@ -/* - Warnings: - - - You are about to drop the column `course` on the `Cohort` table. All the data in the column will be lost. - - You are about to drop the column `name` on the `Cohort` table. All the data in the column will be lost. - - A unique constraint covering the columns `[courseId]` on the table `Cohort` will be added. If there are existing duplicate values, this will fail. - -*/ --- DropIndex -DROP INDEX "Cohort_course_key"; - --- AlterTable -ALTER TABLE "Cohort" DROP COLUMN "course", -DROP COLUMN "name", -ADD COLUMN "cohort" TEXT, -ADD COLUMN "courseId" INTEGER; - -- CreateTable CREATE TABLE "Course" ( "id" SERIAL NOT NULL, - "course" TEXT NOT NULL, + "name" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3), @@ -28,7 +11,7 @@ CREATE TABLE "Course" ( -- CreateTable CREATE TABLE "Module" ( "id" SERIAL NOT NULL, - "module" TEXT NOT NULL, + "name" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3), @@ -38,7 +21,7 @@ CREATE TABLE "Module" ( -- CreateTable CREATE TABLE "Unit" ( "id" SERIAL NOT NULL, - "unit" TEXT NOT NULL, + "name" TEXT NOT NULL, "moduleId" INTEGER NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3), @@ -49,7 +32,7 @@ CREATE TABLE "Unit" ( -- CreateTable CREATE TABLE "Exercise" ( "id" SERIAL NOT NULL, - "exercise" TEXT NOT NULL, + "title" TEXT NOT NULL, "description" TEXT NOT NULL, "githubRepo" TEXT NOT NULL, "unitId" INTEGER NOT NULL, @@ -59,16 +42,32 @@ CREATE TABLE "Exercise" ( CONSTRAINT "Exercise_pkey" PRIMARY KEY ("id") ); +-- CreateTable +CREATE TABLE "StudentExercise" ( + "id" SERIAL NOT NULL, + "exerciseId" INTEGER NOT NULL, + "studentId" INTEGER NOT NULL, + "isComplete" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "StudentExercise_pkey" PRIMARY KEY ("id") +); + -- CreateTable CREATE TABLE "Tag" ( "id" SERIAL NOT NULL, - "tag" TEXT NOT NULL, + "name" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3), CONSTRAINT "Tag_pkey" PRIMARY KEY ("id") ); +-- CreateTable +CREATE TABLE "_CohortToCourse" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + -- CreateTable CREATE TABLE "_CourseToModule" ( "A" INTEGER NOT NULL, @@ -87,6 +86,12 @@ CREATE UNIQUE INDEX "Unit_moduleId_key" ON "Unit"("moduleId"); -- CreateIndex CREATE UNIQUE INDEX "Exercise_unitId_key" ON "Exercise"("unitId"); +-- CreateIndex +CREATE UNIQUE INDEX "_CohortToCourse_AB_unique" ON "_CohortToCourse"("A", "B"); + +-- CreateIndex +CREATE INDEX "_CohortToCourse_B_index" ON "_CohortToCourse"("B"); + -- CreateIndex CREATE UNIQUE INDEX "_CourseToModule_AB_unique" ON "_CourseToModule"("A", "B"); @@ -99,17 +104,23 @@ CREATE UNIQUE INDEX "_ExerciseToTag_AB_unique" ON "_ExerciseToTag"("A", "B"); -- CreateIndex CREATE INDEX "_ExerciseToTag_B_index" ON "_ExerciseToTag"("B"); --- CreateIndex -CREATE UNIQUE INDEX "Cohort_courseId_key" ON "Cohort"("courseId"); +-- AddForeignKey +ALTER TABLE "Unit" ADD CONSTRAINT "Unit_moduleId_fkey" FOREIGN KEY ("moduleId") REFERENCES "Module"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "Cohort" ADD CONSTRAINT "Cohort_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE "Exercise" ADD CONSTRAINT "Exercise_unitId_fkey" FOREIGN KEY ("unitId") REFERENCES "Unit"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "Unit" ADD CONSTRAINT "Unit_moduleId_fkey" FOREIGN KEY ("moduleId") REFERENCES "Module"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "StudentExercise" ADD CONSTRAINT "StudentExercise_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "Exercise"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "Exercise" ADD CONSTRAINT "Exercise_unitId_fkey" FOREIGN KEY ("unitId") REFERENCES "Unit"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "StudentExercise" ADD CONSTRAINT "StudentExercise_studentId_fkey" FOREIGN KEY ("studentId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_CohortToCourse" ADD CONSTRAINT "_CohortToCourse_A_fkey" FOREIGN KEY ("A") REFERENCES "Cohort"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_CohortToCourse" ADD CONSTRAINT "_CohortToCourse_B_fkey" FOREIGN KEY ("B") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "_CourseToModule" ADD CONSTRAINT "_CourseToModule_A_fkey" FOREIGN KEY ("A") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 45d38c23..3a9adc8c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -16,18 +16,19 @@ enum UserRole { } model User { - id Int @id @default(autoincrement()) - email String @unique - password String - role UserRole @default(STUDENT) - profile Profile? - comments Comment[] - cohortId Int? - cohort Cohort? @relation(fields: [cohortId], references: [id]) - posts Post[] - deliveryLogs DeliveryLog[] - notesCreated Note[] @relation("TeacherNotes") - notesReceived Note[] @relation("StudentNotes") + id Int @id @default(autoincrement()) + email String @unique + password String + role UserRole @default(STUDENT) + profile Profile? + comments Comment[] + cohortId Int? + cohort Cohort? @relation(fields: [cohortId], references: [id]) + posts Post[] + deliveryLogs DeliveryLog[] + notesCreated Note[] @relation("TeacherNotes") + notesReceived Note[] @relation("StudentNotes") + studentExercise StudentExercise[] } model Profile { @@ -44,9 +45,8 @@ model Profile { model Cohort { id Int @id @default(autoincrement()) - cohort String? - course Course? @relation(fields: [courseId], references: [id]) - courseId Int? @unique + name String? + courses Course[] users User[] deliveryLogs DeliveryLog[] startDate DateTime? @db.Date @@ -57,7 +57,7 @@ model Cohort { model Course { id Int @id @default(autoincrement()) - course String + name String modules Module[] cohorts Cohort[] createdAt DateTime @default(now()) @@ -66,7 +66,7 @@ model Course { model Module { id Int @id @default(autoincrement()) - module String + name String units Unit[] courses Course[] createdAt DateTime @default(now()) @@ -75,7 +75,7 @@ model Module { model Unit { id Int @id @default(autoincrement()) - unit String + name String module Module @relation(fields: [moduleId], references: [id]) moduleId Int @unique exercises Exercise[] @@ -84,20 +84,30 @@ model Unit { } model Exercise { - id Int @id @default(autoincrement()) - exercise String - description String - githubRepo String - tags Tag[] - unit Unit @relation(fields: [unitId], references: [id]) - unitId Int @unique - createdAt DateTime @default(now()) - updatedAt DateTime? @updatedAt + id Int @id @default(autoincrement()) + title String + description String + githubRepo String + tags Tag[] + unit Unit @relation(fields: [unitId], references: [id]) + unitId Int @unique + createdAt DateTime @default(now()) + updatedAt DateTime? @updatedAt + studentExercise StudentExercise[] +} + +model StudentExercise { + id Int @id @default(autoincrement()) + exercise Exercise @relation(fields: [exerciseId], references: [id]) + exerciseId Int + student User @relation(fields: [studentId], references: [id]) + studentId Int + isComplete Boolean @default(false) } model Tag { id Int @id @default(autoincrement()) - tag String + name String exercises Exercise[] createdAt DateTime @default(now()) updatedAt DateTime? @updatedAt diff --git a/prisma/seed.js b/prisma/seed.js index 1cea4bd1..dfd251cd 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -52,7 +52,7 @@ async function createPost(userId, content) { async function createCohort() { const cohort = await prisma.cohort.create({ data: { - cohort: 'Cohort 1' + name: 'Cohort 1' } }) diff --git a/src/controllers/cohort.js b/src/controllers/cohort.js index 2d4574a9..5a5fa8ae 100644 --- a/src/controllers/cohort.js +++ b/src/controllers/cohort.js @@ -5,9 +5,9 @@ import ERR from '../utils/errors.js' import { dateRegex } from '../utils/regexMatchers.js' export const create = async (req, res) => { - const { cohort, startDate, endDate } = req.body + const { name, startDate, endDate } = req.body - if (!cohort || !startDate || !endDate) { + if (!name || !startDate || !endDate) { return sendMessageResponse(res, 400, { error: ERR.DATE_REQUIRED }) } @@ -20,7 +20,7 @@ export const create = async (req, res) => { startDate, endDate ) - const createdCohort = createCohort(cohort, parsedStartDate, parsedEndDate) + const createdCohort = createCohort(name, parsedStartDate, parsedEndDate) return sendDataResponse(res, 201, createdCohort) } catch (e) { diff --git a/src/controllers/course.js b/src/controllers/course.js new file mode 100644 index 00000000..78e92b05 --- /dev/null +++ b/src/controllers/course.js @@ -0,0 +1,27 @@ +import dbClient from '../utils/dbClient.js' +import { sendDataResponse, sendMessageResponse } from '../utils/responses.js' +import ERR from '../utils/errors.js' + +const getAllCourses = async (req, res) => { + const courses = await dbClient.course.findMany() + + return sendDataResponse(res, 200, courses) +} + +const createCourse = async (req, res) => { + const { name } = req.body + + if (!name) { + return sendMessageResponse(res, 400, { error: ERR.INCOMPLETE_REQUEST }) + } + + const course = await dbClient.course.create({ + data: { + name: name + } + }) + + return sendDataResponse(res, 201, course) +} + +export { getAllCourses, createCourse } diff --git a/src/controllers/user.js b/src/controllers/user.js index 248b91bf..5a6c17b2 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -18,10 +18,10 @@ export const create = async (req, res) => { const existingUser = await User.findByEmail(userToCreate.email) if (existingUser) { - return sendDataResponse(res, 400, { error: ERR.EMAIL_IN_USE }) + return sendMessageResponse(res, 400, { error: ERR.EMAIL_IN_USE }) } - const createdUser = await userToCreate.save() + const createdUser = userToCreate.save() return sendDataResponse(res, 201, createdUser) } catch (error) { diff --git a/src/domain/cohort.js b/src/domain/cohort.js index 88d81655..55536180 100644 --- a/src/domain/cohort.js +++ b/src/domain/cohort.js @@ -4,10 +4,10 @@ import dbClient from '../utils/dbClient.js' * Create a new Cohort in the database * @returns {Cohort} */ -export async function createCohort(cohort, startDate, endDate) { +export async function createCohort(name, startDate, endDate) { const createdCohort = await dbClient.cohort.create({ data: { - cohort, + name, startDate, endDate }, @@ -29,6 +29,7 @@ export class Cohort { return { cohort: { id: this.id, + name: this.name, startDate: this.startDate, endDate: this.endDate } diff --git a/src/routes/course.js b/src/routes/course.js new file mode 100644 index 00000000..c8f63d8b --- /dev/null +++ b/src/routes/course.js @@ -0,0 +1,10 @@ +import { Router } from 'express' +import { validateAuthentication } from '../middleware/auth.js' +import { createCourse, getAllCourses } from '../controllers/course.js' + +const route = Router() + +route.get('/', validateAuthentication, getAllCourses) +route.post('/', validateAuthentication, createCourse) + +export default route diff --git a/src/server.js b/src/server.js index e29d5fcf..5301f72a 100644 --- a/src/server.js +++ b/src/server.js @@ -11,6 +11,7 @@ import cohortRouter from './routes/cohort.js' import deliveryLogRouter from './routes/deliveryLog.js' import noteRouter from './routes/note.js' import commentRouter from './routes/comment.js' +import courseRouter from './routes/course.js' const app = express() app.disable('x-powered-by') @@ -27,6 +28,7 @@ app.use('/users', userRouter) app.use('/posts', postRouter) app.use('/comments', commentRouter) app.use('/cohorts', cohortRouter) +app.use('/courses', courseRouter) app.use('/logs', deliveryLogRouter) app.use('/notes', noteRouter) app.use('/', authRouter) From 5cd7ccaf62be70103807eea5284afbf3bacbc78b Mon Sep 17 00:00:00 2001 From: Leonardo Lodi Date: Wed, 31 Jul 2024 16:02:18 +0100 Subject: [PATCH 5/5] Fix: more merge conflicts --- src/server.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/server.js b/src/server.js index f38f1fc5..38241482 100644 --- a/src/server.js +++ b/src/server.js @@ -11,11 +11,8 @@ import cohortRouter from './routes/cohort.js' import deliveryLogRouter from './routes/deliveryLog.js' import noteRouter from './routes/note.js' import commentRouter from './routes/comment.js' -<<<<<<< HEAD import courseRouter from './routes/course.js' -======= import reactionsRouter from './routes/postReactions.js' ->>>>>>> main const app = express() app.disable('x-powered-by')