Skip to content

Commit 968f778

Browse files
committed
fix: Transform null values to empty strings in IdentitiesService
1 parent fe1a9fe commit 968f778

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/management/identities/identities.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class IdentitiesService extends AbstractServiceSchema {
3737
data?: any,
3838
options?: SaveOptions,
3939
): Promise<Document<T, any, T>> {
40+
data = this.transformNullsToString(data);
4041
await this.checkInetOrgPersonJpegPhoto(data);
4142
const created: Document<T, any, T> = await super.create(data, options);
4243
return created;
@@ -48,6 +49,7 @@ export class IdentitiesService extends AbstractServiceSchema {
4849
data?: IdentitiesUpsertDto,
4950
options?: QueryOptions<T>,
5051
): Promise<[HttpStatus.OK | HttpStatus.CREATED, ModifyResult<Query<T, T, any, T>>]> {
52+
data = this.transformNullsToString(data);
5153
const identity = await this.model.findOne(filters).exec();
5254
this.logger.log(`Upserting identity with filters ${JSON.stringify(filters)}`);
5355

@@ -65,6 +67,8 @@ export class IdentitiesService extends AbstractServiceSchema {
6567
]),
6668
});
6769

70+
console.log('data', data);
71+
6872
if (!data?.inetOrgPerson?.employeeNumber || !data?.inetOrgPerson?.employeeType) {
6973
throw new BadRequestException(
7074
'inetOrgPerson.employeeNumber and inetOrgPerson.employeeType are required for create identity.',
@@ -121,6 +125,7 @@ export class IdentitiesService extends AbstractServiceSchema {
121125
update: UpdateQuery<T>,
122126
options?: QueryOptions<T> & { rawResult: true },
123127
): Promise<ModifyResult<Query<T, T, any, T>>> {
128+
update = this.transformNullsToString(update);
124129
// noinspection UnnecessaryLocalVariableJS
125130
//TODO : add validation logic here
126131
const logPrefix = `Validation [${update.inetOrgPerson.cn}]:`;
@@ -312,4 +317,26 @@ export class IdentitiesService extends AbstractServiceSchema {
312317
}
313318
}
314319
}
320+
321+
private transformNullsToString(obj) {
322+
if (obj === null) {
323+
return "";
324+
}
325+
326+
if (Array.isArray(obj)) {
327+
return obj.map(this.transformNullsToString);
328+
}
329+
330+
if (typeof obj === 'object') {
331+
for (const key in obj) {
332+
if (obj[key] === null) {
333+
obj[key] = "";
334+
} else if (typeof obj[key] === 'object') {
335+
obj[key] = this.transformNullsToString(obj[key]);
336+
}
337+
}
338+
}
339+
340+
return obj;
341+
}
315342
}

0 commit comments

Comments
 (0)