Skip to content
Snippets Groups Projects
Commit 32ab162f authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Resolve "Prevent duplacated name of election"

parent 582c4f7e
No related branches found
No related tags found
No related merge requests found
......@@ -74,6 +74,16 @@ func (d *DataHandler) postElection(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var elections []Election
d.db.Find(&elections)
for _, val := range elections {
if o.Name == val.Name {
http.Error(w, "Name Already exist.", 409)
return
}
}
d.db.Create(&o)
d.db.Last(&o)
json.NewEncoder(w).Encode(o)
......
......@@ -256,6 +256,12 @@ class Election {
}),
}
);
if (response.status == 409) {
throw new Error(
`The name of the election already exist (status ${response.status})`
);
}
if (response.status !== 200) {
throw new Error(
`Election could not be updated or created (status ${response.status})`
......@@ -266,6 +272,7 @@ class Election {
} catch (e) {
Messages.Show("is-warning", e.message);
console.error(e);
return
}
Common.toggleModal("election-modal", "election-modal-card");
this.activateElection(election);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment