UNPKG

@tmlmobilidade/interfaces

Version:

This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.

101 lines (100 loc) 4.41 kB
import { MongoCollectionClass } from '../../mongo-collection.js'; import { CreateUserDto, UpdateUserDto, User } from '@tmlmobilidade/types'; import { Filter, FindOptions, IndexDescription, Sort, WithId } from 'mongodb'; import { z } from 'zod'; type NewType = string; declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, UpdateUserDto> { private static _instance; protected createSchema: z.ZodSchema; protected updateSchema: z.ZodSchema; private constructor(); static getInstance(): Promise<UsersClass>; /** * Finds a user document by its email. * * @param email - The email of the user to find * @param includePasswordHash - Whether to include the password hash in the result * @returns A promise that resolves to the matching user document or null if not found */ findByEmail(email: string, includePasswordHash?: boolean): Promise<null | WithId<User>>; /** * Finds a document by its ID. * * @param id - The ID of the document to find * @param includePasswordHash - Whether to include the password hash in the result * @returns A promise that resolves to the matching document or null if not found */ findById(id: string, options?: FindOptions<User>, includePasswordHash?: boolean): Promise<User | null>; /** * Finds users by their organization code * * @param code - The code of the organization to find users for * @param includePasswordHash - Whether to include the password hash in the result * @returns A promise that resolves to the matching user documents or null if not found */ findByOrganization(id: NewType, includePasswordHash?: boolean): Promise<{ created_at: import("@tmlmobilidade/types").UnixTimestamp; updated_at: import("@tmlmobilidade/types").UnixTimestamp; email: string; phone?: string | null | undefined | undefined; permissions: { scope: string; action: string; resource?: Record<string, any> | null | undefined; }[]; email_verified?: (null | import("@tmlmobilidade/types").UnixTimestamp) | undefined; first_name: string; last_name: string; organization_ids: string[]; role_ids: string[]; session_ids: string[]; verification_token_ids: string[]; avatar?: string | null | undefined | undefined; bio?: string | null | undefined | undefined; _id: string; }[]>; /** * Finds a user by their role * * @param role - The role of the user to find * @returns A promise that resolves to the matching user document or null if not found */ findByRole(role: string, includePasswordHash?: boolean): Promise<{ created_at: import("@tmlmobilidade/types").UnixTimestamp; updated_at: import("@tmlmobilidade/types").UnixTimestamp; email: string; phone?: string | null | undefined | undefined; permissions: { scope: string; action: string; resource?: Record<string, any> | null | undefined; }[]; email_verified?: (null | import("@tmlmobilidade/types").UnixTimestamp) | undefined; first_name: string; last_name: string; organization_ids: string[]; role_ids: string[]; session_ids: string[]; verification_token_ids: string[]; avatar?: string | null | undefined | undefined; bio?: string | null | undefined | undefined; _id: string; }[]>; /** * Finds multiple documents matching the filter criteria with optional pagination and sorting. * * @param filter - (Optional) filter criteria to match documents * @param perPage - (Optional) number of documents per page for pagination * @param page - (Optional) page number for pagination * @param sort - (Optional) sort specification * @returns A promise that resolves to an array of matching documents */ findMany(filter?: Filter<User>, perPage?: number, page?: number, sort?: Sort): Promise<WithId<User>[]>; findOne(filter: Filter<User>): Promise<WithId<User> | null>; protected getCollectionIndexes(): IndexDescription[]; protected getCollectionName(): string; protected getEnvName(): string; private deletePasswordHash; } export declare const users: UsersClass; export {};