-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
655 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class SchoolUsers1617268818418 implements MigrationInterface { | ||
name = 'SchoolUsers1617268818418' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "school" DROP CONSTRAINT "FK_bbfa0c35398b642f1e3903e9789"`); | ||
await queryRunner.query(`ALTER TABLE "school" RENAME COLUMN "directorId" TO "email"`); | ||
await queryRunner.query(`CREATE TABLE "school_user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "schoolId" uuid NOT NULL, "userId" uuid NOT NULL, CONSTRAINT "PK_b75c78082d7ea9dff30f9aba409" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`ALTER TABLE "lead" ALTER COLUMN "email" DROP NOT NULL`); | ||
await queryRunner.query(`ALTER TABLE "school" DROP COLUMN "email"`); | ||
await queryRunner.query(`ALTER TABLE "school" ADD "email" character varying`); | ||
await queryRunner.query(`ALTER TABLE "school_user" ADD CONSTRAINT "FK_414383e1bc95a2c691ddfd7a49f" FOREIGN KEY ("schoolId") REFERENCES "school"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "school_user" ADD CONSTRAINT "FK_85a63063b7de70a37efc967c156" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "school_user" DROP CONSTRAINT "FK_85a63063b7de70a37efc967c156"`); | ||
await queryRunner.query(`ALTER TABLE "school_user" DROP CONSTRAINT "FK_414383e1bc95a2c691ddfd7a49f"`); | ||
await queryRunner.query(`ALTER TABLE "school" DROP COLUMN "email"`); | ||
await queryRunner.query(`ALTER TABLE "school" ADD "email" uuid`); | ||
await queryRunner.query(`ALTER TABLE "lead" ALTER COLUMN "email" SET NOT NULL`); | ||
await queryRunner.query(`DROP TABLE "school_user"`); | ||
await queryRunner.query(`ALTER TABLE "school" RENAME COLUMN "email" TO "directorId"`); | ||
await queryRunner.query(`ALTER TABLE "school" ADD CONSTRAINT "FK_bbfa0c35398b642f1e3903e9789" FOREIGN KEY ("directorId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); | ||
} | ||
|
||
} |
42 changes: 0 additions & 42 deletions
42
api/src/Application/School/Command/AssignDirectorToSchoolCommandHandler.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../Command/AssignDirectorToSchoolCommand.ts → ...Command/User/AssignUserToSchoolCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
api/src/Application/School/Command/User/AssignUserToSchoolCommandHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { CommandHandler } from '@nestjs/cqrs'; | ||
import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException'; | ||
import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository'; | ||
import { ISchoolUserRepository } from 'src/Domain/School/Repository/ISchoolUserRepository'; | ||
import { SchoolUser } from 'src/Domain/School/SchoolUser.entity'; | ||
import { UserAlreadyAssignedToSchoolException } from 'src/Domain/User/Exception/UserAlreadyAssignedToSchoolException'; | ||
import { UserNotFoundException } from 'src/Domain/User/Exception/UserNotFoundException'; | ||
import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository'; | ||
import { IsUserAlreadyAssignedToSchool } from 'src/Domain/User/Specification/IsUserAlreadyAssignedToSchool'; | ||
import { AssignUserToSchoolCommand } from './AssignUserToSchoolCommand'; | ||
|
||
@CommandHandler(AssignUserToSchoolCommand) | ||
export class AssignUserToSchoolCommandHandler { | ||
constructor( | ||
@Inject('ISchoolRepository') | ||
private readonly schoolRepository: ISchoolRepository, | ||
@Inject('ISchoolUserRepository') | ||
private readonly schoolUserRepository: ISchoolUserRepository, | ||
@Inject('IUserRepository') | ||
private readonly userRepository: IUserRepository, | ||
private readonly isUserAlreadyAssignedToSchool: IsUserAlreadyAssignedToSchool, | ||
) {} | ||
|
||
public async execute(command: AssignUserToSchoolCommand): Promise<string> { | ||
const { schoolId, userId } = command; | ||
|
||
const school = await this.schoolRepository.findOneById(schoolId); | ||
if (!school) { | ||
throw new SchoolNotFoundException(); | ||
} | ||
|
||
const user = await this.userRepository.findOneById(userId); | ||
if (!user) { | ||
throw new UserNotFoundException(); | ||
} | ||
|
||
if (true === (await this.isUserAlreadyAssignedToSchool.isSatisfiedBy(school, user))) { | ||
throw new UserAlreadyAssignedToSchoolException(); | ||
} | ||
|
||
const schoolUser = await this.schoolUserRepository.save( | ||
new SchoolUser(school, user) | ||
); | ||
|
||
return schoolUser.getId(); | ||
} | ||
} |
Oops, something went wrong.