1.1.8 • Published 5 months ago

nemopa v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Install

with npm

npm i nemopa

with yarn

yarn add nemopa

Using

import { Paging, PagingInputInterface, PagingWithPage } from "nemopa";

/**
 * filter is a MongoDB Filter<T>
 */
interface FindManyProps {
  filter: any;
  paging: PagingInputInterface;
}

/**
 * In case I choose updatedAt_utc as a Cursor
 */
interface TodoDocument {
  updatedAt_utc: Date;
}

class TodoCRUD {
  private model: Model<TodoDocument>;
  async findMany(props: FindManyProps) {
    const { filter, sort, build } = new Paging<TodoDocument>({
      cursors: props?.paging?.cursors,
      filter: props.filter,
      order: Paging.DESC,
      key: "updatedAt_utc",
      KeyType: Date,
    });
    const limit = Number(props?.paging?.limit || 10);
    if (limit > 20) throw new Error("rate limit");

    const skip = Number(props?.paging?.offset);
    const many = await this.model
      .find(filter)
      .sort(sort)
      .limit(limit)
      .skip(skip);
    return build(many, this.model);
  }
}
1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago