Skip to content

Commit

Permalink
Refactor code structure & add ÉTS API integration for courses and pro…
Browse files Browse the repository at this point in the history
…grams (#29)

* 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
  • Loading branch information
mhd-hi authored Aug 26, 2024
1 parent 9eed67e commit 9dae27e
Show file tree
Hide file tree
Showing 72 changed files with 2,825 additions and 298 deletions.
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATABASE_URL="postgresql://postgres:randompassword@localhost:5432/mydb?schema=public"
NODE_ENV=development

## if no password, use this instead:
# DATABASE_URL="postgresql://postgres@localhost:5432/mydb?schema=public"
PORT=3000

DATABASE_URL="postgresql://postgres@localhost:5432/planifetsDB?schema=public"
89 changes: 45 additions & 44 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'import', 'simple-import-sort'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'airbnb-typescript/base',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js', 'dist/'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
complexity: ['warn', { max: 10 }],
complexity: ['error', { max: 15 }],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
overrides: {
constructors: 'no-public',
},
},
],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'prettier/prettier': [
'error',
{
endOfLine: 'lf',
},
],
indent: 'off',
'@typescript-eslint/indent': 'off',
},
};
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'import', 'simple-import-sort'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'airbnb-typescript/base',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js', 'dist/'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
complexity: ['warn', { max: 10 }],
complexity: ['error', { max: 15 }],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
overrides: {
constructors: 'no-public',
},
},
],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'prettier/prettier': [
'error',
{
endOfLine: 'lf',
},
],
'@typescript-eslint/brace-style': 'off',
indent: 'off',
'@typescript-eslint/indent': 'off',
},
};
15 changes: 8 additions & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "lf"
}
12 changes: 6 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"rvest.vs-code-prettier-eslint"
]
}
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"abians.prisma-generate-uml"
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.eol": "\n"
"files.eol": "\n",
"typescript.preferences.importModuleSpecifier": "relative",
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "planif-ets-backend",
"name": "planifets-backend",
"version": "0.0.1",
"description": "",
"author": "",
Expand All @@ -13,7 +13,7 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint .",
"lint": "eslint src --ext .ts",
"refresh": "rm -rf dist && rm -rf node_modules && yarn cache clean && yarn install",
"prisma:generate": "prisma generate",
"prisma:preview": "prisma migrate dev --create-only",
Expand All @@ -35,8 +35,9 @@
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.1",
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "^2.0.5",
"@nestjs/platform-express": "^10.0.0",
"@prisma/client": "^5.7.1",
"@prisma/client": "^5.15.0",
"axios": "^1.6.8",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand Down Expand Up @@ -69,6 +70,7 @@
"prettier": "^3.2.5",
"prettier-eslint": "^16.3.0",
"prisma": "^5.7.1",
"prisma-erd-generator": "^1.11.2",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
Expand All @@ -95,4 +97,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
1 change: 1 addition & 0 deletions 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,23 @@
/*
Warnings:
- You are about to drop the column `abbreviation` on the `Program` table. All the data in the column will be lost.
- You are about to drop the column `type` on the `Program` table. All the data in the column will be lost.
- A unique constraint covering the columns `[code,title]` on the table `Program` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Program" DROP COLUMN "abbreviation",
DROP COLUMN "type",
ADD COLUMN "types" INTEGER[];

-- CreateTable
CREATE TABLE "ProgramType" (
"id" INTEGER NOT NULL,
"title" TEXT NOT NULL,

CONSTRAINT "ProgramType_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Program_code_title_key" ON "Program"("code", "title");
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Warnings:
- You are about to drop the column `unstructuredPrerequisites` on the `Course` table. All the data in the column will be lost.
- You are about to drop the column `types` on the `Program` table. All the data in the column will be lost.
- You are about to drop the column `name` on the `Session` table. All the data in the column will be lost.
- Added the required column `programTypeId` to the `Program` table without a default value. This is not possible if the table is not empty.
- Added the required column `trimester` to the `Session` table without a default value. This is not possible if the table is not empty.
*/
-- CreateEnum
CREATE TYPE "Trimester" AS ENUM ('A', 'E', 'H');

-- AlterTable
ALTER TABLE "Course" DROP COLUMN "unstructuredPrerequisites";

-- AlterTable
ALTER TABLE "Program" DROP COLUMN "types",
ADD COLUMN "programTypeId" INTEGER NOT NULL;

-- AlterTable
CREATE SEQUENCE programtype_id_seq;
ALTER TABLE "ProgramType" ALTER COLUMN "id" SET DEFAULT nextval('programtype_id_seq');
ALTER SEQUENCE programtype_id_seq OWNED BY "ProgramType"."id";

-- AlterTable
ALTER TABLE "Session" DROP COLUMN "name",
ADD COLUMN "trimester" "Trimester" NOT NULL;

-- CreateIndex
CREATE INDEX "Program_programTypeId_idx" ON "Program"("programTypeId");

-- AddForeignKey
ALTER TABLE "Program" ADD CONSTRAINT "Program_programTypeId_fkey" FOREIGN KEY ("programTypeId") REFERENCES "ProgramType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the column `programTypeId` on the `Program` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Program" DROP CONSTRAINT "Program_programTypeId_fkey";

-- DropIndex
DROP INDEX "Program_programTypeId_idx";

-- AlterTable
ALTER TABLE "Program" DROP COLUMN "programTypeId",
ADD COLUMN "programTypeIds" TEXT NOT NULL DEFAULT '[]';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:
- Added the required column `cycle` to the `Program` table without a default value. This is not possible if the table is not empty.
- Changed the type of `programTypeIds` 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.
*/
-- AlterTable
ALTER TABLE "Program" ADD COLUMN "cycle" INTEGER NOT NULL,
ALTER COLUMN "credits" SET DATA TYPE TEXT,
DROP COLUMN "programTypeIds",
ADD COLUMN "programTypeIds" JSONB NOT NULL;

-- AlterTable
ALTER TABLE "ProgramType" ALTER COLUMN "id" DROP DEFAULT;
DROP SEQUENCE "programtype_id_seq";
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- The values [A,E,H] on the enum `Trimester` will be removed. If these variants are still used in the database, this will fail.
*/
-- AlterEnum
BEGIN;
CREATE TYPE "Trimester_new" AS ENUM ('AUTOMNE', 'ETE', 'HIVER');
ALTER TABLE "Session" ALTER COLUMN "trimester" TYPE "Trimester_new" USING ("trimester"::text::"Trimester_new");
ALTER TYPE "Trimester" RENAME TO "Trimester_old";
ALTER TYPE "Trimester_new" RENAME TO "Trimester";
DROP TYPE "Trimester_old";
COMMIT;
Loading

0 comments on commit 9dae27e

Please sign in to comment.