Skip to content

Commit

Permalink
fix: example in README.md & bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Oct 21, 2022
1 parent 4483454 commit 521fed8
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ export class Item {
import { Request, Response } from 'express';

import {
applyQueryParseOutput,
parseQuery,
applyQuery,
useDataSource
} from 'typeorm-extension';

Expand All @@ -252,9 +251,14 @@ import {
* @param res
*/
export async function getUsers(req: Request, res: Response) {
// const {fields, filter, include, page, sort} = req.query;
const dataSource = await useDataSource();
const repository = dataSource.getRepository(User);
const query = repository.createQueryBuilder('user');

const output = parseQuery<User>(req.query, {
// -----------------------------------------------------

// parse and apply data on the db query.
const { pagination } = applyQuery(query, req.query, {
defaultPath: 'user',
fields: {
allowed: ['id', 'name', 'realm.id', 'realm.name'],
Expand All @@ -273,15 +277,6 @@ export async function getUsers(req: Request, res: Response) {
}
});

const dataSource = await useDataSource();
const repository = dataSource.getRepository(User);
const query = repository.createQueryBuilder('user');

// -----------------------------------------------------

// apply parsed data on the db query.
const parsed = applyQueryParseOutput(query, output);

// -----------------------------------------------------

const [entities, total] = await query.getManyAndCount();
Expand All @@ -291,7 +286,7 @@ export async function getUsers(req: Request, res: Response) {
data: entities,
meta: {
total,
...output.pagination
...pagination
}
}
});
Expand Down

0 comments on commit 521fed8

Please sign in to comment.