Skip to content

Commit

Permalink
chore: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelTshDev committed Mar 14, 2024
1 parent ecc9e03 commit 1bf1dd6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryHandler } from "@tshio/query-bus";
import { CacheQuery } from "../../../../shared/cache-decorator";
import { USERS_QUERY_TYPE, UsersQuery, UsersQueryResult } from "../queries/users";
import { UserEntity } from "../models/user.entity";
import { calculateSkipFindOption, isFilterAvailable, makePaginationMeta } from "../../../../shared/pagination-meta/pagination-meta";
import { calculateSkipFindOption, isFilterAvailable, makePaginationResult } from "../../../../shared/pagination-meta/pagination-meta";

export interface UsersQueryHandlerInterface {
userRepository: Repository<UserEntity>;
Expand Down Expand Up @@ -33,6 +33,6 @@ export default class UsersQueryHandler implements QueryHandler<UsersQuery, Users

const [data, total] = await this.dependencies.userRepository.findAndCount(findOptions);

return new UsersQueryResult(makePaginationMeta(data, total, limit, page));
return new UsersQueryResult(makePaginationResult(data, total, limit, page));
}
}
8 changes: 4 additions & 4 deletions src/shared/pagination-meta/pagination-meta.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "mocha";
import { expect } from "chai";
import { makePaginationMeta, normalizePage } from "./pagination-meta";
import { makePaginationResult, normalizePage } from "./pagination-meta";

describe("pagination-meta", () => {
const data = [
Expand All @@ -19,7 +19,7 @@ describe("pagination-meta", () => {
];

it("returns valid pagination", async () => {
const result = makePaginationMeta(data, 10, 4, 2);
const result = makePaginationResult(data, 10, 4, 2);
expect(result).to.include.deep.equal({
meta: {
page: 2,
Expand All @@ -32,7 +32,7 @@ describe("pagination-meta", () => {
});

it("returns valid pagination if limit is 0", async () => {
const result = makePaginationMeta(data, 10, 0, 2);
const result = makePaginationResult(data, 10, 0, 2);
expect(result).to.include.deep.equal({
meta: {
page: 2,
Expand All @@ -45,7 +45,7 @@ describe("pagination-meta", () => {
});

it("returns first page if passed 0 page", async () => {
const result = makePaginationMeta(data, 10, 5, 2);
const result = makePaginationResult(data, 10, 5, 2);
expect(result).to.include.deep.equal({
meta: {
page: 2,
Expand Down
4 changes: 2 additions & 2 deletions src/shared/pagination-meta/pagination-meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Repository } from "typeorm";
import { AppError } from "../../errors/app.error";

export interface PaginationMeta {
export interface PaginationResult {
meta: {
page?: number;
limit?: number;
Expand All @@ -24,7 +24,7 @@ export function isFilterAvailable(filter: any, repository: Repository<any>): boo
throw new AppError("Invalid query string");
}

export function makePaginationMeta(data: any, total: number, limit?: number, page?: number): PaginationMeta {
export function makePaginationResult(data: any, total: number, limit?: number, page?: number): PaginationResult {
return {
meta: {
page: page || 1,
Expand Down

0 comments on commit 1bf1dd6

Please sign in to comment.