Skip to content

Commit

Permalink
Merge branch 'master' into crud_users_courses
Browse files Browse the repository at this point in the history
  • Loading branch information
PluckySquirrel authored Oct 9, 2024
2 parents 623435d + 96a0e81 commit 7fd83ad
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules/
dist/
**/**/*.log
env/*.env
src/migration/*.ts

# Logs
logs
Expand Down
2 changes: 1 addition & 1 deletion env/development.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ DB_HOST=''
DB_PORT=''
DB_USERNAME=''
DB_PASSWORD=''
DB_DATABASE=''
DB_DATABASE=''
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default tseslint.config(
{ files: ['**/*.ts'] },
{
rules: {
'@typescript-eslint/explicit-member-accessibility': 'warn',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-misused-promises': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/no-confusing-void-expression': 0,
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"lint:tests": "npx eslint ./spec",
"start": "NODE_ENV=development node -r ./preload.js ./dist",
"test": "NODE_ENV=test npx ts-node ./spec",
"test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec -e ts"
"test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec -e ts",
"add:migration": "npm run typeorm -- -d ./src/repos/db.ts migration:generate ./src/migration/$npm_config_name",
"revert:migration": "npm run typeorm migration:revert -- -d ./src/repos/db.ts",
"apply:migration": "npm run typeorm migration:run -- -d ./src/repos/db.ts",
"typeorm": "ts-node --transpile-only -r tsconfig-paths/register ./node_modules/typeorm/cli.js"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/entity/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { Lesson } from './Lesson';

Expand Down
2 changes: 1 addition & 1 deletion src/entity/EnrollmentLesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { Enrollment } from './Enrollment';
import { Lesson } from './Lesson';
Expand Down
2 changes: 1 addition & 1 deletion src/entity/Lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { Section } from './Section';

Expand Down
2 changes: 1 addition & 1 deletion src/entity/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { User } from './User';
import { Course } from './Course';
Expand Down
2 changes: 1 addition & 1 deletion src/entity/Review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { User } from './User';
import { Course } from './Course';
Expand Down
2 changes: 1 addition & 1 deletion src/entity/Section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity,
ManyToOne,
CreateDateColumn,
UpdateDateColumn,
JoinColumn
JoinColumn
} from 'typeorm';
import { Course } from './Course';

Expand Down
2 changes: 1 addition & 1 deletion src/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Entity,
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn
UpdateDateColumn
} from 'typeorm';

