Skip to content

Commit

Permalink
Add Notification Statuses
Browse files Browse the repository at this point in the history
* Add statuses to notifications
  • Loading branch information
Daniel Haselhan committed Sep 5, 2023
1 parent 82118d8 commit 1276c91
Show file tree
Hide file tree
Showing 22 changed files with 1,133 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h4 *ngIf="submission">SRW ID: {{ submission.fileNumber }}</h4>
</div>
<div>
<div class="subheading2">SRW Status</div>
<span *ngIf="submission">TODO</span>
<span *ngIf="submission">{{ submission.status.label }}</span>
</div>
</div>
</div>
Expand All @@ -24,7 +24,7 @@ <h4 *ngIf="submission">SRW ID: {{ submission.fileNumber }}</h4>
</div>
<div>
<div class="subheading2">SRW Status</div>
<span *ngIf="submission">TODO</span>
<span *ngIf="submission">{{ submission.status.label }}</span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
import { NoticeOfIntentSubmissionDetailedDto } from '../../../services/notice-of-intent-submission/notice-of-intent-submission.dto';
import { NotificationSubmissionDto } from '../../../services/notification-submission/notification-submission.dto';
import { NotificationSubmissionService } from '../../../services/notification-submission/notification-submission.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import { BaseCodeDto } from '../../shared/dto/base.dto';
import { NOI_SUBMISSION_STATUS } from '../notice-of-intent-submission/notice-of-intent-submission.dto';
import { NotificationTransfereeDto } from '../notification-transferee/notification-transferee.dto';

export enum NOTIFICATION_STATUS {
IN_PROGRESS = 'PROG',
SUBMITTED_TO_ALC = 'SUBM', //Submitted to ALC
ALC_RESPONSE = 'ALCR', // Response sent
CANCELLED = 'CANC',
}

export interface NotificationSubmissionStatusDto extends BaseCodeDto {
code: NOI_SUBMISSION_STATUS;
portalBackgroundColor: string;
portalColor: string;
}

export interface NotificationSubmissionToSubmissionStatusDto {
submissionUuid: string;
effectiveDate: number | null;
statusTypeCode: string;
status: NotificationSubmissionStatusDto;
}

