Commit 6e88953c authored by Geovanny's avatar Geovanny

Participation on the front end done

parent 8ebe56c2
...@@ -210,4 +210,15 @@ model.warParticipation = async (user_id, house_id, decision) => { ...@@ -210,4 +210,15 @@ model.warParticipation = async (user_id, house_id, decision) => {
await db.con.query('COMMIT;'); await db.con.query('COMMIT;');
} }
model.getParticipation = async (house_id) => {
const sql_text = `SELECT u.username, uw.decision
FROM users as u
LEFT JOIN users_war as uw ON uw.user_id = u.id
LEFT JOIN war_days as w ON w.id = uw.war_id
WHERE uw.house_id = ? AND w.completed = 0;`;
const data = await db.con.query(sql_text, [house_id]);
return data;
}
module.exports = model; module.exports = model;
\ No newline at end of file
...@@ -315,6 +315,18 @@ authRouter.delete('/:house_id', async (context, next) => { ...@@ -315,6 +315,18 @@ authRouter.delete('/:house_id', async (context, next) => {
} }
}); });
authRouter.get('/participation', async (context, next) => {
hasHouse(context);
try{
const data = await houseModel.getParticipation(context.user.house_id);
context.response.status = 200;
context.response.body = data;
}catch(error){
console.log(error);
context.throw('Failed to get Participation');
}
});
authRouter.post('/participation', async (context, next) => { authRouter.post('/participation', async (context, next) => {
hasHouse(context); hasHouse(context);
const body = context.request.body; const body = context.request.body;
......
...@@ -45,6 +45,7 @@ class MyHouseController{ ...@@ -45,6 +45,7 @@ class MyHouseController{
} }
async refresh(){ async refresh(){
this.getParticipation();
this.getMembers(); this.getMembers();
this.getPermissionLevel(); this.getPermissionLevel();
this.getRequests(); this.getRequests();
...@@ -108,7 +109,23 @@ class MyHouseController{ ...@@ -108,7 +109,23 @@ class MyHouseController{
} }
async attempParticipate(decision){ async attempParticipate(decision){
console.log(decision) try{
await this.sync.updateParticipation(decision);
alert('Update Successfull');
this.refresh();
}catch(error){
console.log(error);
alert('Failed to Update Participaation');
}
}
async getParticipation(){
try{
const data = await this.sync.getParticipation();
this.view.drawParticipationTable(data);
}catch(error){
console.log(error);
}
} }
async getPermissionLevel(){ async getPermissionLevel(){
......
...@@ -18,7 +18,6 @@ class MemberUnitsView extends EventTarget{ ...@@ -18,7 +18,6 @@ class MemberUnitsView extends EventTarget{
} }
drawTable(data){ drawTable(data){
console.log(data)
this.table_view.drawTable(data); this.table_view.drawTable(data);
} }
......
...@@ -28,7 +28,7 @@ class ParticipationView extends EventTarget{ ...@@ -28,7 +28,7 @@ class ParticipationView extends EventTarget{
} }
drawTable(data){ drawTable(data){
this.table_view(data); this.table_view.drawTable(data);
} }
} }
......
...@@ -85,9 +85,31 @@ class Sync{ ...@@ -85,9 +85,31 @@ class Sync{
} }
const data = await response.json(); const data = await response.json();
return data;
}
async getParticipation(){
const response = await fetch('/api/house/participation');
if(!response.ok){
throw Error('Failed to get participations');
}
const data = await response.json();
return data; return data;
} }
async updateParticipation(decision){
const response = await fetch('/api/house/participation',{
method: "POST",
body: JSON.stringify({decision: decision}),
headers: {
'Content-Type': 'application/json'
}
});
if(!response.ok){
throw Error('Failed to Update Participation');
}
}
} }
export default Sync; export default Sync;
\ No newline at end of file
...@@ -37,6 +37,10 @@ class MyHouseController extends EventTarget{ ...@@ -37,6 +37,10 @@ class MyHouseController extends EventTarget{
}); });
} }
drawParticipationTable(data){
this.participation_view.drawTable(data);
}
drawMemberUnitsTable(data){ drawMemberUnitsTable(data){
this.member_units_view.drawTable(data); this.member_units_view.drawTable(data);
} }
......
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