Skip to content

Commit

Permalink
Fixing bugs on Rooms and Articles Views
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicra committed Aug 10, 2018
1 parent 750cc23 commit 3e56536
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 374 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
logs/
Binary file modified app/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/controllers/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function editArticle(request, h)
if(request.payload.name != article[0].name)
{
const articleExists = await articleService.getArticleByName(request.payload.name);
if(articleExists.length > 0)
if(articleExists.length > 0 && articleExists.name == request.payload.name)
{
stResponse.message = "Article name is already in use.";
resolve(stResponse);
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function renderView(request,h)
resolve(h.view('views/rooms/view', {
room:room[0],
session: request.auth.credentials,
articles: await articleService.getArticlesByRoomId(request.query.id)
articles: await articleService.getArticlesByRoomId(request.query.id),
hasArticles: await roomService.hasArticles(request.query.id)
}));
});
}
Expand Down
6 changes: 3 additions & 3 deletions app/models/DAO/articleDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ async function getArticleByName(name)
{
const SQL =
`SELECT * FROM Articles
WHERE UPPER(name) = ?`;
return await fw.db.execute('local',SQL,[`${name.toUpperCase()}`]);
WHERE name = ?`;
return await fw.db.execute('local',SQL,[name]);
}

async function getArticleById(id)
Expand Down Expand Up @@ -92,7 +92,7 @@ async function deleteArticle(id)
const deleteRoomArticlesSQL =
`DELETE FROM Rooms_Articles
WHERE article_id = ?`;
return await fw.db.execute('local',deleteRoomArticlesSQL,[id]);
await fw.db.execute('local',deleteRoomArticlesSQL,[id]);

const deleteArticleSQL =
`DELETE FROM Articles
Expand Down
12 changes: 11 additions & 1 deletion app/models/DAO/roomDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ async function deleteRoom(id)
return;
}

async function hasArticles(id)
{
const SQL =
`SELECT *
FROM Rooms_Articles
WHERE room_id = ?`;
var response = await fw.db.execute('local',SQL,[id]);
return (response.length) ? true : false;
}

module.exports =
{
Expand All @@ -130,5 +139,6 @@ module.exports =
getRoom,
addRoom,
updateRoom,
deleteRoom
deleteRoom,
hasArticles
}
4 changes: 2 additions & 2 deletions app/models/services/articleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ async function getArticles()
return await articleDAO.getArticles();
}

async function getArticleByName(email)
async function getArticleByName(name)
{
return await articleDAO.getArticleByName(email);
return await articleDAO.getArticleByName(name);
}

async function getArticleById(id)
Expand Down
8 changes: 7 additions & 1 deletion app/models/services/roomService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ async function deleteRoom(data)
return await roomDAO.deleteRoom(data);
}

async function hasArticles(data)
{
return await roomDAO.hasArticles(data);
}

module.exports =
{
getRooms,
getRoom,
getRoomByName,
addRoom,
updateRoom,
deleteRoom
deleteRoom,
hasArticles
}
1 change: 0 additions & 1 deletion app/templates/views/articles/add.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function submitform()
var formData = serializeObject(frm);
showLoader();
console.log(formData);
$.post('/articles/add',formData,
function(data)
{
Expand Down
22 changes: 12 additions & 10 deletions app/templates/views/rooms/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,25 @@
<input type="text" class="form-control" value="{{room.people_count}}" readonly>
</div>
<hr>
{{#ifCond articles.length ">" 0}}
{{#ifCond hasArticles "==" true}}
<h5 class="card-title">Room Equipment</h5>
{{/ifCond}}
{{#ifCond articles.length "==" 0}}
{{#ifCond hasArticles "==" false}}
<div class="form-group">
<label for="formGroupExampleInput">No equipment available for this room.</label>
</div>
{{/ifCond}}
{{#each articles}}
<ul>
<li>
<div class="form-group">
<label for="formGroupExampleInput">{{amount}} {{name}} item(s)</label>
</div>
</li>
</ul>
{{/each}}
{{#ifCond amount ">" 0}}
<ul>
<li>
<div class="form-group">
<label for="formGroupExampleInput">{{amount}} {{name}} item(s)</label>
</div>
</li>
</ul>
{{/ifCond}}
{{/each}}
</form>
</p>
<a href="/rooms/edit?id={{room.id}}" class="btn btn-primary"><span data-feather="edit"></span> Edit</a>
Expand Down
Empty file removed logs/debug.log
Empty file.
95 changes: 0 additions & 95 deletions logs/errors.log

This file was deleted.

100 changes: 0 additions & 100 deletions logs/node-out.log

This file was deleted.

159 changes: 0 additions & 159 deletions logs/requests.log

This file was deleted.

Binary file added sessions/.DS_Store
Binary file not shown.

0 comments on commit 3e56536

Please sign in to comment.