Skip to content

Commit

Permalink
Init mm nitifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fuuuzz committed Jun 26, 2024
1 parent 6d0e5c9 commit 8c88d55
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 10 deletions.
26 changes: 26 additions & 0 deletions migrations/1717147942177-create-notification-table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."notification_type_enum" AS ENUM('post', 'comment', 'reaction')`
);
await queryRunner.query(
`CREATE TABLE "notification" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "type" "public"."notification_type_enum" NOT NULL, "resourceId" character varying NOT NULL, "message" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "leaveRequestId" uuid, CONSTRAINT "PK_705b6c7cdf9b2c2ff7ac7872cb7" PRIMARY KEY ("id"))`
);
await queryRunner.query(
`ALTER TABLE "notification" ADD CONSTRAINT "FK_d7dcd7fa90cc4542719b880bc7f" FOREIGN KEY ("leaveRequestId") REFERENCES "leave_request"("id") ON DELETE SET NULL ON UPDATE NO ACTION`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "notification" DROP CONSTRAINT "FK_d7dcd7fa90cc4542719b880bc7f"`
);
await queryRunner.query(`DROP TABLE "notification"`);
await queryRunner.query(`DROP TYPE "public"."notification_type_enum"`);
}
}
109 changes: 100 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@concepta/typeorm-seeding": "^4.0.0-beta.0",
"@faker-js/faker": "^7.6.0",
"@fluent/bundle": "^0.18.0",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^9.2.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.2.0",
Expand All @@ -40,6 +41,7 @@
"@nestjs/swagger": "^6.1.3",
"@nestjs/typeorm": "^9.0.1",
"argon2": "^0.26.2",
"axios": "^1.7.2",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"connect-typeorm": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { DoesLeaveRequestExistForPeriod } from 'src/Domain/HumanResource/Leave/S
import { LeaveRequestAlreadyExistForThisPeriodException } from 'src/Domain/HumanResource/Leave/Exception/LeaveRequestAlreadyExistForThisPeriodException';
import { DoesLeaveExistForPeriod } from 'src/Domain/FairCalendar/Specification/DoesLeaveExistForPeriod';
import { EventsOrLeavesAlreadyExistForThisPeriodException } from 'src/Domain/FairCalendar/Exception/EventsOrLeavesAlreadyExistForThisPeriodException';
import { IMattermostNotifier } from 'src/Application/IMattermostNotifier';

@CommandHandler(CreateLeaveRequestCommand)
export class CreateLeaveRequestCommandHandler {
constructor(
@Inject('ILeaveRequestRepository')
private readonly leaveRequestRepository: ILeaveRequestRepository,
private readonly doesLeaveRequestExistForPeriod: DoesLeaveRequestExistForPeriod,
private readonly doesLeaveExistForPeriod: DoesLeaveExistForPeriod
private readonly doesLeaveExistForPeriod: DoesLeaveExistForPeriod,
@Inject('IMattermostNotifier')
private readonly mattermostNotifier: IMattermostNotifier
) {}

public async execute(command: CreateLeaveRequestCommand): Promise<string> {
Expand Down Expand Up @@ -62,6 +65,11 @@ export class CreateLeaveRequestCommandHandler {
)
);

this.mattermostNotifier.createPost(
process.env.MATTERMOST_CHANNEL_LEAVES_ID,
'HELLO FROM PERMACOOOOOOOOP'
);

return leaveRequest.getId();
}
}
9 changes: 9 additions & 0 deletions src/Application/IMattermostNotifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface IMattermostNotifier {
createPost(channelId: string, message: string): Promise<object>;
createComment(
channelId: string,
message: string,
rootId: string
): Promise<object>;
createReaction(postId: string, emojiName: string): Promise<object>;
}
65 changes: 65 additions & 0 deletions src/Domain/Notification/Notification.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { LeaveRequest } from '../HumanResource/Leave/LeaveRequest.entity';

export enum Type {
POST = 'post',
COMMENT = 'comment',
REACTION = 'reaction'
}

@Entity()
export class Notification {
@PrimaryGeneratedColumn('uuid')
private id: string;

@Column('enum', { enum: Type, nullable: false })
private type: Type;

@Column({ type: 'varchar', nullable: false })
private resourceId: string;

@Column({ type: 'varchar', nullable: false })
private message: string;

@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
private createdAt: Date;

@ManyToOne(type => LeaveRequest, { nullable: true, onDelete: 'SET NULL' })
private leaveRequest: LeaveRequest;

constructor(
type: Type,
message: string,
resourceId: string,
leaveRequest: LeaveRequest
) {
this.type = type;
this.message = message;
this.resourceId = resourceId;
this.leaveRequest = leaveRequest;
}

public getId(): string {
return this.id;
}

public getType(): string {
return this.type;
}

public getMessage(): string {
return this.message;
}

public getResourceId(): string {
return this.resourceId;
}

public getLeaveRequest(): LeaveRequest {
return this.leaveRequest;
}

public getCreatedAt(): Date {
return this.createdAt;
}
}
Loading

0 comments on commit 8c88d55

Please sign in to comment.