-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move task to its own module and extends TaskRepository
- Loading branch information
Showing
20 changed files
with
219 additions
and
44 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Logger, Module } from "@nestjs/common"; | ||
import { AdminTaskConsumer } from "./infra/task/AdminTask.consumer"; | ||
import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository"; | ||
import configuration from "@config/configuration"; | ||
import { QueueModule } from "@infra/Queue.module"; | ||
import { ConfigModule } from "@nestjs/config"; | ||
import { DatabaseModule } from "@infra/Database.module"; | ||
import { TaskModule } from "@task/Task.module"; | ||
import { taskMongoProviders } from "@task/infra/TaskMongo.provider"; | ||
import { BullModule } from "@nestjs/bullmq"; | ||
import { QueueType } from "@shared/infra/Queue"; | ||
|
||
@Module({ | ||
imports: [ | ||
TaskModule, | ||
DatabaseModule, | ||
ConfigModule.forRoot({ | ||
load: [configuration], | ||
}), | ||
QueueModule, | ||
BullModule.registerQueue({ | ||
name: QueueType.ADMIN_TASK, | ||
}), | ||
], | ||
providers: [ | ||
Logger, | ||
AdminTaskConsumer, | ||
AdminTaskRepository, | ||
...taskMongoProviders, | ||
// add use case here | ||
], | ||
}) | ||
export class AdminJobModule { | ||
constructor(private logger: Logger) { | ||
this.logger.log("AdminJobModule has started", "AdminJobModule"); | ||
} | ||
} |
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,17 @@ | ||
import { CanActivate, ExecutionContext, Injectable, Logger } from "@nestjs/common"; | ||
import { isSuperAdmin } from "snu-lib"; | ||
|
||
@Injectable() | ||
export class SuperAdminGuard implements CanActivate { | ||
constructor() {} | ||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest(); | ||
|
||
// TODO : request.user mapping | ||
if (isSuperAdmin({ role: request.user.role, subRole: request.user.sousRole })) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import { SuperAdminGuard } from "src/admin/infra/iam/guard/SuperAdmin.guard"; | ||
import { ClasseAdminCleGuard } from "../classe/guard/ClasseAdminCle.guard"; | ||
import { ClasseDepartementGuard } from "../classe/guard/ClasseDepartement.guard"; | ||
import { ClasseGuardService } from "../classe/guard/ClasseGuard.service"; | ||
import { ClasseRegionGuard } from "../classe/guard/ClasseRegion.guard"; | ||
|
||
export const guardProviders = [ClasseGuardService, ClasseAdminCleGuard, ClasseRegionGuard, ClasseDepartementGuard]; | ||
export const guardProviders = [ | ||
ClasseGuardService, | ||
ClasseAdminCleGuard, | ||
ClasseRegionGuard, | ||
ClasseDepartementGuard, | ||
SuperAdminGuard, | ||
]; |
19 changes: 11 additions & 8 deletions
19
apiv2/src/shared/infra/task/Task.consumer.ts → ...rc/admin/infra/task/AdminTask.consumer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { InjectQueue } from "@nestjs/bullmq"; | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
import { QueueType } from "@shared/infra/Queue"; | ||
import { TaskGateway } from "@task/core/Task.gateway"; | ||
import { CreateTaskModel, TaskModel } from "@task/core/Task.model"; | ||
import { TaskMapper } from "@task/infra/Task.mapper"; | ||
import { Queue } from "bullmq"; | ||
import { Model } from "mongoose"; | ||
import { TASK_MONGOOSE_ENTITY, TaskDocument } from "src/task/infra/TaskMongo.provider"; | ||
import { TaskRepository } from "src/task/infra/TaskMongo.repository"; | ||
|
||
@Injectable() | ||
export class AdminTaskRepository extends TaskRepository implements TaskGateway { | ||
constructor( | ||
@Inject(TASK_MONGOOSE_ENTITY) protected taskMongooseEntity: Model<TaskDocument>, | ||
@InjectQueue(QueueType.ADMIN_TASK) private adminTaskQueue: Queue, | ||
) { | ||
super(taskMongooseEntity); | ||
} | ||
|
||
async create(task: CreateTaskModel): Promise<TaskModel> { | ||
const createdTask = await super.create(task); | ||
await this.adminTaskQueue.add(task.name, { ...TaskMapper.toQueue(createdTask) }); | ||
return createdTask; | ||
} | ||
} |
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 { Body, Controller, Get, Param, Post, Put, UseGuards } from "@nestjs/common"; | ||
import { CreateTaskModel, TaskModel } from "@task/core/Task.model"; | ||
import { AdminTaskRepository } from "../AdminTaskMongo.repository"; | ||
import { SuperAdminGuard } from "../../iam/guard/SuperAdmin.guard"; | ||
|
||
@Controller("task") | ||
export class AdminTaskController { | ||
constructor(private adminTaskRepository: AdminTaskRepository) {} | ||
|
||
@Get("/") | ||
@UseGuards(SuperAdminGuard) | ||
findAll(): Promise<TaskModel[]> { | ||
return this.adminTaskRepository.findAll(); | ||
} | ||
|
||
@Get(":id") | ||
@UseGuards(SuperAdminGuard) | ||
verify(@Param("id") id: string): Promise<TaskModel> { | ||
return this.adminTaskRepository.findById(id); | ||
} | ||
|
||
// TODO for testing purposes only => REMOVE | ||
@Post("/") | ||
@UseGuards(SuperAdminGuard) | ||
create(@Body() task: CreateTaskModel): Promise<TaskModel> { | ||
return this.adminTaskRepository.create(task); | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { TaskModel } from "@shared/core/task/Task.model"; | ||
import { TaskModel } from "src/task/core/Task.model"; | ||
|
||
export enum QueueType { | ||
TASK = "task", | ||
ADMIN_TASK = "admin-task", | ||
} | ||
|
||
export type TaskQueue = Pick<TaskModel, "id" | "name">; |
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,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { TaskRepository } from "./infra/TaskMongo.repository"; | ||
import { taskMongoProviders } from "./infra/TaskMongo.provider"; | ||
import { DatabaseModule } from "@infra/Database.module"; | ||
|
||
@Module({ | ||
imports: [DatabaseModule], | ||
providers: [TaskRepository, ...taskMongoProviders], | ||
exports: [TaskRepository], | ||
}) | ||
export class TaskModule {} |
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,12 @@ | ||
import { CreateTaskModel, TaskModel } from "./Task.model"; | ||
|
||
export interface TaskGateway { | ||
create(task: CreateTaskModel): Promise<TaskModel>; | ||
findAll(): Promise<TaskModel[]>; | ||
findById(id: string): Promise<TaskModel>; | ||
delete(id: string): Promise<void>; | ||
update(id: string, task: TaskModel): Promise<TaskModel>; | ||
toSuccess(id: string): Promise<TaskModel>; | ||
} | ||
|
||
export const TaskGateway = Symbol("TaskGateway"); |
File renamed without changes.
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
Oops, something went wrong.