Interface CrudControllerInterface<T, CreateData, UpdateData>

Interface for a CRUD (create, read, update, delete) controller.

interface CrudControllerInterface<
    T extends BaseEntity,
    CreateData extends DeepPartial<T> = DeepPartial<T>,
    UpdateData extends DeepPartial<T> = DeepPartial<T>,
> {
    create: (data: CreateData) => Promise<T>;
    deleteById: (id: T["id"]) => Promise<void>;
    findAll: (page: number, limit: number) => Promise<PaginationResult<T>>;
    findById: (id: T["id"]) => Promise<T>;
    updateById: (id: T["id"], data: UpdateData) => Promise<T>;
}

Type Parameters

Properties

create: (data: CreateData) => Promise<T>

Creates a new entity with the given data.

deleteById: (id: T["id"]) => Promise<void>

Deletes the entity with the given id.

findAll: (page: number, limit: number) => Promise<PaginationResult<T>>

Gets paginated data from the given page.

findById: (id: T["id"]) => Promise<T>

Finds an entity with the given id.

updateById: (id: T["id"], data: UpdateData) => Promise<T>

Updates the entity with the given id by the given data.