added community space

This commit is contained in:
hannathkadher
2024-10-15 11:38:49 +04:00
parent 2292c01220
commit d14d3b5ba2
16 changed files with 253 additions and 11 deletions

View File

@ -0,0 +1,42 @@
type TypeORMIncludeQuery = string[];
const mappingInclude: { [key: string]: any } = {
roles: {
role: true,
},
users: {
user: true,
},
community: {
community: true,
},
space: {
space: true,
},
};
export function buildTypeORMIncludeQuery(
modelName: string,
includeParam?: string,
): TypeORMIncludeQuery | undefined {
if (includeParam) {
const relations: TypeORMIncludeQuery = [];
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}`,
);
}
});
console.log(`Including relations for ${modelName}:`, relations);
return relations;
}
return undefined; // If no includes, return undefined
}

View File

@ -0,0 +1,18 @@
type TypeORMSortQuery = { [key: string]: 'ASC' | 'DESC' };
export function buildTypeORMSortQuery(
sortParam: string | undefined,
): TypeORMSortQuery {
// sortParam format: userId:asc,createdDate:desc
if (!sortParam) {
return {};
}
const conditions: string[] = sortParam.split(',');
return conditions.reduce((acc: TypeORMSortQuery, condition) => {
const [field, direction] = condition.split(':').map((str) => str.trim());
acc[field] = direction.toUpperCase() === 'DESC' ? 'DESC' : 'ASC';
return acc;
}, {});
}

View File

@ -0,0 +1,10 @@
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
}

View File

@ -0,0 +1,21 @@
import { PageResponseDto } from '../dto/pagination.response.dto';
export function getPaginationResponseDto(
count: number,
page: number,
size: number,
): PageResponseDto {
const totalItem = count;
const totalPage = Math.ceil(totalItem / size);
const hasNext = page < totalPage ? true : false;
const hasPrevious = page === 1 || page > totalPage ? false : true;
return {
hasNext,
hasPrevious,
page,
size,
totalItem,
totalPage,
};
}