unclean SPARC
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
class ApplicantMembersModel extends EICModel {
|
||||
|
||||
members = [];
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations/{pic}/members', privileges);
|
||||
}
|
||||
|
||||
list(pic) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
this.members = [];
|
||||
|
||||
let endpoint = this.getApiEndpoint('list');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method)
|
||||
.then( async serverData => {
|
||||
this.members = serverData.payload;
|
||||
return this.members;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
read(pic, uid) {
|
||||
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
//let endpoint = this.getApiEndpoint('list');
|
||||
//let uri = endpoint.uri.replace('{pic}', pic) + '/' + uid;
|
||||
|
||||
return (new Promise((resolve) => resolve(this.members.find(member => member.uid == uid))))
|
||||
|
||||
/*
|
||||
return (
|
||||
|
||||
//this.request(uri, endpoint.method)
|
||||
//.then( async serverData => { return serverData.payload })
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
search(hint) {
|
||||
if(!this.hasPrivilege('add')) return( new Promise((resolve, reject) => reject()))
|
||||
let endpoint = this.getApiEndpoint('search');
|
||||
let uri = endpoint.uri;
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, {'hint': hint })
|
||||
.then( async serverData => {
|
||||
let users = serverData.payload.map(x=> { // Cleanup keys starting with https://
|
||||
for(let k in x){
|
||||
if(k.substring(0,4)=='http') { x[k.substring(k.lastIndexOf('/')+1)]=x[k]; delete(x[k]);}
|
||||
} return(x);
|
||||
} )
|
||||
return(users);
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
update(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('update');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
add(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('add')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('add');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
payload.status = 'active';
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
grant(pic, uid, payload) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('grant');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let organisationLink = '/applicant/{pic}'.replace('{pic}',pic)
|
||||
payload.organisationLink = organisationLink
|
||||
payload.status = 'active';
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
|
||||
revoke(pic, uid) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{pic}', pic).replace('{uid}', uid);
|
||||
let payload = {
|
||||
organisationLink: '/applicant/{pic}'.replace('{pic}',pic),
|
||||
status: 'deleted'
|
||||
}
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload)
|
||||
.then( async serverData => { return serverData.payload; })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantMembersModel', ApplicantMembersModel);
|
||||
@@ -0,0 +1,151 @@
|
||||
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);
|
||||
@@ -0,0 +1,43 @@
|
||||
class ApplicantOrganisationsModel extends EICPluralModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('/organisations', privileges);
|
||||
this.singletonClass = class {
|
||||
itemData = {
|
||||
pic: null,
|
||||
legalname: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
search(criteria) { // search onlegalname can bring several
|
||||
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': criteria })
|
||||
.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)
|
||||
.then( async serverData => {
|
||||
const payload = serverData.payload;
|
||||
//this.fill(payload);
|
||||
|
||||
return payload;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
app.registerClass('ApplicantOrganisationsModel', ApplicantOrganisationsModel);
|
||||
@@ -0,0 +1,51 @@
|
||||
class BypassCompanyModel extends EICModel {
|
||||
|
||||
constructor(privileges) {
|
||||
super('company', privileges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for a company based on its PIC and retrieves its information and the allocated token if applies
|
||||
* @param {*} endpoint
|
||||
* @param {*} payload
|
||||
* @returns
|
||||
*/
|
||||
search(pic) {
|
||||
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)
|
||||
.then( async serverData => this.loadData(serverData.payload))
|
||||
)
|
||||
}
|
||||
|
||||
grant(pic, payload) {
|
||||
if(!this.hasPrivilege('grant')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('grant');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return (
|
||||
this.request(uri, endpoint.method, payload).then(
|
||||
(reply) => { // Now that we have a token, populate company model with it (was null)
|
||||
this.itemData.token = reply.payload.token
|
||||
return(reply)
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
revoke(pic, payload) {
|
||||
if(!this.hasPrivilege('revoke')) return( new Promise((resolve, reject) => reject()))
|
||||
|
||||
let endpoint = this.getApiEndpoint('revoke');
|
||||
let uri = endpoint.uri.replace('{pic}', pic);
|
||||
|
||||
return this.request(uri, endpoint.method, payload);
|
||||
}
|
||||
}
|
||||
|
||||
app.registerClass('BypassCompanyModel', BypassCompanyModel);
|
||||
Reference in New Issue
Block a user