120 lines
3.8 KiB
JavaScript
120 lines
3.8 KiB
JavaScript
class SoeModel extends EICModel {
|
|
|
|
latestProject = null;
|
|
|
|
constructor(privileges) {
|
|
super('/soe', privileges);
|
|
}
|
|
|
|
list() {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('list');
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
|
|
members() {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('members');
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
|
|
fundings(companyId, projectId) {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('project');
|
|
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
|
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method)
|
|
.then( async serverData => {
|
|
this.latestProject = serverData.payload;
|
|
return this.latestProject;
|
|
})
|
|
)
|
|
}
|
|
|
|
getFeedback(id) {
|
|
return this.latestProject ? this.latestProject.fundings.find(item => item.id == id) : null;
|
|
}
|
|
|
|
item(companyId, projectId, fundingId) {
|
|
if(!this.hasPrivilege('list')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('read');
|
|
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
|
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
|
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
|
|
create(companyId, projectId, payload) {
|
|
if(!this.hasPrivilege('create')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('create');
|
|
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
|
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method, payload)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
|
|
update(companyId, projectId, fundingId, payload) {
|
|
if(!this.hasPrivilege('update')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('update');
|
|
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
|
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
|
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method, payload)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
|
|
delete(companyId, projectId, fundingId) {
|
|
if(!this.hasPrivilege('delete')) return( new Promise((resolve, reject) => reject()))
|
|
|
|
let endpoint = this.getApiEndpoint('delete');
|
|
endpoint.uri = endpoint.uri.replace('{pic}', companyId);
|
|
endpoint.uri = endpoint.uri.replace('{projectId}', projectId);
|
|
endpoint.uri = endpoint.uri.replace('{fundingId}', fundingId);
|
|
|
|
return (
|
|
this.request(endpoint.uri, endpoint.method)
|
|
.then( async serverData => {
|
|
return serverData.payload;
|
|
})
|
|
)
|
|
}
|
|
}
|
|
|
|
app.registerClass('SoeModel', SoeModel);
|