Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions migration/1776937038432-AddMros.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/

/**
* @class
* @implements {MigrationInterface}
*/
module.exports = class AddMros1776937038432 {
name = 'AddMros1776937038432'

/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(`CREATE TABLE "mros" ("id" int NOT NULL IDENTITY(1,1), "updated" datetime2 NOT NULL CONSTRAINT "DF_f6ade72c09ca260e3ce42ba0781" DEFAULT getdate(), "created" datetime2 NOT NULL CONSTRAINT "DF_d7ed4994a2c27be9ea6c21b1c21" DEFAULT getdate(), "status" nvarchar(256) NOT NULL, "submissionDate" datetime2, "authorityReference" nvarchar(256), "caseManager" nvarchar(256) NOT NULL, "userDataId" int NOT NULL, CONSTRAINT "PK_48a5606a1194ef6f78c24999754" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "mros" ADD CONSTRAINT "FK_021227644566f36c31912257a39" FOREIGN KEY ("userDataId") REFERENCES "user_data"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}

/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "mros" DROP CONSTRAINT "FK_021227644566f36c31912257a39"`);
await queryRunner.query(`DROP TABLE "mros"`);
}
}
24 changes: 24 additions & 0 deletions src/subdomains/supporting/mros/dto/create-mros.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { MrosStatus } from '../mros-status.enum';

export class CreateMrosDto {
@IsNotEmpty()
@IsInt()
userDataId: number;

@IsNotEmpty()
@IsEnum(MrosStatus)
status: MrosStatus;

@IsOptional()
@IsDateString()
submissionDate?: Date;

@IsOptional()
@IsString()
authorityReference?: string;

@IsNotEmpty()
@IsString()
caseManager: string;
}
21 changes: 21 additions & 0 deletions src/subdomains/supporting/mros/dto/update-mros.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IsDateString, IsEnum, IsString } from 'class-validator';
import { IsOptionalButNotNull } from 'src/shared/validators/is-not-null.validator';
import { MrosStatus } from '../mros-status.enum';

export class UpdateMrosDto {
@IsOptionalButNotNull()
@IsEnum(MrosStatus)
status?: MrosStatus;

@IsOptionalButNotNull()
@IsDateString()
submissionDate?: Date;

@IsOptionalButNotNull()
@IsString()
authorityReference?: string;

@IsOptionalButNotNull()
@IsString()
caseManager?: string;
}
6 changes: 6 additions & 0 deletions src/subdomains/supporting/mros/mros-status.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum MrosStatus {
DRAFT = 'Draft',
SUBMITTED = 'Submitted',
CONFIRMED = 'Confirmed',
CLOSED = 'Closed',
}
48 changes: 48 additions & 0 deletions src/subdomains/supporting/mros/mros.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Body, Controller, Get, Param, Post, Put, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
import { RoleGuard } from 'src/shared/auth/role.guard';
import { UserActiveGuard } from 'src/shared/auth/user-active.guard';
import { UserRole } from 'src/shared/auth/user-role.enum';
import { CreateMrosDto } from './dto/create-mros.dto';
import { UpdateMrosDto } from './dto/update-mros.dto';
import { Mros } from './mros.entity';
import { MrosService } from './mros.service';

@ApiTags('Mros')
@Controller('mros')
export class MrosController {
constructor(private readonly mrosService: MrosService) {}

@Post()
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async createMros(@Body() dto: CreateMrosDto): Promise<void> {
await this.mrosService.create(dto);
}

@Put(':id')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async updateMros(@Param('id') id: string, @Body() dto: UpdateMrosDto): Promise<void> {
await this.mrosService.update(+id, dto);
}

@Get()
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async getAll(): Promise<Mros[]> {
return this.mrosService.getAll();
}

@Get(':id')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async getById(@Param('id') id: string): Promise<Mros> {
return this.mrosService.getById(+id);
}
}
22 changes: 22 additions & 0 deletions src/subdomains/supporting/mros/mros.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IEntity } from 'src/shared/models/entity';
import { UserData } from 'src/subdomains/generic/user/models/user-data/user-data.entity';
import { Column, Entity, ManyToOne } from 'typeorm';
import { MrosStatus } from './mros-status.enum';

@Entity()
export class Mros extends IEntity {
@ManyToOne(() => UserData, { nullable: false })
userData: UserData;

@Column({ length: 256 })
status: MrosStatus;

@Column({ type: 'datetime2', nullable: true })
submissionDate?: Date;

@Column({ length: 256, nullable: true })
authorityReference?: string;

@Column({ length: 256 })
caseManager: string;
}
16 changes: 16 additions & 0 deletions src/subdomains/supporting/mros/mros.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SharedModule } from 'src/shared/shared.module';
import { UserModule } from 'src/subdomains/generic/user/user.module';
import { MrosController } from './mros.controller';
import { Mros } from './mros.entity';
import { MrosRepository } from './mros.repository';
import { MrosService } from './mros.service';

