mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 10:25:23 +00:00
add subspace controller
This commit is contained in:
@ -13,6 +13,9 @@ const mappingInclude: { [key: string]: any } = {
|
||||
space: {
|
||||
space: true,
|
||||
},
|
||||
subspace: {
|
||||
subspace: true,
|
||||
},
|
||||
};
|
||||
|
||||
export function buildTypeORMIncludeQuery(
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user