typeorm-express-query-filter
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

typeorm-express-query-filter

Installation
npm i typeorm-express-query-filter

Usage:

  • Extend class QueryableRepository\<Entity\>
  • Call function findWithPagination(req, res, findOptions<Entity>)
    • req - express request
    • res - express response
    • findOptions - typeorm find options object (optional)

Example model:

{
  @PrimaryGeneratedColumn()
  public id: number;
  @Column()
  public firstName: string;
  @Column()
  public lastName: string;
  @ManyToMany(() => Roles)
  @JoinTable({name: 'user_role'})
  public roles: Role[];
  @Column('date)
  public createdAt: Date;
  @OneToMany(() => Phone)
  public phones: Phone[];
}

Example:
GET URL: /api/users?firstName.contains=john&phones.equals=phoneId&roles.in=${roleId}&page=0&size=20&relations=roles&sort=createdAt-

const roleId=1; // role id
const phoneId=1; // phone id
relations=roles; // will fetch user roles relation
page=0; // first page
size=20; // page size
sort=createdAt-; // sort by createdAt (-) descending
firstName.contains=john; // get all users with firstName containing 'john'
phones.equals=phoneId; // get user by phone id

In response headers under X-Total-Count will be pagination total count.

build:

  • npm run-script build

/typeorm-express-query-filter/

    Package Sidebar

    Install

    npm i typeorm-express-query-filter

    Weekly Downloads

    1

    Version

    0.0.13

    License

    MIT

    Unpacked Size

    25.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • mardari