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

Add Swagger API documentation & fix program creation parameters #31

Merged
merged 44 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
823ffd8
Add common folder
mhd-hi May 19, 2024
ae12b7b
Add program resource
mhd-hi May 19, 2024
b68c8e3
Fix eslint rule (complexity) & fix dependencies versions
mhd-hi May 19, 2024
c6db668
add course, cours-instance
mhd-hi May 19, 2024
1a863d6
add session resource
mhd-hi May 19, 2024
e7fc321
Add prisma, scraper, program files (modules and services)
mhd-hi May 21, 2024
606bce5
Fix prisma & add scraper files & eslint migration
mhd-hi Jun 4, 2024
932e293
chore: address sonarlint warning (if statement)
mhd-hi Jun 5, 2024
712840e
Rollback eslint flat to v8 & remove entity & format imports
mhd-hi Jun 15, 2024
83312c3
add public to classes
mhd-hi Jun 15, 2024
c691904
cleanup
mhd-hi Jun 19, 2024
c78599b
add ets api hekper files
mhd-hi Jun 19, 2024
42e7436
add ets-program logic & (WIP) upsert programs
mhd-hi Jun 22, 2024
edb4647
Remove unnecessary dtos
mhd-hi Jun 22, 2024
8df2b04
(wip 🚔) Add controllers & fix course routes
mhd-hi Jul 23, 2024
5a460d3
fix tests
mhd-hi Jul 23, 2024
f67dc26
Fix ProgramType relation
mhd-hi Jul 23, 2024
d37f8c3
Add coursePrerequisite controller & service
mhd-hi Jul 23, 2024
db78c07
Move scraper folder into /common
mhd-hi Jul 23, 2024
67c6b5a
Move pdf folder into /common
mhd-hi Jul 23, 2024
e93fac0
fix http & add prisma to app module
mhd-hi Jul 23, 2024
7351e66
fix tests (wip) & sessions route
mhd-hi Jul 24, 2024
bddcdc9
fix tests
mhd-hi Jul 24, 2024
d3db0f1
rename
mhd-hi Jul 24, 2024
1bf7bf0
Add schema image generator
mhd-hi Jul 24, 2024
bd61923
add methods
mhd-hi Jul 24, 2024
6a5160d
fix
mhd-hi Jul 24, 2024
a675fa1
change "program to programType" relation
mhd-hi Jul 24, 2024
3eb0ca0
fix ci test
mhd-hi Jul 24, 2024
64883da
miaow miaow
mhd-hi Jul 24, 2024
a616c7c
test test
mhd-hi Jul 25, 2024
4d45140
only run eslint on src folder
mhd-hi Jul 25, 2024
3af0f91
Rollback to ".test.ts" only
mhd-hi Jul 25, 2024
f0ea992
pdf small test
mhd-hi Jul 25, 2024
0f0d180
fix logging
mhd-hi Jul 26, 2024
84f24f6
fix PR & remove scraper folder
mhd-hi Jul 29, 2024
261d3ec
update enum trimester
mhd-hi Aug 3, 2024
12c81ba
remove file
mhd-hi Aug 3, 2024
eed3378
fix param
mhd-hi Aug 14, 2024
69466d6
Add swagger
mhd-hi Aug 14, 2024
1d703d3
fix program creation parameters & some route parameters
mhd-hi Aug 14, 2024
82983c1
fix axios vulnerability
mhd-hi Aug 19, 2024
59d9f1c
Merge branch 'main' into chore/add-swagger
mhd-hi Aug 27, 2024
f0d9356
logger instead of console.log
mhd-hi Aug 27, 2024
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "^2.0.5",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.4.0",
"@prisma/client": "^5.15.0",
"axios": "^1.6.8",
"axios": "^1.7.4",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"express": "^4.19.2",
Expand Down Expand Up @@ -97,4 +98,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
2 changes: 1 addition & 1 deletion prisma/ERD.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Warnings:

- The primary key for the `Course` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `programId` on the `Course` table. All the data in the column will be lost.
- The primary key for the `CoursePrerequisite` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The primary key for the `Program` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `programTypeIds` on the `Program` table. All the data in the column will be lost.
- The primary key for the `ProgramCourse` table will be changed. If it partially fails, the table could be left without primary key constraint.
- Changed the type of `id` on the `Course` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `courseId` on the `CourseInstance` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `courseId` on the `CoursePrerequisite` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `prerequisiteId` on the `CoursePrerequisite` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `id` on the `Program` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Added the required column `typicalSessionIndex` to the `ProgramCourse` table without a default value. This is not possible if the table is not empty.
- Changed the type of `courseId` on the `ProgramCourse` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `programId` on the `ProgramCourse` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- DropForeignKey
ALTER TABLE "CourseInstance" DROP CONSTRAINT "CourseInstance_courseId_fkey";

