Function: Consume()

function Consume<T>(modelClass: Constructor<T>): <This, Args, Return>(originalMethod: (this: This, ...args: Args) => Promise<Return>, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>) => (this: This, ...args: Args) => Promise<any>;

Defined in: src/data-management/decorators/consume.ts:65

Type Parameters

Type Parameter
T

Parameters

Parameter Type Description
modelClass Constructor<T> La clase del modelo (ej: User, Article)

Returns

<This, Args, Return>(originalMethod: (this: This, ...args: Args) => Promise<Return>, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Promise<Return>>): (this: This, ...args: Args) => Promise<any>;

Type Parameters

Type Parameter
This extends object
Args extends any[]
Return

Parameters

Parameter Type
originalMethod (this: This, …args: Args) => Promise<Return>
context ClassMethodDecoratorContext<This, (this: This, …args: Args) => Promise<Return>>

Returns

(this: This, ...args: Args): Promise<any>;

Parameters

Parameter Type
this This
args Args

Returns

Promise<any>

Consume

Example

Service

class UserRepository { @Consume(User) async findAll() { const response = await fetch(’/api/users’); return await response.json(); }

@Consume(User) async findById(id: string) { const response = await fetch(/api/users/${id}); return await response.json(); } }

// Uso: const users = await repo.findAll(); // users es User[], no JSON // users ya están en el Store users[0].changeName(‘New Name’); // Métodos de dominio funcionan