diff --git a/ExpressAPI/src/models/Enonce.ts b/ExpressAPI/src/models/Enonce.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ae10f94ee632c3485b22bda28aa085dec0f1046 --- /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 0000000000000000000000000000000000000000..96740813109612c7e8a0ef1a788e56b1acdc39fd --- /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;