Skip to content

Commit

Permalink
Merge pull request #1952 from bcgov/feature/ALCS-2146
Browse files Browse the repository at this point in the history
Conditionally apply tags based on NARU answers
  • Loading branch information
trslater authored Nov 5, 2024
2 parents 4c8803e + f51b01a commit c6fa3fd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ export class ApplicationTagService {

return application.tags && application.tags.length > 0 ? application.tags : [];
}

async applicationHasTag(fileNumber: string, tagName: string): Promise<boolean> {
const application = await this.applicationRepository.findOne({
where: { fileNumber: fileNumber },
relations: ['tags'],
});

return application?.tags.some((tag) => tag.name === tagName) ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ValidatedApplicationSubmission } from './application-submission-validat
import { ApplicationSubmission } from './application-submission.entity';
import { ApplicationSubmissionService } from './application-submission.service';
import { NaruSubtype } from './naru-subtype/naru-subtype.entity';
import { ApplicationTagService } from '../../alcs/application/application-tag/application-tag.service';

describe('ApplicationSubmissionService', () => {
let service: ApplicationSubmissionService;
Expand All @@ -41,6 +42,7 @@ describe('ApplicationSubmissionService', () => {
>;
let mockNaruSubtypeRepository: DeepMocked<Repository<NaruSubtype>>;
let mockApplicationService: DeepMocked<ApplicationService>;
let mockApplicationTagService: DeepMocked<ApplicationTagService>;
let mockLGService: DeepMocked<LocalGovernmentService>;
let mockAppDocService: DeepMocked<ApplicationDocumentService>;
let mockGenerateSubmissionDocumentService: DeepMocked<GenerateSubmissionDocumentService>;
Expand All @@ -54,6 +56,7 @@ describe('ApplicationSubmissionService', () => {
mockRepository = createMock();
mockStatusRepository = createMock();
mockApplicationService = createMock();
mockApplicationTagService = createMock();
mockLGService = createMock();
mockAppDocService = createMock();
mockGenerateSubmissionDocumentService = createMock();
Expand All @@ -75,6 +78,10 @@ describe('ApplicationSubmissionService', () => {
providers: [
ApplicationSubmissionService,
ApplicationSubmissionProfile,
{
provide: ApplicationTagService,
useValue: mockApplicationTagService,
},
{
provide: getRepositoryToken(ApplicationSubmission),
useValue: mockRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from './application-submission.dto';
import { ApplicationSubmission } from './application-submission.entity';
import { NaruSubtype } from './naru-subtype/naru-subtype.entity';
import { ApplicationTagService } from '../../alcs/application/application-tag/application-tag.service';

const LG_VISIBLE_STATUSES = [
SUBMISSION_STATUS.INCOMPLETE,
Expand Down Expand Up @@ -82,6 +83,7 @@ export class ApplicationSubmissionService {
private generateReviewDocumentService: GenerateReviewDocumentService,
private applicationSubmissionStatusService: ApplicationSubmissionStatusService,
@InjectMapper() private mapper: Mapper,
private applicationTagService: ApplicationTagService,
) {}

async getOrFailByFileNumber(fileNumber: string) {
Expand Down Expand Up @@ -197,6 +199,8 @@ export class ApplicationSubmissionService {
this.setInclusionExclusionFields(applicationSubmission, updateDto);
this.setCovenantFields(applicationSubmission, updateDto);

await this.applyTags(applicationSubmission);

await this.applicationSubmissionRepository.save(applicationSubmission);

if (!applicationSubmission.isDraft && updateDto.localGovernmentUuid) {
Expand Down Expand Up @@ -1225,4 +1229,52 @@ export class ApplicationSubmissionService {
localGovernmentGuid: result[0]?.localGovernment_bceid_business_guid,
};
}

private async applyTags(applicationSubmission: ApplicationSubmission) {
switch (applicationSubmission.typeCode) {
case 'NARU':
await this.applyNaruTags(applicationSubmission);
break;
}
}

private async applyNaruTags(applicationSubmission: ApplicationSubmission) {
await this.conditionallyApplyTag(
applicationSubmission.fileNumber,
applicationSubmission.naruWillBeOverFiveHundredM2 ?? false,
'Principal Residence > 500m2',
);
await this.conditionallyApplyTag(
applicationSubmission.fileNumber,
applicationSubmission.naruWillHaveTemporaryForeignWorkerHousing ?? false,
'Temporary Foreign Worker Housing',
);
await this.conditionallyApplyTag(
applicationSubmission.fileNumber,
applicationSubmission.naruWillRetainResidence ?? false,
'Reside & Replace',
);
await this.conditionallyApplyTag(
applicationSubmission.fileNumber,
applicationSubmission.naruWillHaveAdditionalResidence ?? false,
'Additional Residence',
);
await this.conditionallyApplyTag(
applicationSubmission.fileNumber,
applicationSubmission.naruWillImportFill ?? false,
'Fill Placement',
);
}

private async conditionallyApplyTag(fileNumber: string, condition: boolean, tagName: string) {
const tagExists = await this.applicationTagService.applicationHasTag(fileNumber, tagName);

if (condition && !tagExists) {
await this.applicationTagService.addTagToApplication(fileNumber, tagName);
}

if (!condition && tagExists) {
await this.applicationTagService.removeTagFromApplication(fileNumber, tagName);
}
}
}

0 comments on commit c6fa3fd

Please sign in to comment.