From 6044d7d68c8f8974a715a6ab3b4efe9eb2a65fdf Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 2 Dec 2020 00:56:13 +0300 Subject: feat: add model interface --- lib/model.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/model.ts b/lib/model.ts index 77fede0..218b8ef 100644 --- a/lib/model.ts +++ b/lib/model.ts @@ -6,13 +6,18 @@ interface Event extends EventDocument { log(message: string): void; start(): void; complete(): void; - fail(): void; + fail(error: Error): void; computeNextRunAt(): Date; } +export interface EventModel extends Model> { + findNextEvents(): Event[]; + findMissedEvents(): Event[]; +} + const CronJob = cron.CronJob; -const createEventModel = (name: string, contextSchema: Context) => { +const createEventModel = (name: string, contextSchema: Context): EventModel => { const schema = createEventSchema(contextSchema); // Schema methods @@ -79,7 +84,7 @@ const createEventModel = (name: string, contextSchema: C this.nextRunAt = this.computeNextRunAt(); }); - return model>(name, schema); + return model, EventModel>(name, schema); }; -- cgit v1.2.3