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
19 changes: 18 additions & 1 deletion src/subdomains/supporting/mros/dto/create-mros.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsArray, IsDateString, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { MrosStatus } from '../mros-status.enum';

export class CreateMrosDto {
Expand All @@ -21,4 +21,21 @@ export class CreateMrosDto {
@IsNotEmpty()
@IsString()
caseManager: string;

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

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

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

@IsOptional()
@IsArray()
@IsString({ each: true })
indicators?: string[];
}
19 changes: 18 additions & 1 deletion src/subdomains/supporting/mros/dto/update-mros.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsDateString, IsEnum, IsString } from 'class-validator';
import { IsArray, IsDateString, IsEnum, IsString } from 'class-validator';
import { IsOptionalButNotNull } from 'src/shared/validators/is-not-null.validator';
import { MrosStatus } from '../mros-status.enum';

Expand All @@ -18,4 +18,21 @@ export class UpdateMrosDto {
@IsOptionalButNotNull()
@IsString()
caseManager?: string;

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

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

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

@IsOptionalButNotNull()
@IsArray()
@IsString({ each: true })
indicators?: string[];
}
21 changes: 21 additions & 0 deletions src/subdomains/supporting/mros/mros.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class Mros extends IEntity {
@Column({ length: 256 })
status: MrosStatus;

@Column({ length: 256, default: 'SAR' })
reportCode: string;

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

Expand All @@ -19,4 +22,22 @@ export class Mros extends IEntity {

@Column({ length: 256 })
caseManager: string;

@Column({ length: 'MAX', nullable: true })
reason?: string;

@Column({ length: 'MAX', nullable: true })
action?: string;

// JSON-serialized string[] of goAML indicator codes (e.g. ["0002M","1004V"])
@Column({ length: 'MAX', nullable: true })
indicators?: string;

get indicatorCodes(): string[] {
return this.indicators ? JSON.parse(this.indicators) : [];
}

set indicatorCodes(codes: string[]) {
this.indicators = JSON.stringify(codes);
}
}
13 changes: 10 additions & 3 deletions src/subdomains/supporting/mros/mros.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ export class MrosService {
) {}

async create(dto: CreateMrosDto): Promise<Mros> {
const entity = this.repo.create(dto);
const { userDataId, indicators, ...rest } = dto;
const entity = this.repo.create(rest);

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

if (indicators) entity.indicatorCodes = indicators;

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 });
const { indicators, ...rest } = dto;
Object.assign(entity, rest);
if (indicators !== undefined) entity.indicatorCodes = indicators;

return this.repo.save(entity);
}

async getAll(): Promise<Mros[]> {
Expand Down
Loading