From dc9e2e932ffa62ffe543d48aa20e209b54f6a838 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me>
Date: Wed, 28 Jun 2023 21:36:27 +0200
Subject: [PATCH] Models => Add enonce and enonceStaff

---
 ExpressAPI/src/models/Enonce.ts      | 66 ++++++++++++++++++++++++++++
 ExpressAPI/src/models/EnonceStaff.ts | 42 ++++++++++++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 ExpressAPI/src/models/Enonce.ts
 create mode 100644 ExpressAPI/src/models/EnonceStaff.ts

diff --git a/ExpressAPI/src/models/Enonce.ts b/ExpressAPI/src/models/Enonce.ts
new file mode 100644
index 0000000..1ae10f9
--- /dev/null
+++ b/ExpressAPI/src/models/Enonce.ts
@@ -0,0 +1,66 @@
+import Model from './Model';
+import db    from '../helpers/DatabaseHelper';
+
+
+class Enonce extends Model {
+    static tableName: string = 'Enonce';
+
+    enonceID: number = null;
+    enonceName: string = '';
+    enonceGitlabId: number = null;
+    enonceGitlabLink: string = '';
+    enonceGitlabCreationInfo: string = '';
+    enonceGitlabLastInfo: string = '';
+    enonceGitlabLastInfoTs: number = null;
+
+    public async toJsonObject(lightVersion: boolean): Promise<Object> {
+        const result = {
+            'id'                : this.enonceID,
+            'name'              : this.enonceName,
+            'gitlabId'          : this.enonceGitlabId,
+            'gitlabLink'        : this.enonceGitlabLink,
+            'gitlabCreationInfo': this.enonceGitlabCreationInfo,
+            'gitlabLastInfo'    : this.enonceGitlabLastInfo,
+            'gitlabLastInfoTs'  : this.enonceGitlabLastInfoTs
+        };
+
+        return result;
+    };
+
+    public importFromJsonObject(jsonObject: any) {
+        this.enonceID = jsonObject.id;
+        this.enonceName = jsonObject.name;
+        this.enonceGitlabId = jsonObject.gitlabId;
+        this.enonceGitlabLink = jsonObject.gitlabLink;
+        this.enonceGitlabCreationInfo = jsonObject.gitlabCreationInfo;
+        this.enonceGitlabLastInfo = jsonObject.gitlabLastInfo;
+        this.enonceGitlabLastInfoTs = jsonObject.gitlabLastInfoTs;
+    }
+
+    public toDb(): any {
+        return {
+            enonceName              : this.enonceName,
+            enonceGitlabId          : this.enonceGitlabId,
+            enonceGitlabLink        : this.enonceGitlabLink,
+            enonceGitlabCreationInfo: this.enonceGitlabCreationInfo,
+            enonceGitlabLastInfo    : this.enonceGitlabLastInfo,
+            enonceGitlabLastInfoTs  : this.enonceGitlabLastInfoTs
+        };
+    }
+
+    async create(): Promise<void> {
+        const id = await db(Enonce.tableName).insert(this.toDb());
+        this.enonceID = id[0];
+    }
+
+    update(): Promise<void> {
+        return db(Enonce.tableName).where('enonceID', this.enonceID).update(this.toDb());
+    }
+
+    del(): Promise<void> {
+        return db(Enonce.tableName).where('enonceID', this.enonceID).del();
+    }
+}
+
+
+export default Enonce;
diff --git a/ExpressAPI/src/models/EnonceStaff.ts b/ExpressAPI/src/models/EnonceStaff.ts
new file mode 100644
index 0000000..9674081
--- /dev/null
+++ b/ExpressAPI/src/models/EnonceStaff.ts
@@ -0,0 +1,42 @@
+import Model from './Model';
+import db    from '../helpers/DatabaseHelper';
+
+
+class EnonceStaff extends Model {
+    static tableName: string = 'EnonceStaff';
+
+    enonceID: number = null;
+    userID: number = null;
+
+    public async toJsonObject(lightVersion: boolean): Promise<Object> {
+        const result = {
+            'enonceID': this.enonceID,
+            'userID'  : this.userID
+        };
+
+        return result;
+    };
+
+    public importFromJsonObject(jsonObject: any) {
+        this.enonceID = jsonObject.enonceID;
+        this.userID = jsonObject.userID;
+    }
+
+    public toDb(): any {
+        return {
+            enonceID: this.enonceID,
+            userID  : this.userID
+        };
+    }
+
+    create(): Promise<void> {
+        return db(EnonceStaff.tableName).insert(this.toDb());
+    }
+
+    del(): Promise<void> {
+        return db(EnonceStaff.tableName).where('enonceID', this.enonceID).andWhere('userID', this.userID).del();
+    }
+}
+
+
+export default EnonceStaff;
-- 
GitLab