Created
March 1, 2021 13:56
-
-
Save Alexzanderk/cf4adc92671e0c9e34c93b8c7a33d7dd to your computer and use it in GitHub Desktop.
Revisions
-
Alexzanderk created this gist
Mar 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ type Constructor<T> = new (...args: any[]) => T; type ModelType<T extends Model<T>> = Constructor<T> & typeof Model; export interface IRepository<T extends Model> { get(id: string): Promise<T| null>; find(where: FindOptions<T>): Promise<T>; create(model: T): Promise<T>; update(key: any, model: T): Promise<T>; } export class RepositoryService<T extends Model<T>> implements IRepository<T>{ constructor(protected model: ModelType<T>) {} get(id: string): Promise<T| null> { return this.model.findByPk<T>(id); } find(where: FindOptions<T>): Promise<T> { throw new Error('Method not implemented.'); } create(model: T): Promise<T> { throw new Error('Method not implemented.'); } update(key: any, model: T): Promise<T> { throw new Error('Method not implemented.'); } }