mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Add function to remove circular references and use it in SpaceService
This commit is contained in:
12
libs/common/src/helper/removeCircularReferences.ts
Normal file
12
libs/common/src/helper/removeCircularReferences.ts
Normal 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;
|
||||
};
|
||||
}
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user