Coder Social home page Coder Social logo

Comments (10)

akashabbasi avatar akashabbasi commented on May 28, 2024 1

Like currently search decorator i guess is working like this. it only works for property of string type and lets say we pass search=abc then if available search is on ['firstname', 'email'] then search decorator will transform the values for both firstname and email. and it will be search in database then

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

I think that's because of nestjs request life cycle
Our dto will serialize with class-transformer and then validate with class-validation from typestack.ย 
The entire process will be carried out in the ValidationPipe from @nestjs/common as a global pipe.

As you can see in the doc request life cycle, the global pipe will run after the pre-interceptor.ย 
That why you query params only accessable in interceptor.

So, I guess your problem comes because of the wrong implementation options of ValidationPipe.ย 
Try to set false for whitelist options, maybe that will help to solve your problem.

Here if you need to read more documentation about ValidationPipe

from ack-nestjs-boilerplate.

akashabbasi avatar akashabbasi commented on May 28, 2024

I have tried to make it work by setting IsOptional decorator on properties which we don't expect from front-end like availableSort & availableSearch. Without this decorator inside controller these properties were not accessible.

But my problem still exist with search property. Transform decorator for search tries to create regex for each value inside availableSearch array. my question is how we can make it work for non-string values?

How we can make sorting to work with multiple values at same time

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

Yes, correct! That will work with string type or number type only, and then it depends on AvailableSearch.ย 
The logic of search is only for simple usage.ย 
The search will use regex to make it case insensitive and contain some value.

eg:

{
    "name": {
        "first": "ack",
        "last": "mongoose"
    },
    "phone": "621313121111",
    "email": "[email protected]"
}

and then, you can make AvailableSearch like this to search inside the object.

const availableSearch = [
    'name.first',
    'name.last',
    'name',
]

Okay, there are 2 questions.

  1. How we can make it work for non-string values?

If you want to advance usage, I suggest you make an edit toย PaginationModule with your logic.
For the current version, look in src-> common-> pagination-> decorator-> pagination.decorator.ts -> PaginationSearch, and then edit the @Transform Decorator.ย 

  1. How we can make sorting to work with multiple values at same time?

Same with answer 1. You must change the @Transform Decorator in PaginationSort with your own logic.ย 
The current sort decorator only supports 1 sort.

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

Or you can add more PaginationFilter for other cases.

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

The problem you have about not accessible property in controller, maybe because of ValidationPipe

@Module({
    controllers: [],
    providers: [
        {
            provide: APP_PIPE,
            useFactory: () =>
                new ValidationPipe({
                    transform: true, // <-- try to set it with true
                    whitelist: false, // <-- try to set it with false
                    skipNullProperties: false, // <-- try to set it with false
                    skipUndefinedProperties: false, // <-- try to set it with false
                    skipMissingProperties: false, // <-- try to set it with false
                    errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
                    exceptionFactory: async (errors: ValidationError[]) =>
                        new UnprocessableEntityException({
                            statusCode:
                                ENUM_REQUEST_STATUS_CODE_ERROR.REQUEST_VALIDATION_ERROR,
                            message: 'http.clientError.unprocessableEntity',
                            errors,
                        }),
                }),
        },
    ],
    imports: [],
})
export class RequestModule {}

from ack-nestjs-boilerplate.

akashabbasi avatar akashabbasi commented on May 28, 2024

Thanks for your response. if you can provide postman collection you used to test the endpoints of this repo. it would be very helpful as i have some confusion related to passing some of query params to these endpoints.

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

Sure, i will.
Endpoint will describe with swagger (on progress) and i will update the documentation.
Stay tuned๐Ÿ˜

from ack-nestjs-boilerplate.

andrechristikan avatar andrechristikan commented on May 28, 2024

Hi @akashabbasi,
I already done to add the API Spec with swagger, go check the current version
Thank you ๐Ÿ˜

from ack-nestjs-boilerplate.

akashabbasi avatar akashabbasi commented on May 28, 2024

Let me check it ๐Ÿ‘

from ack-nestjs-boilerplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.