152 lines
5.0 KiB
JavaScript
152 lines
5.0 KiB
JavaScript
class ApplicantOrganisationModel extends EICModel {
|
|
|
|
constructor(privileges) {
|
|
super('/organisations/{pic}', privileges);
|
|
}
|
|
|
|
search(pic) {
|
|
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('search');
|
|
let uri = endpoint.uri
|
|
|
|
return (
|
|
this.request(uri, endpoint.method, {'search': pic })
|
|
.then( async serverData => this.loadData(serverData.payload))
|
|
)
|
|
}
|
|
|
|
list() {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('list');
|
|
let uri = endpoint.uri
|
|
|
|
return ( this.request(uri, endpoint.method, payload) );
|
|
}
|
|
|
|
read(pic) {
|
|
if(!this.hasPrivilege('read')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('read');
|
|
let uri = endpoint.uri.replace('{pic}', pic);
|
|
|
|
return (
|
|
this.request(uri, endpoint.method)
|
|
.then( async serverData => { return serverData.payload })
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
app.registerClass('ApplicantOrganisationModel', ApplicantOrganisationModel);
|
|
|
|
|
|
class ApplicantOrganisationProposalsModel extends EICModel {
|
|
|
|
constructor(privileges) {
|
|
super('/organisations/{pic}/proposals', privileges);
|
|
}
|
|
|
|
sanitize(list) {
|
|
for(let item of list) {
|
|
if(['created', 'updated'].includes(item.status)) item.status = 'draft';
|
|
if(['evaluation-finalised'].includes(item.status)) item.status = 'evaluated';
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
list(pic) {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('list');
|
|
let uri = endpoint.uri.replace('{pic}', pic);
|
|
|
|
return (
|
|
this.request(uri, endpoint.method)
|
|
.then( async serverData => { return this.sanitize(serverData.payload) })
|
|
);
|
|
}
|
|
|
|
search(pic, query) {
|
|
if(!this.hasPrivilege('search')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('search');
|
|
let uri = endpoint.uri.replace('{pic}', pic);
|
|
|
|
return (
|
|
this.request(uri, endpoint.method, query)
|
|
.then( async serverData => { return this.sanitize(serverData.payload) })
|
|
)
|
|
}
|
|
|
|
create(pic) {
|
|
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('create');
|
|
let uri = endpoint.uri.replace('{pic}', pic);
|
|
|
|
return (
|
|
this.request(uri, endpoint.method)
|
|
.then( async serverData => { return serverData.payload })
|
|
)
|
|
}
|
|
|
|
apply(pic, pid, uid) {
|
|
if(!this.hasPrivilege('apply')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('apply');
|
|
let uri = endpoint.uri.replace('{pic}', pic).replace('{pid}', pid).replace('{uid}', uid);
|
|
//TODO NIKE : should get it via app.Route.makelink() but that one seems outdated, doesn't work as expected on complex cases.
|
|
// => it only searches in routes known (loaded) at time of call, not into the whole tree of possible routes
|
|
// (which would be to crazy to recursively build... ) => refactor makelink & come back here ! GREP for proposalLink & organisationLink in models
|
|
let proposalLink = '/organisations/{pic}/proposals/{pid}'.replace('{pic}',pic).replace('{pid}',pid)
|
|
return (
|
|
this.request(uri, endpoint.method, { status: 'pending', proposalLink: proposalLink})
|
|
.then( async serverData => { return serverData.payload })
|
|
)
|
|
}
|
|
}
|
|
|
|
app.registerClass('ApplicantOrganisationProposalsModel', ApplicantOrganisationProposalsModel);
|
|
|
|
class ApplicantOrganisationCoachingsModel extends EICModel {
|
|
|
|
constructor(privileges) {
|
|
super('/organisations/{pic}/coachings', privileges);
|
|
}
|
|
|
|
sanitize(list) {
|
|
for(let item of list) {
|
|
if(['created', 'updated'].includes(item.status)) item.status = 'draft';
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
list(pic) {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('list');
|
|
let uri = endpoint.uri.replace('{pic}', pic);
|
|
|
|
return (
|
|
this.request(uri, endpoint.method)
|
|
.then( async serverData => { return this.sanitize(serverData.payload) })
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Opens a specific coaching. Currently sending user to SMED mycoachings (id is no use right now either)
|
|
* @param {*} id
|
|
*/
|
|
read(id) {
|
|
let endpoint = this.getApiEndpoint('read');
|
|
|
|
window.open(endpoint.uri, '_blank');
|
|
}
|
|
}
|
|
|
|
app.registerClass('ApplicantOrganisationCoachingsModel', ApplicantOrganisationCoachingsModel);
|