You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseRepository.ts 985B

12345678910111213141516171819202122232425262728
  1. import { IWrite } from './IWrite';
  2. import { IRead } from './IRead';
  3. import { MongoClient, Db, Collection, InsertOneWriteOpResult } from 'mongodb';
  4. export abstract class BaseRepository<T> implements IWrite<T>, IRead<T>{
  5. public readonly _collection: Collection;
  6. constructor(db: Db, collectionName: string) {
  7. this._collection = db.collection(collectionName);
  8. }
  9. async create(item: T): Promise<boolean> {
  10. const result: InsertOneWriteOpResult = await this._collection.insert(item);
  11. return !!result.result.ok;
  12. }
  13. update(id: string, item: T): Promise<boolean> {
  14. throw new Error('Method not implemented.');
  15. }
  16. delete(id: string): Promise<boolean> {
  17. throw new Error('Method not implemented.');
  18. }
  19. find(item: T): Promise<T[]> {
  20. throw new Error('Method not implemented.');
  21. }
  22. findOne(id: string): Promise<T> {
  23. throw new Error('Method not implemented.');
  24. }
  25. }