-- DropForeignKey
ALTER TABLE "CoursePrerequisite" DROP CONSTRAINT "CoursePrerequisite_courseId_fkey";

-- DropForeignKey
ALTER TABLE "CoursePrerequisite" DROP CONSTRAINT "CoursePrerequisite_prerequisiteId_fkey";

-- DropForeignKey
ALTER TABLE "ProgramCourse" DROP CONSTRAINT "ProgramCourse_courseId_fkey";

-- DropForeignKey
ALTER TABLE "ProgramCourse" DROP CONSTRAINT "ProgramCourse_programId_fkey";

-- DropIndex
DROP INDEX "Course_code_programId_idx";

-- AlterTable
ALTER TABLE "Course" DROP CONSTRAINT "Course_pkey",
DROP COLUMN "programId",
DROP COLUMN "id",
ADD COLUMN "id" INTEGER NOT NULL,
ADD CONSTRAINT "Course_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "CourseInstance" DROP COLUMN "courseId",
ADD COLUMN "courseId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "CoursePrerequisite" DROP CONSTRAINT "CoursePrerequisite_pkey",
DROP COLUMN "courseId",
ADD COLUMN "courseId" INTEGER NOT NULL,
DROP COLUMN "prerequisiteId",
ADD COLUMN "prerequisiteId" INTEGER NOT NULL,
ADD CONSTRAINT "CoursePrerequisite_pkey" PRIMARY KEY ("courseId", "prerequisiteId");

-- AlterTable
ALTER TABLE "Program" DROP CONSTRAINT "Program_pkey",
DROP COLUMN "programTypeIds",
DROP COLUMN "id",
ADD COLUMN "id" INTEGER NOT NULL,
ADD CONSTRAINT "Program_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "ProgramCourse" DROP CONSTRAINT "ProgramCourse_pkey",
ADD COLUMN "typicalSessionIndex" INTEGER NOT NULL,
DROP COLUMN "courseId",
ADD COLUMN "courseId" INTEGER NOT NULL,
DROP COLUMN "programId",
ADD COLUMN "programId" INTEGER NOT NULL,
ADD CONSTRAINT "ProgramCourse_pkey" PRIMARY KEY ("courseId", "programId");

-- CreateTable
CREATE TABLE "_ProgramToProgramType" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_ProgramToProgramType_AB_unique" ON "_ProgramToProgramType"("A", "B");

-- CreateIndex
CREATE INDEX "_ProgramToProgramType_B_index" ON "_ProgramToProgramType"("B");

-- CreateIndex
CREATE INDEX "Course_code_idx" ON "Course"("code");

-- CreateIndex
CREATE INDEX "CourseInstance_courseId_sessionId_idx" ON "CourseInstance"("courseId", "sessionId");

-- CreateIndex
CREATE UNIQUE INDEX "CourseInstance_courseId_sessionId_key" ON "CourseInstance"("courseId", "sessionId");

