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);
|
||||
Reference in New Issue
Block a user