diff --git a/services/apps/alcs/src/portal/inbox/application/inbox-application-view.entity.ts b/services/apps/alcs/src/portal/inbox/application/inbox-application-view.entity.ts index 82f059c89..4acad2ba3 100644 --- a/services/apps/alcs/src/portal/inbox/application/inbox-application-view.entity.ts +++ b/services/apps/alcs/src/portal/inbox/application/inbox-application-view.entity.ts @@ -1,11 +1,4 @@ -import { - DataSource, - JoinColumn, - ManyToOne, - PrimaryColumn, - ViewColumn, - ViewEntity, -} from 'typeorm'; +import { DataSource, PrimaryColumn, ViewColumn, ViewEntity } from 'typeorm'; import { ApplicationDecision } from '../../../alcs/application-decision/application-decision.entity'; import { ApplicationSubmissionToSubmissionStatus } from '../../../alcs/application/application-submission-status/submission-status.entity'; import { Application } from '../../../alcs/application/application.entity'; @@ -43,11 +36,6 @@ import { LinkedStatusType } from '../inbox.dto'; 'app.file_number = app_sub.file_number AND app.hide_from_portal = FALSE', ) .leftJoin(User, 'user', 'user.uuid = app_sub.created_by_uuid') - .innerJoinAndSelect( - ApplicationType, - 'applicationType', - 'app_sub.type_code = applicationType.code', - ) .leftJoin( (qb) => qb @@ -105,9 +93,6 @@ export class InboxApplicationSubmissionView { @ViewColumn() status: LinkedStatusType; - @ManyToOne(() => ApplicationType, { - nullable: false, - }) - @JoinColumn({ name: 'application_type_code' }) + //Manually Joined applicationType: ApplicationType; } diff --git a/services/apps/alcs/src/portal/inbox/application/inbox-application.service.ts b/services/apps/alcs/src/portal/inbox/application/inbox-application.service.ts index b3ca94980..5ef6af510 100644 --- a/services/apps/alcs/src/portal/inbox/application/inbox-application.service.ts +++ b/services/apps/alcs/src/portal/inbox/application/inbox-application.service.ts @@ -69,11 +69,6 @@ export class InboxApplicationService { const query = this.applicationInboxRepository .createQueryBuilder('appSearch') - .innerJoinAndMapOne( - 'appSearch.applicationType', - 'appSearch.applicationType', - 'applicationType', - ) .orderBy('appSearch.last_update', 'DESC') .offset((searchDto.page - 1) * searchDto.pageSize) .limit(searchDto.pageSize); diff --git a/services/apps/alcs/src/portal/inbox/inbox.controller.spec.ts b/services/apps/alcs/src/portal/inbox/inbox.controller.spec.ts index f365f3e8f..0033abd26 100644 --- a/services/apps/alcs/src/portal/inbox/inbox.controller.spec.ts +++ b/services/apps/alcs/src/portal/inbox/inbox.controller.spec.ts @@ -1,19 +1,24 @@ -import { classes } from 'automapper-classes'; -import { AutomapperModule } from 'automapper-nestjs'; import { createMock, DeepMocked } from '@golevelup/nestjs-testing'; import { Test, TestingModule } from '@nestjs/testing'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { classes } from 'automapper-classes'; +import { AutomapperModule } from 'automapper-nestjs'; import { ClsService } from 'nestjs-cls'; +import { Repository } from 'typeorm'; import { mockKeyCloakProviders } from '../../../test/mocks/mockTypes'; import { ApplicationSubmissionStatusService } from '../../alcs/application/application-submission-status/application-submission-status.service'; +import { ApplicationType } from '../../alcs/code/application-code/application-type/application-type.entity'; import { NoticeOfIntentSubmissionStatusService } from '../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-submission-status.service'; +import { NoticeOfIntentType } from '../../alcs/notice-of-intent/notice-of-intent-type/notice-of-intent-type.entity'; import { NotificationSubmissionStatusService } from '../../alcs/notification/notification-submission-status/notification-submission-status.service'; +import { NotificationType } from '../../alcs/notification/notification-type/notification-type.entity'; import { User } from '../../user/user.entity'; import { UserService } from '../../user/user.service'; import { InboxApplicationService } from './application/inbox-application.service'; -import { InboxNoticeOfIntentService } from './notice-of-intent/inbox-notice-of-intent.service'; -import { InboxNotificationService } from './notification/inbox-notification.service'; import { InboxController } from './inbox.controller'; import { InboxRequestDto } from './inbox.dto'; +import { InboxNoticeOfIntentService } from './notice-of-intent/inbox-notice-of-intent.service'; +import { InboxNotificationService } from './notification/inbox-notification.service'; describe('InboxController', () => { let controller: InboxController; @@ -24,6 +29,9 @@ describe('InboxController', () => { let mockNoiSubStatusService: DeepMocked; let mockNotiSubStatusService: DeepMocked; let mockUserService: DeepMocked; + let mockAppTypeRepo: DeepMocked>; + let mockNOITypeRepo: DeepMocked>; + let mockNotificationTypeRepo: DeepMocked>; let mockRequest; const mockUserId = 'fake-user-uuid'; @@ -36,6 +44,9 @@ describe('InboxController', () => { mockNoiSubStatusService = createMock(); mockNotiSubStatusService = createMock(); mockUserService = createMock(); + mockAppTypeRepo = createMock(); + mockNOITypeRepo = createMock(); + mockNotificationTypeRepo = createMock(); const module: TestingModule = await Test.createTestingModule({ imports: [ @@ -68,6 +79,18 @@ describe('InboxController', () => { provide: NotificationSubmissionStatusService, useValue: mockNotiSubStatusService, }, + { + provide: getRepositoryToken(ApplicationType), + useValue: mockAppTypeRepo, + }, + { + provide: getRepositoryToken(NoticeOfIntentType), + useValue: mockNOITypeRepo, + }, + { + provide: getRepositoryToken(NotificationType), + useValue: mockNotificationTypeRepo, + }, { provide: ClsService, useValue: {}, diff --git a/services/apps/alcs/src/portal/inbox/inbox.controller.ts b/services/apps/alcs/src/portal/inbox/inbox.controller.ts index 5ef841b31..375013f1f 100644 --- a/services/apps/alcs/src/portal/inbox/inbox.controller.ts +++ b/services/apps/alcs/src/portal/inbox/inbox.controller.ts @@ -1,20 +1,26 @@ +import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; import { Mapper } from 'automapper-core'; import { InjectMapper } from 'automapper-nestjs'; -import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; +import { Repository } from 'typeorm'; import { ApplicationSubmissionStatusService } from '../../alcs/application/application-submission-status/application-submission-status.service'; import { ApplicationSubmissionStatusType } from '../../alcs/application/application-submission-status/submission-status-type.entity'; import { ApplicationStatusDto } from '../../alcs/application/application-submission-status/submission-status.dto'; +import { ApplicationType } from '../../alcs/code/application-code/application-type/application-type.entity'; import { NoticeOfIntentSubmissionStatusType } from '../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-status-type.entity'; import { NoticeOfIntentStatusDto } from '../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-status.dto'; import { NoticeOfIntentSubmissionStatusService } from '../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-submission-status.service'; +import { NoticeOfIntentType } from '../../alcs/notice-of-intent/notice-of-intent-type/notice-of-intent-type.entity'; import { NotificationSubmissionStatusType } from '../../alcs/notification/notification-submission-status/notification-status-type.entity'; import { NotificationStatusDto } from '../../alcs/notification/notification-submission-status/notification-status.dto'; import { NotificationSubmissionStatusService } from '../../alcs/notification/notification-submission-status/notification-submission-status.service'; +import { NotificationType } from '../../alcs/notification/notification-type/notification-type.entity'; import { PortalAuthGuard } from '../../common/authorization/portal-auth-guard.service'; import { User } from '../../user/user.entity'; import { UserService } from '../../user/user.service'; import { isStringSetAndNotEmpty } from '../../utils/string-helper'; import { APPLICATION_SUBMISSION_TYPES } from '../pdf-generation/generate-submission-document.service'; +import { ApplicationSearchResultDto } from '../public/search/public-search.dto'; import { InboxApplicationSubmissionView } from './application/inbox-application-view.entity'; import { InboxApplicationService } from './application/inbox-application.service'; import { @@ -42,6 +48,12 @@ export class InboxController { private noiSubStatusService: NoticeOfIntentSubmissionStatusService, private notiSubStatusService: NotificationSubmissionStatusService, private userService: UserService, + @InjectRepository(ApplicationType) + private appTypeRepo: Repository, + @InjectRepository(NoticeOfIntentType) + private noiTypeRepo: Repository, + @InjectRepository(NotificationType) + private notificationTypeRepo: Repository, ) {} @Get('/') @@ -118,7 +130,7 @@ export class InboxController { ); } - return this.mapSearchResults( + return await this.mapSearchResults( applicationSearchResult, noticeOfIntentResults, notifications, @@ -142,7 +154,11 @@ export class InboxController { government?.uuid ?? null, ); - const mappedSearchResult = this.mapSearchResults(applications, null, null); + const mappedSearchResult = await this.mapSearchResults( + applications, + null, + null, + ); return { total: mappedSearchResult.totalApplications, @@ -168,7 +184,7 @@ export class InboxController { government?.uuid ?? null, ); - const mappedSearchResult = this.mapSearchResults( + const mappedSearchResult = await this.mapSearchResults( null, noticeOfIntents, null, @@ -197,7 +213,11 @@ export class InboxController { government?.uuid ?? null, ); - const mappedSearchResult = this.mapSearchResults(null, null, notifications); + const mappedSearchResult = await this.mapSearchResults( + null, + null, + notifications, + ); return { total: mappedSearchResult.totalNotifications, @@ -239,7 +259,7 @@ export class InboxController { }; } - private mapSearchResults( + private async mapSearchResults( applications: AdvancedSearchResultDto< InboxApplicationSubmissionView[] > | null, @@ -252,29 +272,61 @@ export class InboxController { ) { const response = new InboxResponseDto(); - const mappedApplications: ApplicationInboxResultDto[] = []; + const mappedApplications: ApplicationSearchResultDto[] = []; if (applications && applications.data.length > 0) { + const appTypes = await this.appTypeRepo.find({ + select: { + code: true, + label: true, + }, + }); + const appTypeMap = new Map(); + for (const type of appTypes) { + appTypeMap.set(type.code, type); + } mappedApplications.push( ...applications.data.map((app) => - this.mapApplicationToSearchResult(app), + this.mapApplicationToSearchResult(app, appTypeMap), ), ); } const mappedNoticeOfIntents: NoticeOfIntentInboxResultDto[] = []; if (noticeOfIntents && noticeOfIntents.data.length > 0) { + const noiTypes = await this.noiTypeRepo.find({ + select: { + code: true, + label: true, + }, + }); + const noiTypeMap = new Map(); + for (const type of noiTypes) { + noiTypeMap.set(type.code, type); + } + mappedNoticeOfIntents.push( ...noticeOfIntents.data.map((noi) => - this.mapNoticeOfIntentToSearchResult(noi), + this.mapNoticeOfIntentToSearchResult(noi, noiTypeMap), ), ); } const mappedNotifications: NotificationInboxResultDto[] = []; if (notifications && notifications.data && notifications.data.length > 0) { + const notificationTypes = await this.notificationTypeRepo.find({ + select: { + code: true, + label: true, + }, + }); + const notificationTypeMap = new Map(); + for (const type of notificationTypes) { + notificationTypeMap.set(type.code, type); + } + mappedNotifications.push( ...notifications.data.map((notification) => - this.mapNotificationToSearchResult(notification), + this.mapNotificationToSearchResult(notification, notificationTypeMap), ), ); } @@ -291,11 +343,12 @@ export class InboxController { private mapApplicationToSearchResult( application: InboxApplicationSubmissionView, + appTypeMap: Map, ): ApplicationInboxResultDto { return { referenceId: application.fileNumber, fileNumber: application.fileNumber, - type: application.applicationType.label, + type: appTypeMap.get(application.applicationTypeCode)!.label, createdAt: application.createdAt.getTime(), lastUpdate: application.lastUpdate?.getTime(), ownerName: application.applicant, @@ -306,13 +359,14 @@ export class InboxController { private mapNoticeOfIntentToSearchResult( noi: InboxNoticeOfIntentSubmissionView, + noiTypeMap: Map, ): NoticeOfIntentInboxResultDto { return { referenceId: noi.fileNumber, fileNumber: noi.fileNumber, createdAt: noi.createdAt.getTime(), lastUpdate: noi.lastUpdate?.getTime(), - type: noi.noticeOfIntentType.label, + type: noiTypeMap.get(noi.noticeOfIntentTypeCode)!.label, ownerName: noi.applicant, class: 'NOI', status: noi.status.status_type_code, @@ -321,13 +375,14 @@ export class InboxController { private mapNotificationToSearchResult( notification: InboxNotificationSubmissionView, + notificationTypeMap: Map, ): NotificationInboxResultDto { return { referenceId: notification.fileNumber, fileNumber: notification.fileNumber, createdAt: notification.createdAt.getTime(), lastUpdate: notification.status.effective_date, - type: notification.notificationType.label, + type: notificationTypeMap.get(notification.notificationTypeCode)!.label, ownerName: notification.applicant, class: 'NOTI', status: notification.status.status_type_code, diff --git a/services/apps/alcs/src/portal/inbox/inbox.module.ts b/services/apps/alcs/src/portal/inbox/inbox.module.ts index 27f8ab2f3..9ff9f91c0 100644 --- a/services/apps/alcs/src/portal/inbox/inbox.module.ts +++ b/services/apps/alcs/src/portal/inbox/inbox.module.ts @@ -3,10 +3,13 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ApplicationSubmissionStatusModule } from '../../alcs/application/application-submission-status/application-submission-status.module'; import { Application } from '../../alcs/application/application.entity'; +import { ApplicationType } from '../../alcs/code/application-code/application-type/application-type.entity'; import { LocalGovernment } from '../../alcs/local-government/local-government.entity'; import { NoticeOfIntentSubmissionStatusModule } from '../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-submission-status.module'; +import { NoticeOfIntentType } from '../../alcs/notice-of-intent/notice-of-intent-type/notice-of-intent-type.entity'; import { NoticeOfIntent } from '../../alcs/notice-of-intent/notice-of-intent.entity'; import { NotificationSubmissionStatusModule } from '../../alcs/notification/notification-submission-status/notification-submission-status.module'; +import { NotificationType } from '../../alcs/notification/notification-type/notification-type.entity'; import { Notification } from '../../alcs/notification/notification.entity'; import { ApplicationSubmissionReview } from '../application-submission-review/application-submission-review.entity'; import { ApplicationSubmission } from '../application-submission/application-submission.entity'; @@ -28,11 +31,14 @@ import { InboxNotificationService } from './notification/inbox-notification.serv InboxNotificationSubmissionView, LocalGovernment, Application, + ApplicationType, ApplicationSubmission, ApplicationSubmissionReview, NoticeOfIntent, + NoticeOfIntentType, NoticeOfIntentSubmission, Notification, + NotificationType, NotificationSubmission, ]), RedisModule, diff --git a/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent-view.entity.ts b/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent-view.entity.ts index f00c0edcf..c4357e32b 100644 --- a/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent-view.entity.ts +++ b/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent-view.entity.ts @@ -1,11 +1,4 @@ -import { - DataSource, - JoinColumn, - ManyToOne, - PrimaryColumn, - ViewColumn, - ViewEntity, -} from 'typeorm'; +import { DataSource, PrimaryColumn, ViewColumn, ViewEntity } from 'typeorm'; import { NoticeOfIntentDecision } from '../../../alcs/notice-of-intent-decision/notice-of-intent-decision.entity'; import { NoticeOfIntentSubmissionToSubmissionStatus } from '../../../alcs/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-status.entity'; import { NoticeOfIntentType } from '../../../alcs/notice-of-intent/notice-of-intent-type/notice-of-intent-type.entity'; @@ -43,11 +36,6 @@ import { LinkedStatusType } from '../inbox.dto'; 'noi.file_number = noi_sub.file_number AND noi.hide_from_portal = false', ) .leftJoin(User, 'user', 'user.uuid = noi_sub.created_by_uuid') - .innerJoinAndSelect( - NoticeOfIntentType, - 'noticeOfIntentType', - 'noi_sub.type_code = noticeOfIntentType.code', - ) .leftJoin( (qb) => qb @@ -108,9 +96,6 @@ export class InboxNoticeOfIntentSubmissionView { @ViewColumn() status: LinkedStatusType; - @ManyToOne(() => NoticeOfIntentType, { - nullable: false, - }) - @JoinColumn({ name: 'notice_of_intent_type_code' }) + //Manually Joined noticeOfIntentType: NoticeOfIntentType; } diff --git a/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent.service.ts b/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent.service.ts index fe71ab3fc..564822800 100644 --- a/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent.service.ts +++ b/services/apps/alcs/src/portal/inbox/notice-of-intent/inbox-notice-of-intent.service.ts @@ -64,11 +64,6 @@ export class InboxNoticeOfIntentService { const query = this.noiSearchRepository .createQueryBuilder('noiSearch') - .innerJoinAndMapOne( - 'noiSearch.noticeOfIntentType', - 'noiSearch.noticeOfIntentType', - 'noticeOfIntentType', - ) .orderBy('"noiSearch"."last_update"', 'DESC') .offset((searchDto.page - 1) * searchDto.pageSize) .limit(searchDto.pageSize); diff --git a/services/apps/alcs/src/portal/inbox/notification/inbox-notification-view.entity.ts b/services/apps/alcs/src/portal/inbox/notification/inbox-notification-view.entity.ts index 63f365170..d23f09ded 100644 --- a/services/apps/alcs/src/portal/inbox/notification/inbox-notification-view.entity.ts +++ b/services/apps/alcs/src/portal/inbox/notification/inbox-notification-view.entity.ts @@ -1,11 +1,4 @@ -import { - DataSource, - JoinColumn, - ManyToOne, - PrimaryColumn, - ViewColumn, - ViewEntity, -} from 'typeorm'; +import { DataSource, PrimaryColumn, ViewColumn, ViewEntity } from 'typeorm'; import { NotificationType } from '../../../alcs/notification/notification-type/notification-type.entity'; import { Notification } from '../../../alcs/notification/notification.entity'; import { User } from '../../../user/user.entity'; @@ -36,11 +29,6 @@ import { LinkedStatusType } from '../inbox.dto'; Notification, 'noti', 'noti.file_number = noti_sub.file_number', - ) - .innerJoinAndSelect( - NotificationType, - 'notificationType', - 'noti_sub.type_code = notificationType.code', ), }) export class InboxNotificationSubmissionView { @@ -78,9 +66,6 @@ export class InboxNotificationSubmissionView { @ViewColumn() status: LinkedStatusType; - @ManyToOne(() => NotificationType, { - nullable: false, - }) - @JoinColumn({ name: 'notification_type_code' }) + //Manually Joined notificationType: NotificationType; } diff --git a/services/apps/alcs/src/portal/inbox/notification/inbox-notification.service.ts b/services/apps/alcs/src/portal/inbox/notification/inbox-notification.service.ts index 11d6e9498..034a15b64 100644 --- a/services/apps/alcs/src/portal/inbox/notification/inbox-notification.service.ts +++ b/services/apps/alcs/src/portal/inbox/notification/inbox-notification.service.ts @@ -64,11 +64,6 @@ export class InboxNotificationService { const query = this.notificationSearchViewRepo .createQueryBuilder('notificationSearch') - .innerJoinAndMapOne( - 'notificationSearch.notificationType', - 'notificationSearch.notificationType', - 'notificationType', - ) .orderBy(`("notificationSearch"."status" ->> 'effective_date')`, 'DESC') .offset((searchDto.page - 1) * searchDto.pageSize) .limit(searchDto.pageSize); diff --git a/services/apps/alcs/src/providers/typeorm/migrations/1717017176544-move_type_out_of_view.ts b/services/apps/alcs/src/providers/typeorm/migrations/1717017176544-move_type_out_of_view.ts new file mode 100644 index 000000000..a2ddc409c --- /dev/null +++ b/services/apps/alcs/src/providers/typeorm/migrations/1717017176544-move_type_out_of_view.ts @@ -0,0 +1,125 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class MoveTypeOutOfView1717017176544 implements MigrationInterface { + name = 'MoveTypeOutOfView1717017176544'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_notice_of_intent_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_notice_of_intent_submission_view"`, + ); + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_application_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_application_submission_view"`, + ); + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_notification_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_notification_submission_view"`, + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_notification_submission_view" AS SELECT "noti_sub"."uuid" AS "uuid", "noti_sub"."applicant" AS "applicant", "noti"."uuid" AS "notification_uuid", "noti_sub"."file_number" AS "file_number", "noti_sub"."audit_created_at" AS "created_at", "noti_sub"."created_by_uuid" AS "created_by_uuid", "noti_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noti"."type_code" AS "notification_type_code", "noti"."date_submitted_to_alc" AS "date_submitted_to_alc", alcs.get_current_status_for_notification_submission_by_uuid("noti_sub"."uuid") AS "status" FROM "alcs"."notification_submission" "noti_sub" LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noti_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification" "noti" ON "noti"."file_number" = "noti_sub"."file_number" AND "noti"."audit_deleted_date_at" IS NULL WHERE "noti_sub"."audit_deleted_date_at" IS NULL`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_notification_submission_view', + 'SELECT "noti_sub"."uuid" AS "uuid", "noti_sub"."applicant" AS "applicant", "noti"."uuid" AS "notification_uuid", "noti_sub"."file_number" AS "file_number", "noti_sub"."audit_created_at" AS "created_at", "noti_sub"."created_by_uuid" AS "created_by_uuid", "noti_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noti"."type_code" AS "notification_type_code", "noti"."date_submitted_to_alc" AS "date_submitted_to_alc", alcs.get_current_status_for_notification_submission_by_uuid("noti_sub"."uuid") AS "status" FROM "alcs"."notification_submission" "noti_sub" LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noti_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification" "noti" ON "noti"."file_number" = "noti_sub"."file_number" AND "noti"."audit_deleted_date_at" IS NULL WHERE "noti_sub"."audit_deleted_date_at" IS NULL', + ], + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_notice_of_intent_submission_view" AS SELECT "noi_sub"."uuid" AS "uuid", "noi_sub"."applicant" AS "applicant", "noi"."uuid" AS "notice_of_intent_uuid", "noi_sub"."file_number" AS "file_number", "noi_sub"."audit_created_at" AS "created_at", "noi_sub"."created_by_uuid" AS "created_by_uuid", "noi_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noi_sub"."type_code" AS "notice_of_intent_type_code", "noi"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_notice_of_intent_submission_by_uuid("noi_sub"."uuid") AS "status" FROM "alcs"."notice_of_intent_submission" "noi_sub" INNER JOIN "alcs"."notice_of_intent" "noi" ON "noi"."file_number" = "noi_sub"."file_number" AND "noi"."hide_from_portal" = false AND "noi"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noi_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."notice_of_intent_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "noi_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", notice_of_intent_uuid AS "notice_of_intent_uuid" FROM "alcs"."notice_of_intent_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY notice_of_intent_uuid) "decision_date" ON decision_date."notice_of_intent_uuid" = "noi"."uuid" WHERE ( "noi_sub"."is_draft" = FALSE ) AND ( "noi_sub"."audit_deleted_date_at" IS NULL )`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_notice_of_intent_submission_view', + 'SELECT "noi_sub"."uuid" AS "uuid", "noi_sub"."applicant" AS "applicant", "noi"."uuid" AS "notice_of_intent_uuid", "noi_sub"."file_number" AS "file_number", "noi_sub"."audit_created_at" AS "created_at", "noi_sub"."created_by_uuid" AS "created_by_uuid", "noi_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noi_sub"."type_code" AS "notice_of_intent_type_code", "noi"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_notice_of_intent_submission_by_uuid("noi_sub"."uuid") AS "status" FROM "alcs"."notice_of_intent_submission" "noi_sub" INNER JOIN "alcs"."notice_of_intent" "noi" ON "noi"."file_number" = "noi_sub"."file_number" AND "noi"."hide_from_portal" = false AND "noi"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noi_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."notice_of_intent_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "noi_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", notice_of_intent_uuid AS "notice_of_intent_uuid" FROM "alcs"."notice_of_intent_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY notice_of_intent_uuid) "decision_date" ON decision_date."notice_of_intent_uuid" = "noi"."uuid" WHERE ( "noi_sub"."is_draft" = FALSE ) AND ( "noi_sub"."audit_deleted_date_at" IS NULL )', + ], + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_application_submission_view" AS SELECT "app_sub"."uuid" AS "uuid", "app_sub"."applicant" AS "applicant", "app"."uuid" AS "application_uuid", "app_sub"."file_number" AS "file_number", "app_sub"."created_by_uuid" AS "created_by_uuid", "app_sub"."local_government_uuid" AS "local_government_uuid", "app_sub"."audit_created_at" AS "created_at", "user"."bceid_business_guid" AS "bceid_business_guid", "app_sub"."type_code" AS "application_type_code", "app"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_application_submission_by_uuid("app_sub"."uuid") AS "status" FROM "alcs"."application_submission" "app_sub" INNER JOIN "alcs"."application" "app" ON "app"."file_number" = "app_sub"."file_number" AND "app"."hide_from_portal" = FALSE AND "app"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "app_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."application_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "app_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", application_uuid AS "application_uuid" FROM "alcs"."application_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY application_uuid) "decision_date" ON decision_date."application_uuid" = "app"."uuid" WHERE ( "app_sub"."is_draft" = FALSE ) AND ( "app_sub"."audit_deleted_date_at" IS NULL )`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_application_submission_view', + 'SELECT "app_sub"."uuid" AS "uuid", "app_sub"."applicant" AS "applicant", "app"."uuid" AS "application_uuid", "app_sub"."file_number" AS "file_number", "app_sub"."created_by_uuid" AS "created_by_uuid", "app_sub"."local_government_uuid" AS "local_government_uuid", "app_sub"."audit_created_at" AS "created_at", "user"."bceid_business_guid" AS "bceid_business_guid", "app_sub"."type_code" AS "application_type_code", "app"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_application_submission_by_uuid("app_sub"."uuid") AS "status" FROM "alcs"."application_submission" "app_sub" INNER JOIN "alcs"."application" "app" ON "app"."file_number" = "app_sub"."file_number" AND "app"."hide_from_portal" = FALSE AND "app"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "app_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."application_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "app_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", application_uuid AS "application_uuid" FROM "alcs"."application_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY application_uuid) "decision_date" ON decision_date."application_uuid" = "app"."uuid" WHERE ( "app_sub"."is_draft" = FALSE ) AND ( "app_sub"."audit_deleted_date_at" IS NULL )', + ], + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_application_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_application_submission_view"`, + ); + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_notice_of_intent_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_notice_of_intent_submission_view"`, + ); + await queryRunner.query( + `DELETE FROM "alcs"."typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, + ['VIEW', 'inbox_notification_submission_view', 'alcs'], + ); + await queryRunner.query( + `DROP VIEW "alcs"."inbox_notification_submission_view"`, + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_notification_submission_view" AS SELECT "noti_sub"."uuid" AS "uuid", "noti_sub"."applicant" AS "applicant", "noti"."uuid" AS "notification_uuid", "notificationType"."audit_deleted_date_at" AS "notificationType_audit_deleted_date_at", "notificationType"."audit_created_at" AS "notificationType_audit_created_at", "notificationType"."audit_updated_at" AS "notificationType_audit_updated_at", "notificationType"."audit_created_by" AS "notificationType_audit_created_by", "notificationType"."audit_updated_by" AS "notificationType_audit_updated_by", "notificationType"."label" AS "notificationType_label", "notificationType"."code" AS "notificationType_code", "notificationType"."description" AS "notificationType_description", "notificationType"."short_label" AS "notificationType_short_label", "notificationType"."background_color" AS "notificationType_background_color", "notificationType"."text_color" AS "notificationType_text_color", "notificationType"."html_description" AS "notificationType_html_description", "notificationType"."portal_label" AS "notificationType_portal_label", "noti_sub"."file_number" AS "file_number", "noti_sub"."audit_created_at" AS "created_at", "noti_sub"."created_by_uuid" AS "created_by_uuid", "noti_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noti"."type_code" AS "notification_type_code", "noti"."date_submitted_to_alc" AS "date_submitted_to_alc", alcs.get_current_status_for_notification_submission_by_uuid("noti_sub"."uuid") AS "status" FROM "alcs"."notification_submission" "noti_sub" LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noti_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification" "noti" ON "noti"."file_number" = "noti_sub"."file_number" AND "noti"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification_type" "notificationType" ON "noti_sub"."type_code" = "notificationType"."code" AND "notificationType"."audit_deleted_date_at" IS NULL WHERE "noti_sub"."audit_deleted_date_at" IS NULL`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_notification_submission_view', + 'SELECT "noti_sub"."uuid" AS "uuid", "noti_sub"."applicant" AS "applicant", "noti"."uuid" AS "notification_uuid", "notificationType"."audit_deleted_date_at" AS "notificationType_audit_deleted_date_at", "notificationType"."audit_created_at" AS "notificationType_audit_created_at", "notificationType"."audit_updated_at" AS "notificationType_audit_updated_at", "notificationType"."audit_created_by" AS "notificationType_audit_created_by", "notificationType"."audit_updated_by" AS "notificationType_audit_updated_by", "notificationType"."label" AS "notificationType_label", "notificationType"."code" AS "notificationType_code", "notificationType"."description" AS "notificationType_description", "notificationType"."short_label" AS "notificationType_short_label", "notificationType"."background_color" AS "notificationType_background_color", "notificationType"."text_color" AS "notificationType_text_color", "notificationType"."html_description" AS "notificationType_html_description", "notificationType"."portal_label" AS "notificationType_portal_label", "noti_sub"."file_number" AS "file_number", "noti_sub"."audit_created_at" AS "created_at", "noti_sub"."created_by_uuid" AS "created_by_uuid", "noti_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noti"."type_code" AS "notification_type_code", "noti"."date_submitted_to_alc" AS "date_submitted_to_alc", alcs.get_current_status_for_notification_submission_by_uuid("noti_sub"."uuid") AS "status" FROM "alcs"."notification_submission" "noti_sub" LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noti_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification" "noti" ON "noti"."file_number" = "noti_sub"."file_number" AND "noti"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notification_type" "notificationType" ON "noti_sub"."type_code" = "notificationType"."code" AND "notificationType"."audit_deleted_date_at" IS NULL WHERE "noti_sub"."audit_deleted_date_at" IS NULL', + ], + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_application_submission_view" AS SELECT "app_sub"."uuid" AS "uuid", "app_sub"."applicant" AS "applicant", "app"."uuid" AS "application_uuid", "applicationType"."audit_deleted_date_at" AS "applicationType_audit_deleted_date_at", "applicationType"."audit_created_at" AS "applicationType_audit_created_at", "applicationType"."audit_updated_at" AS "applicationType_audit_updated_at", "applicationType"."audit_created_by" AS "applicationType_audit_created_by", "applicationType"."audit_updated_by" AS "applicationType_audit_updated_by", "applicationType"."label" AS "applicationType_label", "applicationType"."code" AS "applicationType_code", "applicationType"."description" AS "applicationType_description", "applicationType"."short_label" AS "applicationType_short_label", "applicationType"."background_color" AS "applicationType_background_color", "applicationType"."text_color" AS "applicationType_text_color", "applicationType"."html_description" AS "applicationType_html_description", "applicationType"."portal_label" AS "applicationType_portal_label", "applicationType"."portal_order" AS "applicationType_portal_order", "applicationType"."requires_government_review" AS "applicationType_requires_government_review", "applicationType"."alc_fee_amount" AS "applicationType_alc_fee_amount", "applicationType"."government_fee_amount" AS "applicationType_government_fee_amount", "app_sub"."file_number" AS "file_number", "app_sub"."created_by_uuid" AS "created_by_uuid", "app_sub"."local_government_uuid" AS "local_government_uuid", "app_sub"."audit_created_at" AS "created_at", "user"."bceid_business_guid" AS "bceid_business_guid", "app_sub"."type_code" AS "application_type_code", "app"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_application_submission_by_uuid("app_sub"."uuid") AS "status" FROM "alcs"."application_submission" "app_sub" INNER JOIN "alcs"."application" "app" ON "app"."file_number" = "app_sub"."file_number" AND "app"."hide_from_portal" = FALSE AND "app"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "app_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."application_type" "applicationType" ON "app_sub"."type_code" = "applicationType"."code" AND "applicationType"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."application_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "app_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", application_uuid AS "application_uuid" FROM "alcs"."application_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY application_uuid) "decision_date" ON decision_date."application_uuid" = "app"."uuid" WHERE ( "app_sub"."is_draft" = FALSE ) AND ( "app_sub"."audit_deleted_date_at" IS NULL )`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_application_submission_view', + 'SELECT "app_sub"."uuid" AS "uuid", "app_sub"."applicant" AS "applicant", "app"."uuid" AS "application_uuid", "applicationType"."audit_deleted_date_at" AS "applicationType_audit_deleted_date_at", "applicationType"."audit_created_at" AS "applicationType_audit_created_at", "applicationType"."audit_updated_at" AS "applicationType_audit_updated_at", "applicationType"."audit_created_by" AS "applicationType_audit_created_by", "applicationType"."audit_updated_by" AS "applicationType_audit_updated_by", "applicationType"."label" AS "applicationType_label", "applicationType"."code" AS "applicationType_code", "applicationType"."description" AS "applicationType_description", "applicationType"."short_label" AS "applicationType_short_label", "applicationType"."background_color" AS "applicationType_background_color", "applicationType"."text_color" AS "applicationType_text_color", "applicationType"."html_description" AS "applicationType_html_description", "applicationType"."portal_label" AS "applicationType_portal_label", "applicationType"."portal_order" AS "applicationType_portal_order", "applicationType"."requires_government_review" AS "applicationType_requires_government_review", "applicationType"."alc_fee_amount" AS "applicationType_alc_fee_amount", "applicationType"."government_fee_amount" AS "applicationType_government_fee_amount", "app_sub"."file_number" AS "file_number", "app_sub"."created_by_uuid" AS "created_by_uuid", "app_sub"."local_government_uuid" AS "local_government_uuid", "app_sub"."audit_created_at" AS "created_at", "user"."bceid_business_guid" AS "bceid_business_guid", "app_sub"."type_code" AS "application_type_code", "app"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_application_submission_by_uuid("app_sub"."uuid") AS "status" FROM "alcs"."application_submission" "app_sub" INNER JOIN "alcs"."application" "app" ON "app"."file_number" = "app_sub"."file_number" AND "app"."hide_from_portal" = FALSE AND "app"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "app_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."application_type" "applicationType" ON "app_sub"."type_code" = "applicationType"."code" AND "applicationType"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."application_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "app_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", application_uuid AS "application_uuid" FROM "alcs"."application_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY application_uuid) "decision_date" ON decision_date."application_uuid" = "app"."uuid" WHERE ( "app_sub"."is_draft" = FALSE ) AND ( "app_sub"."audit_deleted_date_at" IS NULL )', + ], + ); + await queryRunner.query( + `CREATE VIEW "alcs"."inbox_notice_of_intent_submission_view" AS SELECT "noi_sub"."uuid" AS "uuid", "noi_sub"."applicant" AS "applicant", "noi"."uuid" AS "notice_of_intent_uuid", "noticeOfIntentType"."audit_deleted_date_at" AS "noticeOfIntentType_audit_deleted_date_at", "noticeOfIntentType"."audit_created_at" AS "noticeOfIntentType_audit_created_at", "noticeOfIntentType"."audit_updated_at" AS "noticeOfIntentType_audit_updated_at", "noticeOfIntentType"."audit_created_by" AS "noticeOfIntentType_audit_created_by", "noticeOfIntentType"."audit_updated_by" AS "noticeOfIntentType_audit_updated_by", "noticeOfIntentType"."label" AS "noticeOfIntentType_label", "noticeOfIntentType"."code" AS "noticeOfIntentType_code", "noticeOfIntentType"."description" AS "noticeOfIntentType_description", "noticeOfIntentType"."short_label" AS "noticeOfIntentType_short_label", "noticeOfIntentType"."background_color" AS "noticeOfIntentType_background_color", "noticeOfIntentType"."text_color" AS "noticeOfIntentType_text_color", "noticeOfIntentType"."html_description" AS "noticeOfIntentType_html_description", "noticeOfIntentType"."portal_label" AS "noticeOfIntentType_portal_label", "noticeOfIntentType"."alc_fee_amount" AS "noticeOfIntentType_alc_fee_amount", "noticeOfIntentType"."government_fee_amount" AS "noticeOfIntentType_government_fee_amount", "noi_sub"."file_number" AS "file_number", "noi_sub"."audit_created_at" AS "created_at", "noi_sub"."created_by_uuid" AS "created_by_uuid", "noi_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noi_sub"."type_code" AS "notice_of_intent_type_code", "noi"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_notice_of_intent_submission_by_uuid("noi_sub"."uuid") AS "status" FROM "alcs"."notice_of_intent_submission" "noi_sub" INNER JOIN "alcs"."notice_of_intent" "noi" ON "noi"."file_number" = "noi_sub"."file_number" AND "noi"."hide_from_portal" = false AND "noi"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noi_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notice_of_intent_type" "noticeOfIntentType" ON "noi_sub"."type_code" = "noticeOfIntentType"."code" AND "noticeOfIntentType"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."notice_of_intent_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "noi_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", notice_of_intent_uuid AS "notice_of_intent_uuid" FROM "alcs"."notice_of_intent_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY notice_of_intent_uuid) "decision_date" ON decision_date."notice_of_intent_uuid" = "noi"."uuid" WHERE ( "noi_sub"."is_draft" = FALSE ) AND ( "noi_sub"."audit_deleted_date_at" IS NULL )`, + ); + await queryRunner.query( + `INSERT INTO "alcs"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, + [ + 'alcs', + 'VIEW', + 'inbox_notice_of_intent_submission_view', + 'SELECT "noi_sub"."uuid" AS "uuid", "noi_sub"."applicant" AS "applicant", "noi"."uuid" AS "notice_of_intent_uuid", "noticeOfIntentType"."audit_deleted_date_at" AS "noticeOfIntentType_audit_deleted_date_at", "noticeOfIntentType"."audit_created_at" AS "noticeOfIntentType_audit_created_at", "noticeOfIntentType"."audit_updated_at" AS "noticeOfIntentType_audit_updated_at", "noticeOfIntentType"."audit_created_by" AS "noticeOfIntentType_audit_created_by", "noticeOfIntentType"."audit_updated_by" AS "noticeOfIntentType_audit_updated_by", "noticeOfIntentType"."label" AS "noticeOfIntentType_label", "noticeOfIntentType"."code" AS "noticeOfIntentType_code", "noticeOfIntentType"."description" AS "noticeOfIntentType_description", "noticeOfIntentType"."short_label" AS "noticeOfIntentType_short_label", "noticeOfIntentType"."background_color" AS "noticeOfIntentType_background_color", "noticeOfIntentType"."text_color" AS "noticeOfIntentType_text_color", "noticeOfIntentType"."html_description" AS "noticeOfIntentType_html_description", "noticeOfIntentType"."portal_label" AS "noticeOfIntentType_portal_label", "noticeOfIntentType"."alc_fee_amount" AS "noticeOfIntentType_alc_fee_amount", "noticeOfIntentType"."government_fee_amount" AS "noticeOfIntentType_government_fee_amount", "noi_sub"."file_number" AS "file_number", "noi_sub"."audit_created_at" AS "created_at", "noi_sub"."created_by_uuid" AS "created_by_uuid", "noi_sub"."local_government_uuid" AS "local_government_uuid", "user"."bceid_business_guid" AS "bceid_business_guid", "noi_sub"."type_code" AS "notice_of_intent_type_code", "noi"."date_submitted_to_alc" AS "date_submitted_to_alc", GREATEST(status_link.effective_date, decision_date.date) AS "last_update", alcs.get_current_status_for_notice_of_intent_submission_by_uuid("noi_sub"."uuid") AS "status" FROM "alcs"."notice_of_intent_submission" "noi_sub" INNER JOIN "alcs"."notice_of_intent" "noi" ON "noi"."file_number" = "noi_sub"."file_number" AND "noi"."hide_from_portal" = false AND "noi"."audit_deleted_date_at" IS NULL LEFT JOIN "alcs"."user" "user" ON "user"."uuid" = "noi_sub"."created_by_uuid" AND "user"."audit_deleted_date_at" IS NULL INNER JOIN "alcs"."notice_of_intent_type" "noticeOfIntentType" ON "noi_sub"."type_code" = "noticeOfIntentType"."code" AND "noticeOfIntentType"."audit_deleted_date_at" IS NULL LEFT JOIN (SELECT MAX("effective_date") AS "effective_date", submission_uuid AS "submission_uuid" FROM "alcs"."notice_of_intent_submission_to_submission_status" "status_link" GROUP BY submission_uuid) "status_link" ON status_link."submission_uuid" = "noi_sub"."uuid" LEFT JOIN (SELECT MAX("date") AS "date", notice_of_intent_uuid AS "notice_of_intent_uuid" FROM "alcs"."notice_of_intent_decision" "decision_date" WHERE "decision_date"."audit_deleted_date_at" IS NULL GROUP BY notice_of_intent_uuid) "decision_date" ON decision_date."notice_of_intent_uuid" = "noi"."uuid" WHERE ( "noi_sub"."is_draft" = FALSE ) AND ( "noi_sub"."audit_deleted_date_at" IS NULL )', + ], + ); + } +}