Git Product home page Git Product logo

nfw's Issues

problem with pagination and sorting combined

typeorm/typeorm#2912

Workaround : don't escape string / use parent alias before attribute

File : https://github.com/TRIPTYK/nfw/blob/develop/src/core/repositories/base.repository.ts

query parameter sort=name

if (allowSorting && query.sort) {
            const sortFields = splitAndFilter(query.sort, ","); // split parameters and filter empty strings

            // need to use SqlString.escapeId in order to prevent SQL injection on orderBy()
            for (const field of sortFields) {
                if (field[0] === "-") {  // JSON-API convention , when sort field starts with '-' order is DESC
                    queryBuilder.orderBy(SqlString.escapeId(field.substr(1)), "DESC");
                } else {
                    queryBuilder.orderBy(SqlString.escapeId(field), "ASC");
                }
            }
        }

TO

query parameter sort=<entity>.name

        if (allowSorting && query.sort) {
            const sortFields = splitAndFilter(query.sort, ","); // split parameters and filter empty string

            // need to use SqlString.escapeId in order to prevent SQL injection on orderBy()
            for (const field of sortFields)
            {
                if (field[0] === "-") {  // JSON-API convention , when sort field starts with '-' order is DESC
                    queryBuilder.addOrderBy(field.substr(1), "DESC");
                } else {
                    queryBuilder.addOrderBy(field, "ASC");
                }
            }
        }

classify services

global service container

  • OAuth
  • Cache

config classify

  • Passport
  • Multer
  • Logger
  • Env

Improve the serializers

We should consider improving the serializing/de-serializing process. They are not generic enough

ACL & security

Use an ACL module to authorize GET / LIST / CREATE / DELETE / UPDATE for resources

Param order matter when it should not

Reproduce issue:

  @JsonApiGet()
  async get (@Param('id') id: string, query: JsonApiQuery, @CurrentUser() currentUser: UserModel) {
    const document = await this.documentService.getOneOrFail(id, query);
    await canOrFail(this.authorizer, currentUser, 'read', [document])
    return this.registry.getSerializerFor<DocumentResource>('documents').serializeOne(document);
  }

This create an error because query become currentUser.

  @JsonApiGet()
  async get (@Param('id') id: string, @JsonApiQueryDecorator(RESOURCE_NAME) query: JsonApiQuery, @CurrentUser() currentUser: UserModel) {
    const document = await this.documentService.getOneOrFail(id, query);
    await canOrFail(this.authorizer, currentUser, 'read', [document])
    return this.registry.getSerializerFor<DocumentResource>('documents').serializeOne(document);
  }

This does not create an error because currentUser is correctly assigned

Expected:

Decorator to assign the param assigned to it and not the param before

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.