mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
list space-model
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user