Skip to content

Commit

Permalink
FilterMerge helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kaihaase committed Nov 4, 2023
1 parent e7aa550 commit 346f7dd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lenne.tech/nest-server",
"version": "10.0.11",
"version": "10.1.0",
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
"keywords": [
"node",
Expand Down
1 change: 1 addition & 0 deletions src/config.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const config: { [env: string]: IServerOptions } = {
},
},
},
hostname: 'localhost',
ignoreSelectionsForPopulate: true,
jwt: {
// Each secret should be unique and not reused in other environments,
Expand Down
39 changes: 34 additions & 5 deletions src/core/common/helpers/filter.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export function generateFilterQuery<T = any>(
case ComparisonOperatorEnum.REGEX:
result[field] = not
? {
$not: {
$regex: new RegExp(value),
$options: options || '',
},
}
$not: {
$regex: new RegExp(value),
$options: options || '',
},
}
: { $regex: new RegExp(value), $options: options || '' };
break;
}
Expand Down Expand Up @@ -265,3 +265,32 @@ export function generateFindOptions(

return queryOptions;
}

/**
* Merge FilterArgs and FilterQueries
*/
export function filterMerge<T = unknown>(
filterArgs: Partial<FilterArgs>,
filterQuery: Partial<FilterQuery<T>>,
options?: {
operator?: '$and' | '$or' | '$nor';
queryOptions?: Partial<QueryOptions>;
samples?: number;
},
): { filterQuery: FilterQuery<T>; queryOptions?: QueryOptions; samples?: number } {
const config = {
operator: '$and',
...options,
};
const converted = convertFilterArgsToQuery(filterArgs);
return {
filterQuery: (converted[0]
? { [config.operator]: [converted[0], filterQuery || {}] }
: filterQuery
) as FilterQuery<T>,
queryOptions: converted[1] || config.queryOptions
? { ...converted[1], ...config.queryOptions }
: undefined,
samples: config.samples,
};
}
6 changes: 6 additions & 0 deletions src/core/common/interfaces/server-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ export interface IServerOptions {
};
};

/**
* Hostname of the server
* default: localhost
*/
hostname?: string;

/**
* Ignore selections in fieldSelection
* [ConfigService must be integrated in ModuleService]
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ async function bootstrap() {
server.enableCors();

// Start server on configured port
await server.listen(envConfig.port);
await server.listen(envConfig.port, envConfig.hostname);
console.debug(`Server startet at ${await server.getUrl()}`);

// Run command after server init
if (envConfig.execAfterInit) {
Expand Down

0 comments on commit 346f7dd

Please sign in to comment.