# entix-cli-app

## DB

### Create a migration file
```cmd
pnpm db migrate:make <migration-file-name>
```

### Run one migration
```cmd
pnpm db:up
```

### Rollback one migration
```cmd
pnpm db:down
```

### Run all migrations
```cmd
pnpm db:latest
```

### Rollback all migrations
```cmd
pnpm db:rollback
```

## Pagination
### Cursor Pagination
The base repository adds cursor pagination to all subclasses. This pagination is based on the created_at and id property which is expected to be included in each table that will use the cursor. 
The cursor is returned in reach response where a next page is availible, other wise the cursor will be set to null. This api does not provide a back cursor, instead the client is expected to keep a cursor stack and use that to move backward.

### Filtering
**Note**: Cursor should be removed from the request each time the search/filter query param changes, otherwise matches may be excluded from the returned results.

Filtering is supported and is added to the find method on the base class through defining a custom '$findQueryContext' then calling 'super.$findQueryContext' when done, please see an example below:
```ts
 $findQueryContext(
    query: Knex.QueryBuilder,
    filter: IUserQueryParams,
    options: IDbQueryOption,
  ) {
    if (filter?.search) {
      const { xid, first_name, last_name } = filter.search
      if (xid) query.andWhere(`${this.tableName}.xid`, xid)
      if (last_name)
        query.andWhere(`${this.tableName}.last_name`, 'ilike', `%${last_name}%`)
      if (first_name)
        query.andWhere(
          `${this.tableName}.first_name`,
          'ilike',
          `%${first_name}%`,
        )
    }
    return super.$findQueryContext(query, filter, options)
  }
```