export interface NotificationSubmissionDto {
fileNumber: string;
uuid: string;
Expand All @@ -9,6 +31,7 @@ export interface NotificationSubmissionDto {
localGovernmentUuid: string;
type: string;
typeCode: string;
status: NotificationSubmissionStatusDto;
lastStatusUpdate: number;
owners: NotificationTransfereeDto[];
canEdit: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AutoMap } from '@automapper/classes';
import { Column, Entity, OneToMany } from 'typeorm';
import { BaseCodeEntity } from '../../../common/entities/base.code.entity';
import { NotificationSubmissionToSubmissionStatus } from './notification-status.entity';

@Entity()
export class NotificationSubmissionStatusType extends BaseCodeEntity {
constructor(data?: Partial<NotificationSubmissionStatusType>) {
super();
if (data) {
Object.assign(this, data);
}
}

@AutoMap(() => Number)
@Column({ type: 'smallint', default: 0 })
weight: number;

@OneToMany(
() => NotificationSubmissionToSubmissionStatus,
(s) => s.statusType,
)
public submissionStatuses: NotificationSubmissionToSubmissionStatus[];

@AutoMap()
@Column()
alcsBackgroundColor: string;

@AutoMap()
@Column()
alcsColor: string;

@AutoMap()
@Column()
portalBackgroundColor: string;

@AutoMap()
@Column()
portalColor: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { AutoMap } from '@automapper/classes';
import { BaseCodeDto } from '../../../common/dtos/base.dto';

export enum NOTIFICATION_STATUS {
IN_PROGRESS = 'PROG',
SUBMITTED_TO_ALC = 'SUBM', //Submitted to ALC
ALC_RESPONSE_SENT = 'ALCR', //Response sent to applicant
CANCELLED = 'CANC',
}

export class NotificationStatusDto extends BaseCodeDto {
@AutoMap()
alcsBackgroundColor: string;

@AutoMap()
alcsColor: string;

@AutoMap()
portalBackgroundColor: string;

@AutoMap()
portalColor: string;

@AutoMap()
weight: number;
}

export class NotificationSubmissionToSubmissionStatusDto {
@AutoMap()
submissionUuid: string;

@AutoMap()
effectiveDate: number;

@AutoMap()
statusTypeCode: string;

@AutoMap(() => NotificationStatusDto)
status: NotificationStatusDto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { AutoMap } from '@automapper/classes';
import {
BaseEntity,
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryColumn,
} from 'typeorm';
import { NotificationSubmission } from '../../../portal/notification-submission/notification-submission.entity';
import { NotificationSubmissionStatusType } from './notification-status-type.entity';

@Entity()
export class NotificationSubmissionToSubmissionStatus extends BaseEntity {
constructor(data?: Partial<NotificationSubmissionToSubmissionStatus>) {
super();
if (data) {
Object.assign(this, data);
}
}

@AutoMap(() => Date)
@Column({ type: 'timestamptz', nullable: true })
effectiveDate: Date | null;

@AutoMap()
@PrimaryColumn({ type: 'uuid' })
submissionUuid: string;

@AutoMap()
@ManyToOne(
() => NotificationSubmission,
(submission) => submission.submissionStatuses,
)
@JoinColumn({ name: 'submission_uuid' })
submission: NotificationSubmission;

@AutoMap()
@PrimaryColumn()
statusTypeCode: string;

@AutoMap()
@ManyToOne(
() => NotificationSubmissionStatusType,
(status) => status.submissionStatuses,
{ eager: true },
)
@JoinColumn({ name: 'status_type_code' })
statusType: NotificationSubmissionStatusType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { classes } from '@automapper/classes';
import { AutomapperModule } from '@automapper/nestjs';
import { createMock, DeepMocked } from '@golevelup/nestjs-testing';
import { Test, TestingModule } from '@nestjs/testing';
import { ClsService } from 'nestjs-cls';
import { mockKeyCloakProviders } from '../../../../test/mocks/mockTypes';
import { NotificationSubmissionProfile } from '../../../common/automapper/notification-submission.automapper.profile';
import { NotificationSubmissionToSubmissionStatus } from './notification-status.entity';
import { NotificationSubmissionStatusController } from './notification-submission-status.controller';
import { NotificationSubmissionStatusService } from './notification-submission-status.service';

describe('NotificationSubmissionStatusController', () => {
let controller: NotificationSubmissionStatusController;
let mockNoticeOfIntentSubmissionStatusService: DeepMocked<NotificationSubmissionStatusService>;

beforeEach(async () => {
mockNoticeOfIntentSubmissionStatusService = createMock();

const module: TestingModule = await Test.createTestingModule({
controllers: [NotificationSubmissionStatusController],
providers: [
NotificationSubmissionProfile,
{
provide: NotificationSubmissionStatusService,
useValue: mockNoticeOfIntentSubmissionStatusService,
},
{
provide: ClsService,
useValue: {},
},
...mockKeyCloakProviders,
],
imports: [
AutomapperModule.forRoot({
strategyInitializer: classes(),
}),
],
}).compile();

controller = module.get<NotificationSubmissionStatusController>(
NotificationSubmissionStatusController,
);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});

it('should call service to get statuses by file number', async () => {
const fakeFileNumber = 'fake';

mockNoticeOfIntentSubmissionStatusService.getCurrentStatusesByFileNumber.mockResolvedValue(
[new NotificationSubmissionToSubmissionStatus()],
);

const result = await controller.getStatusesByFileNumber(fakeFileNumber);

expect(
mockNoticeOfIntentSubmissionStatusService.getCurrentStatusesByFileNumber,
).toBeCalledTimes(1);
expect(
mockNoticeOfIntentSubmissionStatusService.getCurrentStatusesByFileNumber,
).toBeCalledWith(fakeFileNumber);
expect(result.length).toEqual(1);
expect(result).toBeDefined();
});

it('should call service to get current submission status by file number', async () => {
const fakeFileNumber = 'fake';

mockNoticeOfIntentSubmissionStatusService.getCurrentStatusByFileNumber.mockResolvedValue(
new NotificationSubmissionToSubmissionStatus(),
);

const result = await controller.getCurrentStatusByFileNumber(
fakeFileNumber,
);

expect(
mockNoticeOfIntentSubmissionStatusService.getCurrentStatusByFileNumber,
).toBeCalledTimes(1);
expect(
mockNoticeOfIntentSubmissionStatusService.getCurrentStatusByFileNumber,
).toBeCalledWith(fakeFileNumber);
expect(result).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Mapper } from '@automapper/core';
import { InjectMapper } from '@automapper/nestjs';
import { Controller, Get, Param } from '@nestjs/common';
import { ANY_AUTH_ROLE } from '../../../common/authorization/roles';
import { UserRoles } from '../../../common/authorization/roles.decorator';
import { NotificationSubmissionToSubmissionStatusDto } from './notification-status.dto';
import { NotificationSubmissionToSubmissionStatus } from './notification-status.entity';
import { NotificationSubmissionStatusService } from './notification-submission-status.service';

@Controller('notification-submission-status')
@UserRoles(...ANY_AUTH_ROLE)
export class NotificationSubmissionStatusController {
constructor(
private notificationSubmissionStatusService: NotificationSubmissionStatusService,
@InjectMapper() private mapper: Mapper,
) {}

@Get('/:fileNumber')
async getStatusesByFileNumber(@Param('fileNumber') fileNumber) {
const statuses =
await this.notificationSubmissionStatusService.getCurrentStatusesByFileNumber(
fileNumber,
);

return this.mapper.mapArrayAsync(
statuses,
NotificationSubmissionToSubmissionStatus,
NotificationSubmissionToSubmissionStatusDto,
);
}

@Get('/current-status/:fileNumber')
async getCurrentStatusByFileNumber(@Param('fileNumber') fileNumber) {
const status =
await this.notificationSubmissionStatusService.getCurrentStatusByFileNumber(
fileNumber,
);

return this.mapper.mapAsync(
status,
NotificationSubmissionToSubmissionStatus,
NotificationSubmissionToSubmissionStatusDto,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NotificationSubmission } from '../../../portal/notification-submission/notification-submission.entity';
import { NotificationSubmissionStatusType } from './notification-status-type.entity';
import { NotificationSubmissionToSubmissionStatus } from './notification-status.entity';
import { NotificationSubmissionStatusController } from './notification-submission-status.controller';
import { NotificationSubmissionStatusService } from './notification-submission-status.service';

@Module({
imports: [
TypeOrmModule.forFeature([
NotificationSubmissionToSubmissionStatus,
NotificationSubmissionStatusType,
NotificationSubmission,
]),
],
providers: [NotificationSubmissionStatusService],
exports: [NotificationSubmissionStatusService],
controllers: [NotificationSubmissionStatusController],
})
export class NotificationSubmissionStatusModule {}
Loading

0 comments on commit 1276c91

Please sign in to comment.