Abstract class representing a generic data service with CRUD operations and sanitization capabilities.

Hierarchy (View Summary)

Constructors

Properties

collectionName: string
connector: MongoConnector

Methods

  • Creates a new record in the collection associated with this instance.

    Parameters

    • data: User

      The data to be stored in the collection.

    • OptionalskipSanitization: boolean = false

      Indicates whether to skip sanitization of the data before returning it.

    Returns Promise<User>

    A promise that resolves to the created and optionally sanitized record.

  • Deletes an item from the collection identified by the given ID.

    Parameters

    • id: string | number

      The unique identifier of the item to be deleted. Can be a number or a string.

    Returns Promise<boolean>

    A promise that resolves to true if the deletion was successful, or false otherwise.

  • Fetches all data entries from the collection that match the given query. Allows optional skipping of data sanitization.

    Parameters

    • query: string

      The query string used to match entries in the collection.

    • bindings: any[]

      An array of bindings to parameterize the query.

    • OptionalskipSanitization: boolean = false

      Determines whether to skip sanitization of the results.

    Returns Promise<User[]>

    A promise that resolves to an array of matching entries.

  • Finds a single record from the collection based on the provided query and bindings.

    Parameters

    • query: string

      The query string used to locate the record in the collection.

    • bindings: any[]

      An array of bindings to parameterize the query.

    • OptionalskipSanitization: boolean = false

      If true, skips sanitization of the returned data.

    Returns Promise<User>

    A promise that resolves to the found record. If no record is found, the promise resolves to undefined.

  • Retrieves all items from the collection and optionally applies sanitization.

    Parameters

    • OptionalskipSanitization: boolean = false

      If true, sanitization will be skipped; otherwise, all items will be sanitized.

    Returns Promise<User[]>

    A promise that resolves to an array of items, optionally sanitized.

  • Retrieves an entity by its unique identifier.

    Parameters

    • id: string | number

      The unique identifier of the entity to retrieve.

    • OptionalskipSanitization: boolean = false

      If true, skips the sanitization of the retrieved data.

    Returns Promise<User>

    A promise that resolves to the retrieved entity.

  • Performs cleanup and de-initialization tasks when the component or service is being destroyed. Typically used to unsubscribe from observables, detach event listeners, or release resources to prevent memory leaks.

    Returns void

    No return value.

  • Updates a record in the specified collection and optionally skips data sanitization.

    Parameters

    • data: User

      The data to be updated in the collection.

    • OptionalskipSanitization: boolean = false

      Whether to skip sanitization of the returned data.

    Returns Promise<User>

    A promise that resolves to the updated record, either sanitized or unsanitized based on the value of skipSanitization.

  • Updates multiple entries in the database collection and optionally sanitizes the updated data.

    Parameters

    • data: User[]

      The array of data objects to be updated in the collection.

    • OptionalskipSanitization: boolean = false

      A flag to determine whether sanitization of updated objects should be skipped. Defaults to false.

    Returns Promise<User[]>

    • A promise that resolves to an array of updated (and optionally sanitized) data objects.