Skip to content

Commit

Permalink
User can now view summary of books borrowed by others
Browse files Browse the repository at this point in the history
  • Loading branch information
dwij2812 committed Jun 6, 2019
1 parent a65fbda commit 49334f3
Show file tree
Hide file tree
Showing 40 changed files with 270 additions and 16 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ app.use(require('express-formidable')({
}));

app.locals.blog = {
title: 'Welcome to Accord :: CheckOut'
title: 'Accord CheckOut'
};

app.use(function (req, res, next) {
Expand Down
178 changes: 178 additions & 0 deletions logs/success.log

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions models/borrowParts.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,12 @@ module.exports = {
return BorrowParts
.count({bool: false})
.exec();
},
BorrowSummary: function(){
return BorrowParts
.find({ bool:false })
.sort({ _id: -1 })
.addCreatedAt()
.exec();
}
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
47 changes: 47 additions & 0 deletions routes/borrow_summary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var express = require('express');
var router = express.Router();
var async = require('asyncawait/async');
var await = require('asyncawait/await');
var UserModel = require('../models/users');
var BorrowPartModel = require('../models/borrowParts');
var BorrowParts = require('../lib/mongo').BorrowPart;
var checkIsAdmin = require('../middlewares/check').checkIsAdmin;
var InventoryModel = require('../models/inventory');

router.get('/', async (function (req, res, next) {
var result = [];
try {
var users = await (BorrowPartModel.BorrowSummary());
users.forEach(async (function(user){
var userInfo = await (UserModel.getUserByDefaultId(user.userId));
var partInfo = await (InventoryModel.getPartById(user.partId));
result.push({
userId: user.userId,
name: userInfo.name,
id: userInfo.id,
avatar: userInfo.avatar,
borrowTime: user.created_at,
borrowId: user._id,
partId: user.partId,
returnTime: user.return_time,
bool: user.bool,
approval: user.approval,
partname: partInfo.name,
partmodel_no: partInfo.model_no,
partpic: partInfo.image
})
}));

setTimeout(function() {
res.render('borrow_summary', {
borrowUser: result
});
}, 1000);

} catch (error) {
next();
}

}));

module.exports = router;
1 change: 1 addition & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function (app) {
app.use('/quick_borrow', require('./quick_borrow'));
app.use('/approval', require('./approval'));
app.use('/userApproval', require('./userApproval'));
app.use('/borrow_summary', require('./borrow_summary'));
// 404 page
app.use(function (req, res) {
if (!res.headersSent) {
Expand Down
25 changes: 25 additions & 0 deletions views/borrow_summary.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%- include('./layout/header') %>
<div class="ui items" style="padding: 0 100px;">
<% borrowUser.forEach(function(user){ %>
<div class="item">
<a class="ui tiny image" href="/profile/<%= user.userId%>" style="width: 72px; height: 72px; overflow: hidden; background: #eee;">
<img src="/img/<%= user.avatar%>">
</a>
<a class="ui tiny image" style="width: 72px; height: 72px; overflow: hidden; background: #eee;">
<img src="<%= user.partpic%>">
</a>
<div class="content">
<a class="header" href="/profile/<%= user.userId%>"><%= user.name%></a>
<div class="description">
<p><span style="color: #666;">Employee Id</span> : <%= user.id%></p>
<p><span style="color: #666;">Book Name</span> : <%= user.partname%></p>
<p><span style="color: #666;">Author</span> : <%= user.partmodel_no%></p>
<p><span style="color: #666;">Borrow Time</span>: <%= user.borrowTime%></p>
<p><span style="color: #666;">Admin Approval Created</span>: <%= user.approval == false ? "NA" : "Approval Pending By Admin"%></p>
</div>
</div>
</div>
<hr>
<% }) %>
</div>
<%- include('./layout/footer') %>
26 changes: 11 additions & 15 deletions views/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,25 @@
</div>
<div style=" margin-left: 30px;">
<h2><%= borrowCount %></h2>
Books Awaiting Return
<a href="/profile/<%= user._id %>">Books Awaiting Return</a>
</div>
</div>
<div class="column">
<% if (user.isAdmin) { %>
<div style=" margin-left: 30px;">
<h2><%= approvalCount %></h2>
Return Approvals Pending
<a href="/approval">Return Approvals Pending</a>
</div>
<% } %>
</div>
<div class="column">
<% if (user.isAdmin) { %>
<div style=" margin-left: 30px;">
<h2><%= userApprovalCount %></h2>
User Account Approvals Pending
<a href="/userApproval">User Account Approvals Pending</a>
</div>
<% } %>
</div>
<div class="column">
<a class="item" href="/profile/<%= user._id %>"><i class="user icon"></i>Manage your Account</a>
<% if (user.isAdmin) { %>
<br>
<a class="item" href="/approval"><i class="clock icon"></i>Return Approvals</a>
<br>
<a class="item" href="/inventory"><i class="configure icon"></i>Manage Inventory</a>
<br>
<a class="item" href="/userApproval"><i class="add user icon"></i>Approve Users</a>
<% } %>
</div>
</div>
</div>
Expand Down Expand Up @@ -89,10 +78,17 @@
</div>
</div>
<div class="column">
<% if (user.isAdmin) { %>
<div style=" margin-left: 30px;">
<h2><%= TotalBorrowCount %></h2>
Copies Borrowed
<a href="/inventory">Copies Borrowed</a>
</div>
<% }else{ %>
<div style=" margin-left: 30px;">
<h2><%= TotalBorrowCount %></h2>
<a href="/borrow_summary">Copies Borrowed</a>
</div>
<% } %>
</div>
</div>
</div>
Expand Down

0 comments on commit 49334f3

Please sign in to comment.