From 338147f9dbaf9a30921370e7d7c2379d3464a0ee Mon Sep 17 00:00:00 2001
From: Matt Kirby <MattJKirby@outlook.com>
Date: Fri, 14 Apr 2023 23:31:52 +0100
Subject: [PATCH] Added Datastore Generic

---
 .../src/Datastores/DataStore.ts               | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 backend-services/friend-service/src/Datastores/DataStore.ts

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 00000000..63cf51dd
--- /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
-- 
GitLab