@Module({
imports: [TypeOrmModule.forFeature([Mros]), SharedModule, UserModule],
controllers: [MrosController],
providers: [MrosRepository, MrosService],
exports: [],
})
export class MrosModule {}
11 changes: 11 additions & 0 deletions src/subdomains/supporting/mros/mros.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { BaseRepository } from 'src/shared/repositories/base.repository';
import { EntityManager } from 'typeorm';
import { Mros } from './mros.entity';

@Injectable()
export class MrosRepository extends BaseRepository<Mros> {
constructor(manager: EntityManager) {
super(Mros, manager);
}
}
41 changes: 41 additions & 0 deletions src/subdomains/supporting/mros/mros.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { UserDataService } from 'src/subdomains/generic/user/models/user-data/user-data.service';
import { CreateMrosDto } from './dto/create-mros.dto';
import { UpdateMrosDto } from './dto/update-mros.dto';
import { Mros } from './mros.entity';
import { MrosRepository } from './mros.repository';

@Injectable()
export class MrosService {
constructor(
private readonly repo: MrosRepository,
private readonly userDataService: UserDataService,
) {}

async create(dto: CreateMrosDto): Promise<Mros> {
const entity = this.repo.create(dto);

entity.userData = await this.userDataService.getUserData(dto.userDataId);
if (!entity.userData) throw new NotFoundException('UserData not found');

return this.repo.save(entity);
}

async update(id: number, dto: UpdateMrosDto): Promise<Mros> {
const entity = await this.repo.findOneBy({ id });
if (!entity) throw new NotFoundException('Mros not found');

return this.repo.save({ ...entity, ...dto });
}

async getAll(): Promise<Mros[]> {
return this.repo.find({ relations: { userData: true } });
}

async getById(id: number): Promise<Mros> {
const entity = await this.repo.findOne({ where: { id }, relations: { userData: true } });
if (!entity) throw new NotFoundException('Mros not found');

return entity;
}
}
23 changes: 20 additions & 3 deletions src/subdomains/supporting/recall/recall.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Body, Controller, Param, Post, Put, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Param, Post, Put, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
import { RoleGuard } from 'src/shared/auth/role.guard';
import { UserActiveGuard } from 'src/shared/auth/user-active.guard';
import { UserRole } from 'src/shared/auth/user-role.enum';
import { CreateRecallDto } from './dto/create-recall.dto';
import { UpdateRecallDto } from './dto/update-recall.dto';
import { Recall } from './recall.entity';
import { RecallService } from './recall.service';

@ApiTags('Recall')
Expand All @@ -16,16 +17,32 @@ export class RecallController {
@Post()
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async createRecall(@Body() dto: CreateRecallDto): Promise<void> {
await this.recallService.create(dto);
}

@Put(':id')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async updateRecall(@Param('id') id: string, @Body() dto: UpdateRecallDto): Promise<void> {
await this.recallService.update(+id, dto);
}

@Get()
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async getAll(): Promise<Recall[]> {
return this.recallService.getAll();
}

@Get(':id')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.COMPLIANCE), UserActiveGuard())
async getById(@Param('id') id: string): Promise<Recall> {
return this.recallService.getById(+id);
}
}
14 changes: 14 additions & 0 deletions src/subdomains/supporting/recall/recall.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ export class RecallService {

return this.repo.save({ ...entity, ...dto });
}

async getAll(): Promise<Recall[]> {
return this.repo.find({ relations: { bankTx: true, checkoutTx: true, user: true } });
}

async getById(id: number): Promise<Recall> {
const entity = await this.repo.findOne({
where: { id },
relations: { bankTx: true, checkoutTx: true, user: true },
});
if (!entity) throw new NotFoundException('Recall not found');

return entity;
}
}
2 changes: 2 additions & 0 deletions src/subdomains/supporting/supporting.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DexModule } from './dex/dex.module';
import { FiatOutputModule } from './fiat-output/fiat-output.module';
import { FiatPayInModule } from './fiat-payin/fiat-payin.module';
import { LogModule } from './log/log.module';
import { MrosModule } from './mros/mros.module';
import { NotificationModule } from './notification/notification.module';
import { PayInModule } from './payin/payin.module';
import { PayoutModule } from './payout/payout.module';
Expand All @@ -34,6 +35,7 @@ import { SupportIssueModule } from './support-issue/support-issue.module';
FiatOutputModule,
SupportIssueModule,
RecallModule,
MrosModule,
],
controllers: [],
providers: [],
Expand Down
Loading