list space-model

This commit is contained in:
hannathkadher
2024-12-18 11:40:45 +04:00
parent 70e1fe2ae5
commit 7833151b70
7 changed files with 111 additions and 11 deletions

View File

@ -273,6 +273,10 @@ export class ControllerRoute {
'Create a New Space Model';
public static readonly CREATE_SPACE_MODEL_DESCRIPTION =
'This endpoint allows you to create a new space model within a specified project. A space model defines the structure of spaces, including subspaces, products, and product items, and is uniquely identifiable within the project.';
public static readonly LIST_SPACE_MODEL_SUMMARY = 'List Space Models';
public static readonly LIST_SPACE_MODEL_DESCRIPTION =
'This endpoint allows you to retrieve a list of space models within a specified project. Each space model includes its structure, associated subspaces, products, and product items.';
};
};

View File

@ -13,6 +13,7 @@ export const PermissionMapping = {
'UPDATE',
'DELETE',
'MODULE_ADD',
'MODEL_VIEW',
'ASSIGN_USER_TO_SPACE',
'DELETE_USER_FROM_SPACE',
],

View File

@ -17,6 +17,7 @@ export const RolePermissions = {
'SPACE_UPDATE',
'SPACE_DELETE',
'SPACE_MODULE_ADD',
'SPACE_MODEL_VIEW',
'ASSIGN_USER_TO_SPACE',
'DELETE_USER_FROM_SPACE',
'SUBSPACE_VIEW',
@ -60,6 +61,7 @@ export const RolePermissions = {
'SPACE_UPDATE',
'SPACE_DELETE',
'SPACE_MODULE_ADD',
'SPACE_MODEL_VIEW',
'ASSIGN_USER_TO_SPACE',
'DELETE_USER_FROM_SPACE',
'SUBSPACE_VIEW',

View File

@ -31,7 +31,7 @@ interface FindAllQueryWithDefaults extends CustomFindAllQuery {
function getDefaultQueryOptions(
query: Partial<TypeORMCustomModelFindAllQuery>,
): FindManyOptions & FindAllQueryWithDefaults {
const { page, size, includeDisable, modelName, ...rest } = query;
const { page, size, includeDisable, include, modelName, ...rest } = query;
// Set default if undefined or null
const returnPage = page ? Number(page) : 1;
@ -48,7 +48,9 @@ function getDefaultQueryOptions(
},
page: returnPage,
size: returnSize,
include: include || undefined,
includeDisable: returnIncludeDisable,
modelName: modelName || query.modelName, // Ensure modelName is passed through
};
}
@ -97,7 +99,6 @@ export function TypeORMCustomModel(repository: Repository<any>) {
// Use the where clause directly, without wrapping it under 'where'
const whereClause = buildTypeORMWhereClause({ where });
console.log('Final where clause:', whereClause);
// Ensure the whereClause is passed directly to findAndCount
const [data, count] = await repository.findAndCount({

View File

@ -19,6 +19,19 @@ const mappingInclude: { [key: string]: any } = {
project: {
project: true,
},
'space-model': {
subspaceModels: 'subspace-model',
spaceProductModels: 'space-product-model',
},
'subspace-model': {
productModels: 'subspace-product-model',
},
'subspace-product-model': {
itemModels: true,
},
'space-product-model': {
items: true,
},
};
export function buildTypeORMIncludeQuery(
@ -30,17 +43,33 @@ export function buildTypeORMIncludeQuery(
const fieldsToInclude: string[] = includeParam.split(',');
fieldsToInclude.forEach((field: string) => {
if (mappingInclude[field]) {
relations.push(field); // Push mapped field
} else {
console.warn(
`Field ${field} not found in mappingInclude for ${modelName}`,
);
const nestedFields = field.split('.');
let currentModelName = modelName;
let isValid = true;
nestedFields.forEach((nestedField, index) => {
const currentMapping = mappingInclude[currentModelName];
if (currentMapping?.[nestedField]) {
currentModelName =
typeof currentMapping[nestedField] === 'string'
? currentMapping[nestedField]
: currentModelName;
} else {
console.warn(
`Field "${nestedFields.slice(0, index + 1).join('.')}" not found in mappingInclude for model "${currentModelName}"`,
);
isValid = false;
return;
}
});
if (isValid) {
relations.push(field);
}
});
return relations;
return relations.length ? relations : undefined;
}
return undefined; // If no includes, return undefined
return undefined;
}