@Entity('users')
Expand Down
58 changes: 58 additions & 0 deletions src/migration/1728392492258-first_migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class FirstMigration1728392492258 implements MigrationInterface {
name = 'FirstMigration1728392492258';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('CREATE TABLE `users` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `role` enum (\'user\', \'professor\', \'admin\') NOT NULL DEFAULT \'user\', `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `courses` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `price` double NOT NULL, `description` text NOT NULL, `average_rating` float NOT NULL, `professor_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `reviews` (`id` bigint NOT NULL AUTO_INCREMENT, `rating` int NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `sections` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `total_time` int NOT NULL, `total_lesson` int NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `payments` (`id` bigint NOT NULL AUTO_INCREMENT, `amount` double NOT NULL, `payment_date` date NOT NULL, `status` enum (\'pending\', \'done\') NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `lessons` (`id` bigint NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text NOT NULL, `time` int NOT NULL, `section_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `enrollments` (`id` bigint NOT NULL AUTO_INCREMENT, `enrollment_date` datetime NOT NULL, `progress` int NOT NULL, `completion_date` datetime NOT NULL, `user_id` bigint NOT NULL, `course_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `enrollments_lessons` (`id` bigint NOT NULL AUTO_INCREMENT, `progress` int NOT NULL, `completion_date` datetime NOT NULL, `enrollment_id` bigint NOT NULL, `lesson_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `components` (`id` bigint NOT NULL AUTO_INCREMENT, `type` enum (\'video\', \'url\', \'pdf\', \'text\') NOT NULL, `content` text NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `lesson_id` bigint NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('CREATE TABLE `comments` (`id` bigint NOT NULL AUTO_INCREMENT, `parent_id` bigint NOT NULL, `comment_text` text NOT NULL, `review_id` bigint NOT NULL, `created_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), `updated_at` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (`id`)) ENGINE=InnoDB');
await queryRunner.query('ALTER TABLE `courses` ADD CONSTRAINT `FK_7722a465aa381126eb553158c73` FOREIGN KEY (`professor_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `reviews` ADD CONSTRAINT `FK_728447781a30bc3fcfe5c2f1cdf` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `reviews` ADD CONSTRAINT `FK_f99062f36181ab42863facfaea3` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `sections` ADD CONSTRAINT `FK_53ccbd6e2fa20dac9062f4f4c36` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `payments` ADD CONSTRAINT `FK_427785468fb7d2733f59e7d7d39` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `payments` ADD CONSTRAINT `FK_c5fa169d2de9407d99f2c6e4fab` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `lessons` ADD CONSTRAINT `FK_19261e484ffd22b40ea596ece4d` FOREIGN KEY (`section_id`) REFERENCES `sections`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `enrollments` ADD CONSTRAINT `FK_ff997f5a39cd24a491b9aca45c9` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `enrollments` ADD CONSTRAINT `FK_b79d0bf01779fdf9cfb6b092af3` FOREIGN KEY (`course_id`) REFERENCES `courses`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `enrollments_lessons` ADD CONSTRAINT `FK_8c1f7f99b8fd21076b8ae547bba` FOREIGN KEY (`enrollment_id`) REFERENCES `enrollments`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `enrollments_lessons` ADD CONSTRAINT `FK_a0b2d6a99bbb3ab51916259b3c1` FOREIGN KEY (`lesson_id`) REFERENCES `lessons`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `components` ADD CONSTRAINT `FK_1184609d2ce4aec53e82e051051` FOREIGN KEY (`lesson_id`) REFERENCES `lessons`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
await queryRunner.query('ALTER TABLE `comments` ADD CONSTRAINT `FK_0fe168752ce3bb4e7376d81f7ad` FOREIGN KEY (`review_id`) REFERENCES `reviews`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION');
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('ALTER TABLE `comments` DROP FOREIGN KEY `FK_0fe168752ce3bb4e7376d81f7ad`');
await queryRunner.query('ALTER TABLE `components` DROP FOREIGN KEY `FK_1184609d2ce4aec53e82e051051`');
await queryRunner.query('ALTER TABLE `enrollments_lessons` DROP FOREIGN KEY `FK_a0b2d6a99bbb3ab51916259b3c1`');
await queryRunner.query('ALTER TABLE `enrollments_lessons` DROP FOREIGN KEY `FK_8c1f7f99b8fd21076b8ae547bba`');
await queryRunner.query('ALTER TABLE `enrollments` DROP FOREIGN KEY `FK_b79d0bf01779fdf9cfb6b092af3`');
await queryRunner.query('ALTER TABLE `enrollments` DROP FOREIGN KEY `FK_ff997f5a39cd24a491b9aca45c9`');
await queryRunner.query('ALTER TABLE `lessons` DROP FOREIGN KEY `FK_19261e484ffd22b40ea596ece4d`');
await queryRunner.query('ALTER TABLE `payments` DROP FOREIGN KEY `FK_c5fa169d2de9407d99f2c6e4fab`');
await queryRunner.query('ALTER TABLE `payments` DROP FOREIGN KEY `FK_427785468fb7d2733f59e7d7d39`');
await queryRunner.query('ALTER TABLE `sections` DROP FOREIGN KEY `FK_53ccbd6e2fa20dac9062f4f4c36`');
await queryRunner.query('ALTER TABLE `reviews` DROP FOREIGN KEY `FK_f99062f36181ab42863facfaea3`');
await queryRunner.query('ALTER TABLE `reviews` DROP FOREIGN KEY `FK_728447781a30bc3fcfe5c2f1cdf`');
await queryRunner.query('ALTER TABLE `courses` DROP FOREIGN KEY `FK_7722a465aa381126eb553158c73`');
await queryRunner.query('DROP TABLE `comments`');
await queryRunner.query('DROP TABLE `components`');
await queryRunner.query('DROP TABLE `enrollments_lessons`');
await queryRunner.query('DROP TABLE `enrollments`');
await queryRunner.query('DROP TABLE `lessons`');
await queryRunner.query('DROP TABLE `payments`');
await queryRunner.query('DROP TABLE `sections`');
await queryRunner.query('DROP TABLE `reviews`');
await queryRunner.query('DROP TABLE `courses`');
await queryRunner.query('DROP TABLE `users`');
}

}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@
"exclude": [
"src/public/*"
]
}
}

0 comments on commit 7fd83ad

Please sign in to comment.