Type Parameters

  • T extends BaseModel

Implements

Constructors

Properties

authUser: undefined | BaseUser
model: PaginateModel<T, {}, {}>
modelName: string

The name of the model.

Accessors

Methods

  • Soft delete an entity by its ID. This operation marks the entity as deleted without permanently destroying the record.

    Parameters

    • id: string

      The ID of the entity to delete. @returns- A promise that resolves to the deleted entity or null if not found.

    Returns Promise<null | Saved<T>>

  • Find an entity by its ID.

    Parameters

    • id: string

      The ID of the entity to find.

    • fields: SelectQuery<T>[] = []

      Fields to select in the returned entity.

    • OptionallistQueryOptions: ListQueryOptions<T>

    Returns Promise<null | Saved<T>>

    • A promise that resolves to the found entity or null if not found.
  • Find one entity matching the query.

    Parameters

    • query: FilterQuery<T> = {}
    • fields: SelectQuery<T>[] = []
    • OptionallistQueryOptions: ListQueryOptions<T>

    Returns Promise<null | Saved<T>>

    • A promise that resolves to the found entity or null if not found.
  • List entities matching the query.

    Parameters

    • query: FilterQuery<T> = {}

      The query to filter documents.

    • fields: SelectQuery<T>[] = []

      Fields to select in the returned entities.

    • OptionallistQueryOptions: ListQueryOptions<T>

    Returns Promise<Saved<T>[]>

    • A promise that resolves to an array of found entities.
  • Update an entity by its ID.

    Parameters

    • id: string

      The ID of the entity to update.

    • entity: PartialQuery<T>

      The partial entity to update.

    • Optionaloptions: UpdateOptions

    Returns Promise<null | Saved<T>>

    • A promise that resolves to the updated entity or null if not found.
  • Update multiple entities matching the filter.

    Parameters

    • filter: FilterQuery<T> = {}

      The filter to match documents.

    • update: PartialQuery<T>

      The partial update to apply.

    Returns Promise<number>

    • A promise that resolves to the number of documents updated.
  • Update a single entity matching the filter.

    Parameters

    • filter: FilterQuery<T> = {}

      The filter to match documents.

    • update: PartialQuery<T>

      The partial update to apply.

    • Optionaloptions: UpdateOneOptions

      Options for updating a single document.

    Returns Promise<null | Saved<T>>

    | null>} - A promise that resolves to the updated entity or null if not found.

  • Upsert a single record based on certain criteria.

    Parameters

    • filter: FilterQuery<T>

      The filter to find the record to update or insert.

    • entity: PartialQuery<T>

      The entity to upsert.

    Returns Promise<null | Saved<T>["_id"]>

    The return types of this method align with the MongoDB UpdateResult interface

    • Returns models.baseModel.Saved<T>['_id'] if the document did not exist (an upsert took place).
    • Returns null if the document did exist before the upsert operation.