autoapprove

This commit is contained in:
Evert Prants 2022-12-06 18:29:27 +02:00
parent e28c9228bc
commit f9566af7be
4 changed files with 26 additions and 4 deletions

View File

@ -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();
}

View File

@ -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()

View File

@ -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<Resident> {
return this.residentModel.findOne({ sub });
}
public async save(resident: Partial<Resident>): Promise<Resident> {
return this.residentModel.findOneAndUpdate({ sub: resident.sub }, resident);
}
}

View File

@ -5,7 +5,7 @@
* @param mongoObj Mongo database response
* @returns Plain javascript object
*/
export default function takeMongoObject<T>(mongoObj: T): T {
export default function takeMongoObject<T>(mongoObj: T): T & { id: string } {
const dirty = (mongoObj as Record<string, unknown>)._doc as Record<
string,
unknown
@ -13,5 +13,5 @@ export default function takeMongoObject<T>(mongoObj: T): T {
dirty.id = dirty._id.toString();
delete dirty._id;
delete dirty.__v;
return dirty as T;
return dirty as T & { id: string };
}