From 521fed8fda810d5dc1487db7c7a97962ea3baa0a Mon Sep 17 00:00:00 2001 From: tada5hi Date: Fri, 21 Oct 2022 11:54:01 +0200 Subject: [PATCH] fix: example in README.md & bump version --- README.MD | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/README.MD b/README.MD index 90ee168e..38facbe3 100644 --- a/README.MD +++ b/README.MD @@ -238,8 +238,7 @@ export class Item { import { Request, Response } from 'express'; import { - applyQueryParseOutput, - parseQuery, + applyQuery, useDataSource } from 'typeorm-extension'; @@ -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(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'], @@ -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(); @@ -291,7 +286,7 @@ export async function getUsers(req: Request, res: Response) { data: entities, meta: { total, - ...output.pagination + ...pagination } } });