-- AddForeignKey
ALTER TABLE "CourseInstance" ADD CONSTRAINT "CourseInstance_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CoursePrerequisite" ADD CONSTRAINT "CoursePrerequisite_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CoursePrerequisite" ADD CONSTRAINT "CoursePrerequisite_prerequisiteId_fkey" FOREIGN KEY ("prerequisiteId") REFERENCES "Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ProgramCourse" ADD CONSTRAINT "ProgramCourse_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ProgramCourse" ADD CONSTRAINT "ProgramCourse_programId_fkey" FOREIGN KEY ("programId") REFERENCES "Program"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_ProgramToProgramType" ADD CONSTRAINT "_ProgramToProgramType_A_fkey" FOREIGN KEY ("A") REFERENCES "Program"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_ProgramToProgramType" ADD CONSTRAINT "_ProgramToProgramType_B_fkey" FOREIGN KEY ("B") REFERENCES "ProgramType"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Program" ALTER COLUMN "code" SET DATA TYPE TEXT;
36 changes: 19 additions & 17 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ model Session {

model CourseInstance {
id String @id @default(uuid())
courseId String
courseId Int
sessionId String

course Course @relation(fields: [courseId], references: [id])
Expand All @@ -47,8 +47,7 @@ model CourseInstance {
}

model Course {
id String @id
programId String
id Int @id
code String @unique
title String
description String
Expand All @@ -62,12 +61,12 @@ model Course {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([code, programId])
@@index([code])
}

model CoursePrerequisite {
courseId String
prerequisiteId String
courseId Int
prerequisiteId Int

course Course @relation("CourseToPrerequisite", fields: [courseId], references: [id])
prerequisite Course @relation("PrerequisiteToCourse", fields: [prerequisiteId], references: [id])
Expand All @@ -79,8 +78,9 @@ model CoursePrerequisite {
}

model ProgramCourse {
courseId String
programId String
courseId Int
programId Int
typicalSessionIndex Int

course Course @relation(fields: [courseId], references: [id])
program Program @relation(fields: [programId], references: [id])
Expand All @@ -92,13 +92,14 @@ model ProgramCourse {
}

model Program {
id String @id
code Int @unique
title String
credits String
cycle Int
url String
programTypeIds Json
id Int @id
code String @unique
title String
credits String
cycle Int
url String
programTypes ProgramType[]

horaireCoursPdfJson Json?
planificationPdfJson Json?
courses ProgramCourse[]
Expand All @@ -110,6 +111,7 @@ model Program {
}

model ProgramType {
id Int @id
title String
id Int @id
title String
programs Program[]
}
4 changes: 4 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';

@Controller()
export class AppController {
@Get()
@ApiOperation({
summary: 'Hello World',
})
public getHello(): string {
return 'Hello World!';
}
Expand Down
44 changes: 5 additions & 39 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,15 @@ import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';

import { AppController } from './app.controller';
import { EtsController } from './common/api-helper/ets/ets.controller';
import { EtsModule } from './common/api-helper/ets/ets.module';
import { FileUtil } from './common/utils/pdf/fileUtil';
import { PdfController } from './common/website-helper/pdf/pdf.controller';
import { HoraireCoursService } from './common/website-helper/pdf/pdf-parser/horaire/horaire-cours.service';
import { PlanificationCoursService } from './common/website-helper/pdf/pdf-parser/planification/planification-cours.service';
import { PdfModule } from './common/website-helper/pdf/pdf.module';
import config from './config/configuration';
import { CourseController } from './course/course.controller';
import { CourseModule } from './course/course.module';
import { CourseService } from './course/course.service';
import { CourseInstanceController } from './course-instance/course-instance.controller';
import { CourseInstanceModule } from './course-instance/course-instance.module';
import { CourseInstanceService } from './course-instance/course-instance.service';
import { CoursePrerequisiteController } from './course-prerequisite/course-prerequisite.controller';
import { CoursePrerequisiteModule } from './course-prerequisite/course-prerequisite.module';
import { CoursePrerequisiteService } from './course-prerequisite/course-prerequisite.service';
import { PrismaModule } from './prisma/prisma.module';
import { PrismaService } from './prisma/prisma.service';
import { ProgramController } from './program/program.controller';
import { ProgramModule } from './program/program.module';
import { ProgramService } from './program/program.service';
import { SessionController } from './session/session.controller';
import { SessionModule } from './session/session.module';
import { SessionService } from './session/session.service';

@Module({
imports: [
Expand All @@ -38,35 +23,16 @@ import { SessionService } from './session/session.service';
HttpModule,
PrismaModule,
EtsModule,
PdfModule,

CourseModule,
CourseInstanceModule,
CoursePrerequisiteModule,
SessionModule,
ProgramModule,
],
providers: [
PrismaService,
FileUtil,
HoraireCoursService,
PlanificationCoursService,

CourseService,
CourseInstanceService,
CoursePrerequisiteService,
ProgramService,
SessionService,
],
controllers: [
AppController,
PdfController,
EtsController,

CourseController,
CourseInstanceController,
CoursePrerequisiteController,
ProgramController,
SessionController,
],
providers: [],
controllers: [AppController],
exports: [HttpModule],
})
export class AppModule {}
2 changes: 2 additions & 0 deletions src/common/api-helper/ets/course/ets-course.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import {
EtsCourseService,
IEtsCourse,
IEtsCoursesData,
} from './ets-course.service';

@ApiTags('ÉTS API')
@Controller('ets/courses')
export class EtsCourseController {
constructor(private readonly etsCourseService: EtsCourseService) {}
Expand Down
35 changes: 0 additions & 35 deletions src/common/api-helper/ets/ets.controller.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/common/api-helper/ets/ets.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';

import { EtsCourseController } from './course/ets-course.controller';
import { EtsCourseService } from './course/ets-course.service';
import { EtsController } from './ets.controller';
import { EtsProgramController } from './program/ets-program.controller';
import { EtsProgramService } from './program/ets-program.service';

@Module({
imports: [HttpModule],
controllers: [EtsController],
controllers: [EtsCourseController, EtsProgramController],
providers: [EtsCourseService, EtsProgramService],
exports: [EtsCourseService, EtsProgramService],
})
Expand Down
15 changes: 15 additions & 0 deletions src/common/api-helper/ets/program/ets-program.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { EtsProgramService } from './ets-program.service';

@ApiTags('ÉTS API')
@Controller('ets/programs')
export class EtsProgramController {
constructor(private readonly etsProgramService: EtsProgramService) {}

@Get()
public async fetchAllPrograms() {
return this.etsProgramService.fetchAllPrograms();
}
}
Loading
Loading