Skip to content
Snippets Groups Projects
Commit 33242331 authored by michael.minelli's avatar michael.minelli
Browse files

Enonce => Modify the json values management

parent 70065774
Branches
Tags
No related merge requests found
......@@ -16,7 +16,12 @@ class EnonceManager {
}
createObjectFromRawSql(raw: any): Enonce {
return Enonce.createFromSql(raw);
const enonce = Enonce.createFromSql(raw);
enonce.enonceGitlabCreationInfo = raw.enonceGitlabCreationInfo;
enonce.enonceGitlabLastInfo = raw.enonceGitlabLastInfo;
return enonce;
}
async getByName(name: string): Promise<Enonce | undefined> {
......
import Model from './Model';
import db from '../helpers/DatabaseHelper';
import GitlabRepository from '../shared/types/Gitlab/GitlabRepository';
import LazyVal from '../shared/helpers/LazyVal';
import UserManager from '../managers/UserManager';
import User from './User';
class Enonce extends Model {
......@@ -8,17 +12,47 @@ class Enonce extends Model {
enonceName: string = '';
enonceGitlabId: number = null;
enonceGitlabLink: string = '';
enonceGitlabCreationInfo: string = '';
enonceGitlabLastInfo: string = '';
private _enonceGitlabCreationInfo: string = '{}';
private _enonceGitlabLastInfo: string = '{}';
enonceGitlabLastInfoTs: number = null;
get enonceGitlabCreationInfo(): GitlabRepository {
return JSON.parse(this._enonceGitlabCreationInfo);
}
set enonceGitlabCreationInfo(value: any) {
if ( typeof value === 'string' ) {
this._enonceGitlabCreationInfo = value;
return;
}
this._enonceGitlabCreationInfo = JSON.stringify(value);
}
get enonceGitlabLastInfo(): GitlabRepository {
return JSON.parse(this._enonceGitlabLastInfo);
}
set enonceGitlabLastInfo(value: any) {
if ( typeof value === 'string' ) {
this._enonceGitlabLastInfo = value;
return;
}
this._enonceGitlabLastInfo = JSON.stringify(value);
}
staff = new LazyVal<Array<User>>(() => {
return UserManager.getStaffOfEnonce(this.enonceName);
});
public async toJsonObject(): Promise<Object> {
const result = {
'name' : this.enonceName,
'gitlabId' : this.enonceGitlabId,
'gitlabLink' : this.enonceGitlabLink,
'gitlabCreationInfo': JSON.parse(this.enonceGitlabCreationInfo),
'gitlabLastInfo' : JSON.parse(this.enonceGitlabLastInfo),
'gitlabCreationInfo': this.enonceGitlabCreationInfo,
'gitlabLastInfo' : this.enonceGitlabLastInfo,
'gitlabLastInfoTs' : this.enonceGitlabLastInfoTs
};
......@@ -39,8 +73,8 @@ class Enonce extends Model {
enonceName : this.enonceName,
enonceGitlabId : this.enonceGitlabId,
enonceGitlabLink : this.enonceGitlabLink,
enonceGitlabCreationInfo: this.enonceGitlabCreationInfo,
enonceGitlabLastInfo : this.enonceGitlabLastInfo,
enonceGitlabCreationInfo: this._enonceGitlabCreationInfo,
enonceGitlabLastInfo : this._enonceGitlabLastInfo,
enonceGitlabLastInfoTs : this.enonceGitlabLastInfoTs
};
}
......
......@@ -20,6 +20,7 @@ import EnonceStaff from '../models/EnonceStaff';
import { AxiosError } from 'axios';
import logger from '../shared/logging/WinstonLogger';
import DojoValidators from '../helpers/DojoValidators';
import EnonceManager from '../managers/EnonceManager';
class EnonceRoutes implements RoutesManager {
......@@ -90,7 +91,7 @@ class EnonceRoutes implements RoutesManager {
}
}));
const enonce: Enonce = await Enonce.createFromSql({
const enonce: Enonce = await EnonceManager.createObjectFromRawSql({
enonceName : repository.name,
enonceGitlabId : repository.id,
enonceGitlabLink : repository.web_url,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment