add subspace controller

This commit is contained in:
hannathkadher
2024-10-28 09:53:47 +04:00
parent 6d6560b3e0
commit 74428b408e
15 changed files with 401 additions and 18 deletions

View File

@ -129,4 +129,30 @@ export class ControllerRoute {
'Disassociates a user from a space by removing the existing association.';
};
};
static SUBSPACE = class {
public static readonly ROUTE =
'/communities/:communityUuid/spaces/:spaceUuid/subspaces';
static ACTIONS = class {
public static readonly CREATE_SUBSPACE_SUMMARY = 'Create Subspace';
public static readonly CREATE_SUBSPACE_DESCRIPTION =
'Creates a new subspace within a specific space and community.';
public static readonly LIST_SUBSPACES_SUMMARY = 'List Subspaces';
public static readonly LIST_SUBSPACES_DESCRIPTION =
'Retrieves a list of subspaces within a specified space and community.';
public static readonly GET_SUBSPACE_SUMMARY = 'Get Subspace';
public static readonly GET_SUBSPACE_DESCRIPTION =
'Fetches a specific subspace by UUID within a given space and community';
public static readonly UPDATE_SUBSPACE_SUMMARY = 'Update Subspace';
public static readonly UPDATE_SUBSPACE_DESCRIPTION =
'Updates a specific subspace within a given space and community.';
public static readonly DELETE_SUBSPACE_SUMMARY = 'Delete Subspace';
public static readonly DELETE_SUBSPACE_DESCRIPTION =
'Deletes a specific subspace within a given space and community.';
};
};
}

View File

@ -15,9 +15,6 @@ export class SpacePermissionService {
const spaceData = await this.spaceRepository.findOne({
where: {
uuid: spaceUuid,
spaceType: {
type: type,
},
userSpaces: {
user: {
uuid: userUuid,

View File

@ -97,7 +97,7 @@ export function TypeORMCustomModel(repository: Repository<any>) {
// Use the where clause directly, without wrapping it under 'where'
const whereClause = buildTypeORMWhereClause({ where });
console.log('Where clause after building:', whereClause);
console.log('Final where clause:', whereClause);
// Ensure the whereClause is passed directly to findAndCount
const [data, count] = await repository.findAndCount({
@ -112,7 +112,7 @@ export function TypeORMCustomModel(repository: Repository<any>) {
const paginationResponseDto = getPaginationResponseDto(count, page, size);
const baseResponseDto: BaseResponseDto = {
data,
message: getResponseMessage(modelName, { where: whereClause }),
message: getResponseMessage(modelName, { where }),
};
return { baseResponseDto, paginationResponseDto };

View File

@ -1,6 +1,6 @@
import { DataSource, Repository } from 'typeorm';
import { Injectable } from '@nestjs/common';
import { SpaceEntity, SpaceTypeEntity } from '../entities';
import { SpaceEntity, SpaceTypeEntity, SubspaceEntity } from '../entities';
@Injectable()
export class SpaceRepository extends Repository<SpaceEntity> {
@ -15,3 +15,10 @@ export class SpaceTypeRepository extends Repository<SpaceTypeEntity> {
super(SpaceTypeEntity, dataSource.createEntityManager());
}
}
@Injectable()
export class SubspaceRepository extends Repository<SubspaceEntity> {
constructor(private dataSource: DataSource) {
super(SubspaceEntity, dataSource.createEntityManager());
}
}

View File

@ -13,6 +13,9 @@ const mappingInclude: { [key: string]: any } = {
space: {
space: true,
},
subspace: {
subspace: true,
},
};
export function buildTypeORMIncludeQuery(

View File

@ -1,10 +1,29 @@
import { FindOptionsWhere } from 'typeorm';
export function buildTypeORMWhereClause({
where,
}: {
where?: FindOptionsWhere<any> | FindOptionsWhere<any>[]; // Accepts both object and array formats
}): FindOptionsWhere<any> | FindOptionsWhere<any>[] {
// Return the 'where' clause directly, without wrapping
return where || {}; // If 'where' is undefined, return an empty object
export function buildTypeORMWhereClause({ where }) {
if (!where) return {};
// Remove extra nesting if `where` is wrapped within an additional `where` property
const condition = where.where ? where.where : where;
console.log(condition);
const convertToNestedObject = (condition: any): any => {
const result = {};
for (const [key, value] of Object.entries(condition)) {
if (key.includes('.')) {
const [parentKey, childKey] = key.split('.');
result[parentKey] = {
...(result[parentKey] || {}),
[childKey]: value,
};
} else {
result[key] = value;
}
}
return result;
};
return Array.isArray(condition)
? condition.map((item) => convertToNestedObject(item))
: convertToNestedObject(condition);
}