Skip to content
Snippets Groups Projects
Select Git revision
  • 8f87568edb45cae354d840f0304fea770c41f0d7
  • main default protected
  • jw_sonar
  • v6.0.0 protected
  • bedran_exercise-list
  • ask-user-to-delete-exercises-on-duplicates
  • update-dependencies
  • jw_sonar_backup
  • add_route_assignments
  • 6.0.0-dev
  • 5.0.1
  • 5.0.0
  • 4.1.0
  • 4.0.0
  • 3.5.3
  • 3.5.2
  • 3.5.1
  • 3.5.0
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.3
  • 3.1.2
  • 3.1.1
  • 3.1.0
  • 3.0.1
  • 3.0.0
29 results

Exercice.ts

Blame
  • Exercice.ts 3.32 KiB
    import Model            from './Model';
    import db               from '../helpers/DatabaseHelper';
    import GitlabRepository from '../shared/types/Gitlab/GitlabRepository';
    
    
    class Exercice extends Model {
        static tableName: string = 'Exercice';
    
        exerciceId: string = '';
        exerciceEnonceName: string = '';
        exerciceName: string = '';
        exerciceGitlabId: number = null;
        exerciceGitlabLink: string = '';
        private _exerciceGitlabCreationInfo: string = '{}';
        private _exerciceGitlabLastInfo: string = '{}';
        exerciceGitlabLastInfoTs: number = null;
    
        get exerciceGitlabCreationInfo(): GitlabRepository {
            return JSON.parse(this._exerciceGitlabCreationInfo);
        }
    
        set exerciceGitlabCreationInfo(value: any) {
            if ( typeof value === 'string' ) {
                this._exerciceGitlabCreationInfo = value;
                return;
            }
    
            this._exerciceGitlabCreationInfo = JSON.stringify(value);
        }
    
        get exerciceGitlabLastInfo(): GitlabRepository {
            return JSON.parse(this._exerciceGitlabLastInfo);
        }
    
        set exerciceGitlabLastInfo(value: any) {
            if ( typeof value === 'string' ) {
                this._exerciceGitlabLastInfo = value;
                return;
            }
    
            this._exerciceGitlabLastInfo = JSON.stringify(value);
        }
    
        public async toJsonObject(): Promise<Object> {
            const result = {
                'id'                : this.exerciceId,
                'enonceName'        : this.exerciceEnonceName,
                'name'              : this.exerciceName,
                'gitlabId'          : this.exerciceGitlabId,
                'gitlabLink'        : this.exerciceGitlabLink,
                'gitlabCreationInfo': this.exerciceGitlabCreationInfo,
                'gitlabLastInfo'    : this.exerciceGitlabLastInfo,
                'gitlabLastInfoTs'  : this.exerciceGitlabLastInfoTs
            };
    
            return result;
        };
    
        public importFromJsonObject(jsonObject: any) {
            this.exerciceId = jsonObject.id;
            this.exerciceEnonceName = jsonObject.enonceName;
            this.exerciceName = jsonObject.name;
            this.exerciceGitlabId = jsonObject.gitlabId;
            this.exerciceGitlabLink = jsonObject.gitlabLink;
            this.exerciceGitlabCreationInfo = jsonObject.gitlabCreationInfo;
            this.exerciceGitlabLastInfo = jsonObject.gitlabLastInfo;
            this.exerciceGitlabLastInfoTs = jsonObject.gitlabLastInfoTs;
        }
    
        public toDb(): any {
            return {
                exerciceId                : this.exerciceId,
                exerciceEnonceName        : this.exerciceEnonceName,
                exerciceName              : this.exerciceName,
                exerciceGitlabId          : this.exerciceGitlabId,
                exerciceGitlabLink        : this.exerciceGitlabLink,
                exerciceGitlabCreationInfo: this._exerciceGitlabCreationInfo,
                exerciceGitlabLastInfo    : this._exerciceGitlabLastInfo,
                exerciceGitlabLastInfoTs  : this.exerciceGitlabLastInfoTs
            };
        }
    
        async create(): Promise<Exercice> {
            await db(Exercice.tableName).insert(this.toDb());
            return this;
        }
    
        update(): Promise<void> {
            return db(Exercice.tableName).where('exerciceId', this.exerciceId).update(this.toDb());
        }
    
        del(): Promise<void> {
            return db(Exercice.tableName).where('exerciceId', this.exerciceId).del();
        }
    }
    
    
    export default Exercice;