Skip to content

Commit

Permalink
policy e2e test fail fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjiequan authored and bpedersen2 committed Jan 19, 2024
1 parent a8fefc3 commit fd8b64e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ export const parseLimitFilters = (
sort?: { [key: string]: "asc" | "desc" } | string;
} => {
if (!limits) {
return { limit: 100, skip: 0 };
return { limit: 100, skip: 0, sort: {} };
}
const limit = limits.limit ? limits.limit : 100;
const skip = limits.skip ? limits.skip : 0;
let sort;
let sort = {};
if (limits.order) {
const [field, direction] = limits.order.split(":");
if (direction === "asc" || direction === "desc") {
Expand Down
27 changes: 13 additions & 14 deletions src/policies/policies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { Request } from "express";
import { JWTUser } from "src/auth/interfaces/jwt-user.interface";
import { UsersService } from "src/users/users.service";
import { IPolicyFilter } from "./interfaces/policy-filters.interface";
import { addCreatedByFields, addUpdatedByField } from "src/common/utils";
import {
addCreatedByFields,
addUpdatedByField,
parseLimitFilters,
} from "src/common/utils";
import { REQUEST } from "@nestjs/core";

@Injectable()
Expand Down Expand Up @@ -100,19 +104,14 @@ export class PoliciesService implements OnModuleInit {

async findAll(filter: IPolicyFilter): Promise<Policy[]> {
const whereFilter: FilterQuery<PolicyDocument> = filter.where ?? {};
let limit = 100;
let skip = 0;
let sort = {};
if (filter.limit) {
limit = filter.limit;
}
if (filter.skip) {
skip = filter.skip;
}
if (filter.order) {
const [field, direction] = filter.order.split(":");
sort = { [field]: direction };
}

const limits = {
limit: filter.limit as number,
skip: filter.skip as number,
order: filter.order as string,
};
const { limit, skip, sort } = parseLimitFilters(limits);

return this.policyModel
.find(whereFilter)
.limit(limit)
Expand Down

0 comments on commit fd8b64e

Please sign in to comment.