mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
Merge pull request #240 from SyncrowIOT/fix-create-space-issue
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 { SpaceModelService } from 'src/space-model/services';
|
||||||
import { DisableSpaceCommand } from '../commands';
|
import { DisableSpaceCommand } from '../commands';
|
||||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||||
|
import { removeCircularReferences } from '@app/common/helper/removeCircularReferences';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceService {
|
export class SpaceService {
|
||||||
constructor(
|
constructor(
|
||||||
@ -116,7 +117,7 @@ export class SpaceService {
|
|||||||
|
|
||||||
return new SuccessResponseDto({
|
return new SuccessResponseDto({
|
||||||
statusCode: HttpStatus.CREATED,
|
statusCode: HttpStatus.CREATED,
|
||||||
data: newSpace,
|
data: JSON.parse(JSON.stringify(newSpace, removeCircularReferences())),
|
||||||
message: 'Space created successfully',
|
message: 'Space created successfully',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user