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

@ -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);
}