Closed cicciodifranco closed 7 months ago
@cicciodifranco nice feature, man. I will release it now!
@cicciodifranco I had an issue when generating the library package due to an error generated by TypeScript when creating a ParameterDecorator, as MongoQueryOptions cannot be nullable:
TS2322: Type '(...dataOrPipes: (MongoQueryOptions | PipeTransform<any, any> | Type<PipeTransform<any, any>>)[]) => ParameterDecorator' is not assignable to type '(opts?: MongoQueryOptions | undefined) => ParameterDecorator'. Types of parameters 'dataOrPipes' and 'opts' are incompatible. Type 'MongoQueryOptions | undefined' is not assignable to type 'MongoQueryOptions | PipeTransform<any, any> | Type<PipeTransform<any, any>>'. Type 'undefined' is not assignable to type 'MongoQueryOptions | PipeTransform<any, any> | Type<PipeTransform<any, any>>'.
Because of this, I will create and expose a method called MongoQueryOpts
, which performs the same operations as MongoQuery
, but with the possibility of having search options, as defined in your feature.
If there are questions or new suggestions for implementing this feature, please open a new Pull Request or an Issue, so that I can adjust it.
Thanks for the contribution!
a possible solution could be
export const MongoQuery: (data: MongoQueryOptions | undefined) => ParameterDecorator =
createParamDecorator(
(
data: MongoQueryOptions | undefined,
ctx: ExecutionContext,
): MongoQueryModel => {
const query = ctx.getArgByIndex(0).query;
return parse(query, data);
},
);
btw I will open a new pr for that
@cicciodifranco bruh, I didn't considerate this solution 🤦🏻 . No new pr needed, I will fix this now. Thanks!
Edit: feature available on v.1.0.13
✅
Overview:
This PR introduces a new feature aimed at enhancing the search capabilities. The primary focus is on enabling users to perform searches using regular expressions (RegExp) across multiple fields
Changes Made:
MongoQueryOptions
interface to provide users with the flexibility to specify search parameters, including the search key and paths for searching.Key Additions:
MongoQueryOptions
Interface: Introduced MongoQueryOptions interface to define search parameters, allowing users to specify the search key and paths for searching.getSearch
Function: Implemented a new function getSearch to parse search queries using regular expressions across specified fields. This function enhances the search capability of the library by enabling global searches across multiple fields.Result
Users can now pass options to
MongoQuery
decorator (useful for further options like defaultlimit
orsort
)Request
http://localhost:3000/resources?q=John
Query
Impact and Benefits:
MongoQueryOptions
interface provides users with greater control over search parameters, enhancing the flexibility of the library.