diff --git a/backend-services/friend-service/src/Datastores/DataStore.ts b/backend-services/friend-service/src/Datastores/DataStore.ts new file mode 100644 index 0000000000000000000000000000000000000000..63cf51dd12e8b289a2418a4435c37720b29802c5 --- /dev/null +++ b/backend-services/friend-service/src/Datastores/DataStore.ts @@ -0,0 +1,25 @@ +import mongoose, { Model, Schema } from 'mongoose' + +/** + * Defines common datastore functionality + */ +export abstract class DataStore<T> { + + /** + * Mongoose model pertaining to the datastore type + */ + public Model: Model<any> + + constructor (modelName: string, schema: Schema) { + this.Model = mongoose.model(modelName, schema) + } + + /** + * Finds a single item matching a given query + * @param query + * @returns + */ + public GetItem = async (query: any): Promise<T | null> => { + return await this.Model.findOne(query) + } +} \ No newline at end of file