Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pagination. Add Page class and req params mapper #101

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

OlegMakarenko
Copy link
Contributor

@OlegMakarenko OlegMakarenko commented Nov 9, 2021

Usage:

import { reqToPageParameters } from '@src/utils';
import { Page } from '@src/infrastructure/Page';

async (req: Request): Promise<ExamplePageDTO> => {
	return (
		await new Page<IExample, ExampleDTO>(
			reqToPageParameters(req, ['filter1']), // map query parameters to search criteria and filters
			ExampleMongooseModel, // mongoose.Model<IExample>
			(_) => _.map(ExampleService.convertToDTO), // map document to DTO
		).exec()
	).toObject();
},

@OlegMakarenko OlegMakarenko linked an issue Nov 9, 2021 that may be closed by this pull request
@@ -58,3 +60,10 @@ export const splitArray = (array: Array<any>, chunks: number): Array<any> =>
all[ch] = [].concat(all[ch] || [], one);
return all;
}, []);

export const reqToPageParameters = (req: Request, filterKeys?: Array<string>): { [key: string]: unknown } => {
Copy link
Member

@AnthonyLaw AnthonyLaw Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array<string> vs string[]

I think we have different styles for the Typescript type, should we unite the style?

Copy link
Member

@AnthonyLaw AnthonyLaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good for me.
@fboucquez @yilmazbahadir has a better experience than me as they are working pagination for SDK and REST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

task: add pagination
2 participants