Skip to content

Commit

Permalink
Add Swagger API documentation & fix program creation parameters (#31)
Browse files Browse the repository at this point in the history
* Add common folder

* Add program resource

* Fix eslint rule (complexity) & fix dependencies versions

* add course, cours-instance

* add session resource

* Add prisma, scraper, program files (modules and services)

* Fix prisma & add scraper files & eslint migration

* chore: address sonarlint warning (if statement)

* Rollback eslint flat to v8 & remove entity & format imports

* add public to classes

* cleanup

* add ets api hekper files

* add ets-program logic & (WIP) upsert programs

* Remove unnecessary dtos

* (wip 🚔) Add controllers & fix course routes

* fix tests

* Fix ProgramType relation

* Add coursePrerequisite controller & service

* Move scraper folder into /common

* Move pdf folder into /common

* fix http & add prisma to app module

* fix tests (wip) & sessions route

* fix tests

* rename

* Add schema image generator

* add methods

* fix

* change "program to programType" relation

* fix ci test

* miaow miaow

* test test

* only run eslint on src folder

* Rollback to ".test.ts" only

* pdf small test

* fix logging

* fix PR & remove scraper folder

* update enum trimester

* remove file

* fix param

* Add swagger

* fix program creation parameters & some route parameters

* fix axios vulnerability

* logger instead of console.log
  • Loading branch information
mhd-hi authored Aug 29, 2024
1 parent 9dae27e commit 5219b01
Show file tree
Hide file tree
Showing 28 changed files with 317 additions and 145 deletions.
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

0 comments on commit 5219b01

Please sign in to comment.