Add function to remove circular references and use it in SpaceService

This commit is contained in:
faris Aljohari
2025-02-03 07:38:19 -06:00
parent 94bec00f7f
commit 9dcb68da2d
2 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,12 @@
export function removeCircularReferences() {
const seen = new WeakSet();
return (key: string, value: any) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return undefined; // Skip circular reference
}
seen.add(value);
}
return value;
};
}

View File

@ -33,6 +33,7 @@ import { TagService } from './tag';
import { SpaceModelService } from 'src/space-model/services';
import { DisableSpaceCommand } from '../commands';
import { GetSpaceDto } from '../dtos/get.space.dto';
import { removeCircularReferences } from '@app/common/helper/removeCircularReferences';
@Injectable()
export class SpaceService {
constructor(
@ -116,7 +117,7 @@ export class SpaceService {
return new SuccessResponseDto({
statusCode: HttpStatus.CREATED,
data: newSpace,
data: JSON.parse(JSON.stringify(newSpace, removeCircularReferences())),
message: 'Space created successfully',
});
} catch (error) {