Compare commits

..

No commits in common. "experiments" and "master" have entirely different histories.

2 changed files with 17 additions and 22 deletions

View File

@ -4,7 +4,6 @@ import {
NotFoundException, NotFoundException,
} from '@nestjs/common'; } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose'; import { InjectModel } from '@nestjs/mongoose';
import { instanceToPlain, plainToInstance } from 'class-transformer';
import { Model } from 'mongoose'; import { Model } from 'mongoose';
import { import {
ApplicationStatus, ApplicationStatus,
@ -28,6 +27,17 @@ const requestedFields = [
'regulatoryElectionSub', 'regulatoryElectionSub',
]; ];
const fieldsToExpose = [
'id',
'residentSub',
'current',
'requested',
'status',
'submittedAt',
'decision',
'objectStatus',
];
@Injectable() @Injectable()
export class IndustryChangeApplicationService { export class IndustryChangeApplicationService {
constructor( constructor(
@ -164,15 +174,12 @@ export class IndustryChangeApplicationService {
return findApplication.save(); return findApplication.save();
} }
// I wrote this because I could not for the life of me get class-transformer to
// play along with mongo documents. I do not have experience with either, so this
// was a last ditch effort.
makeReadable(input: IndustryChangeApplication | IndustryChangeApplication[]) { makeReadable(input: IndustryChangeApplication | IndustryChangeApplication[]) {
if (Array.isArray(input)) { return Array.isArray(input)
return input.map((item) => this.makeReadable(item)); ? input.map((object) => take(takeMongoObject(object), fieldsToExpose))
} : take(takeMongoObject(input), fieldsToExpose);
const response = plainToInstance(
IndustryChangeApplication,
(input as IndustryChangeApplicationDocument).toJSON(),
);
return instanceToPlain(response);
} }
} }

View File

@ -3,7 +3,6 @@ import { HydratedDocument } from 'mongoose';
import { Decision } from './Decision.schema'; import { Decision } from './Decision.schema';
import { ApplicationStatus, ObjectStatus } from 'src/enums/status.enum'; import { ApplicationStatus, ObjectStatus } from 'src/enums/status.enum';
import { ICAInformation } from './ICAInformation.schema'; import { ICAInformation } from './ICAInformation.schema';
import { Exclude, Expose, Transform } from 'class-transformer';
export type IndustryChangeApplicationDocument = export type IndustryChangeApplicationDocument =
HydratedDocument<IndustryChangeApplication>; HydratedDocument<IndustryChangeApplication>;
@ -12,13 +11,6 @@ export type IndustryChangeApplicationDocument =
timestamps: true, timestamps: true,
}) })
export class IndustryChangeApplication { export class IndustryChangeApplication {
@Expose({ name: 'id' })
@Transform(({ key, obj }) => obj[key].toString())
_id: string;
@Exclude()
__v: number;
@Prop({ @Prop({
required: true, required: true,
}) })
@ -50,11 +42,9 @@ export class IndustryChangeApplication {
@Prop({ type: Decision }) @Prop({ type: Decision })
decision: Decision; decision: Decision;
@Exclude()
@Prop() @Prop()
createdBy: string; createdBy: string;
@Exclude()
@Prop() @Prop()
updatedBy: string; updatedBy: string;
@ -66,10 +56,8 @@ export class IndustryChangeApplication {
}) })
objectStatus: ObjectStatus; objectStatus: ObjectStatus;
@Exclude()
createdAt: Date; createdAt: Date;
@Exclude()
updatedAt: Date; updatedAt: Date;
} }