diff --git a/src/industry-change-application/industry-change-application.service.ts b/src/industry-change-application/industry-change-application.service.ts index 15c8a5b..5a766b7 100644 --- a/src/industry-change-application/industry-change-application.service.ts +++ b/src/industry-change-application/industry-change-application.service.ts @@ -120,6 +120,15 @@ export class IndustryChangeApplicationService { createdBy: token ?? 'no token provided for testing', }); + if (status === ApplicationStatus.APPROVED) { + getResident.willWorkInPhysicalJurisdiction = + data.willWorkInPhysicalJurisdiction; + getResident.industry = data.industry ?? null; + getResident.regulatoryElection = data.regulatoryElection ?? null; + getResident.regulatoryElectionSub = data.regulatoryElectionSub ?? null; + await this.resident.save(getResident); + } + return newApplication.save(); } diff --git a/src/industry-change-application/schemas/ICAInformation.schema.ts b/src/industry-change-application/schemas/ICAInformation.schema.ts index 9994a30..4bd8fcb 100644 --- a/src/industry-change-application/schemas/ICAInformation.schema.ts +++ b/src/industry-change-application/schemas/ICAInformation.schema.ts @@ -4,13 +4,21 @@ import { RegulatoryElection } from 'src/enums/regulatory-election.enums'; @Schema({ _id: false }) export class ICAInformation { - @Prop({ type: String, enum: Industry }) + @Prop({ + type: String, + enum: Object.values(Industry).concat([null]), + required: false, + }) industry: Industry; @Prop({ required: true }) willWorkInPhysicalJurisdiction: boolean; - @Prop({ type: String, enum: RegulatoryElection }) + @Prop({ + type: String, + enum: Object.values(RegulatoryElection).concat([null]), + required: false, + }) regulatoryElection: RegulatoryElection; @Prop() diff --git a/src/resident/resident.service.ts b/src/resident/resident.service.ts index 4e46677..96f94bb 100644 --- a/src/resident/resident.service.ts +++ b/src/resident/resident.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; +import { takeMongoObject } from 'src/utility'; import { Resident, ResidentDocument } from './schemas/Resident.schema'; @Injectable() @@ -17,4 +18,8 @@ export class ResidentService { public async getResidentBySub(sub: string): Promise { return this.residentModel.findOne({ sub }); } + + public async save(resident: Partial): Promise { + return this.residentModel.findOneAndUpdate({ sub: resident.sub }, resident); + } } diff --git a/src/utility/take-mongo-object.ts b/src/utility/take-mongo-object.ts index 463e62c..71ece58 100644 --- a/src/utility/take-mongo-object.ts +++ b/src/utility/take-mongo-object.ts @@ -5,7 +5,7 @@ * @param mongoObj Mongo database response * @returns Plain javascript object */ -export default function takeMongoObject(mongoObj: T): T { +export default function takeMongoObject(mongoObj: T): T & { id: string } { const dirty = (mongoObj as Record)._doc as Record< string, unknown @@ -13,5 +13,5 @@ export default function takeMongoObject(mongoObj: T): T { dirty.id = dirty._id.toString(); delete dirty._id; delete dirty.__v; - return dirty as T; + return dirty as T & { id: string }; }