Commit bfab0be2 authored by Laura Fuentes Grau's avatar Laura Fuentes Grau
Browse files

wip #210 added query parameter 'param'

parent b801a509
...@@ -73,6 +73,7 @@ class RestAPI { ...@@ -73,6 +73,7 @@ class RestAPI {
} }
post(url, body, token) { post(url, body, token) {
console.log(url);
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
var req = request.post(url).send(body).timeout({ response: 5000 }); // Simple response start timeout (3s) var req = request.post(url).send(body).timeout({ response: 5000 }); // Simple response start timeout (3s)
......
...@@ -52,7 +52,7 @@ class RestDataManager { ...@@ -52,7 +52,7 @@ class RestDataManager {
return object; return object;
} }
load(id, token = null) { load(id, token = null,param = null) {
if (id != null) { if (id != null) {
// load single object // load single object
RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => { RestAPI.get(this.makeURL(this.url + '/' + id), token).then(response => {
...@@ -96,54 +96,102 @@ class RestDataManager { ...@@ -96,54 +96,102 @@ class RestDataManager {
} }
} }
add(object, token = null) { add(object, token = null, param = null) {
var obj = {}; var obj = {};
obj[this.type] = this.filterKeys(object); obj[this.type] = this.filterKeys(object);
RestAPI.post(this.makeURL(this.url), obj, token).then(response => { if (param === null) {
AppDispatcher.dispatch({ RestAPI.post(this.makeURL(this.url), obj, token).then(response => {
type: this.type + 's/added', AppDispatcher.dispatch({
data: response[this.type] type: this.type + 's/added',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/add-error',
error: error
});
}); });
}).catch(error => { }
AppDispatcher.dispatch({ else{
type: this.type + 's/add-error', console.log("else was called in add");
error: error RestAPI.post(this.makeURL(this.url) + "?" + param, obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/added',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/add-error',
error: error
});
}); });
}); }
} }
remove(object, token = null) { remove(object, token = null, param = null) {
RestAPI.delete(this.makeURL(this.url + '/' + object.id), token).then(response => { if (param === null) {
AppDispatcher.dispatch({ RestAPI.delete(this.makeURL(this.url + '/' + object.id), token).then(response => {
type: this.type + 's/removed', AppDispatcher.dispatch({
data: response[this.type], type: this.type + 's/removed',
original: object data: response[this.type],
original: object
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/remove-error',
error: error
});
}); });
}).catch(error => { }
AppDispatcher.dispatch({ else{
type: this.type + 's/remove-error', RestAPI.delete(this.makeURL(this.url + '/' + object.id + '?' + param), token).then(response => {
error: error AppDispatcher.dispatch({
type: this.type + 's/removed',
data: response[this.type],
original: object
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/remove-error',
error: error
});
}); });
}); }
} }
update(object, token = null) { update(object, token = null, param = null) {
var obj = {}; var obj = {};
obj[this.type] = this.filterKeys(object); obj[this.type] = this.filterKeys(object);
RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token).then(response => { if(param === null) {
AppDispatcher.dispatch({ RestAPI.put(this.makeURL(this.url + '/' + object.id), obj, token).then(response => {
type: this.type + 's/edited', AppDispatcher.dispatch({
data: response[this.type] type: this.type + 's/edited',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/edit-error',
error: error
});
}); });
}).catch(error => { }
AppDispatcher.dispatch({ else{
type: this.type + 's/edit-error', RestAPI.put(this.makeURL(this.url + '/' + object.id + '?' + param), obj, token).then(response => {
error: error AppDispatcher.dispatch({
type: this.type + 's/edited',
data: response[this.type]
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/edit-error',
error: error
});
}); });
}); }
} }
}; };
export default RestDataManager; export default RestDataManager;
...@@ -121,8 +121,8 @@ class EditUserDialog extends React.Component { ...@@ -121,8 +121,8 @@ class EditUserDialog extends React.Component {
<FormControl type="text" placeholder="Enter e-mail" value={this.state.mail} onChange={(e) => this.handleChange(e)} /> <FormControl type="text" placeholder="Enter e-mail" value={this.state.mail} onChange={(e) => this.handleChange(e)} />
</FormGroup> </FormGroup>
<FormGroup as={Col} controlId="oldPassword"> <FormGroup as={Col} controlId="oldPassword">
<FormLabel>Old Password</FormLabel> <FormLabel>Admin Password</FormLabel>
<FormControl type="password" placeholder="Enter current password" value={this.state.oldPassword} onChange={(e) => this.handleChange(e)} /> <FormControl type="password" placeholder="Enter admin password" value={this.state.oldPassword} onChange={(e) => this.handleChange(e)} />
</FormGroup> </FormGroup>
<FormGroup as={Col} controlId="password"> <FormGroup as={Col} controlId="password">
<FormLabel>Password</FormLabel> <FormLabel>Password</FormLabel>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment