Skip to content

Commit

Permalink
working on edit product and edit category
Browse files Browse the repository at this point in the history
  • Loading branch information
Easybuoy committed Nov 22, 2018
1 parent 877beda commit bef1378
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ You need Nodejs Installed to be able to run this project on your machine.
| Register User | POST | /api/v1/auth/signup | PRIVATE |
| Login User | POST | /api/v1/auth/login | PUBLIC |
| Make Store Attendant an Admin | POST | /api/v1/auth/makeadmin | PRIVATE |
| Get Current User Details | GET | /api/v1/auth/current | PRIVATE |
| Get All Store Attendants | GET | /api/v1/auth/attendants | PRIVATE |
| Create New Product | POST | /api/v1/products | PRIVATE |
| Get All Products | GET | /api/v1/products | PRIVATE |
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions client/js/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,21 @@ const viewAllAttendants = () => {

})
};

const getAttendantProfile = () => {
request('/auth/current', 'GET')
.then(res => res.json())
.then(data =>{
let role = 'Store Attendant';
if (data.data.type === 2) {
role = 'Admin';
}

document.getElementById('profileimg').src = data.data.userImage;
document.getElementById('profilename').innerHTML = data.data.name;
document.getElementById('profileemail').innerHTML = data.data.email;
document.getElementById('profilerole').innerHTML = role;
document.getElementById('profilestatus').innerHTML = 'Active';

})
}
35 changes: 7 additions & 28 deletions client/store_attendant_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

</head>

<body>
<body onload="getAttendantProfile()">

<nav class="navbar">
<span class="open-slide">
Expand Down Expand Up @@ -94,43 +94,22 @@ <h2 style="margin-bottom: 50px;">$30,322.53</h2>
<img src="img/avartar.png" id="profileimg"/>

<ul class="list-group" id="profilecontent">
<li class="list-group-item text-center"><strong>Name:</strong> Store Attendant 1</li>
<li class="list-group-item text-center"><strong>Email:</strong> attendant1@gmail.com</li>
<li class="list-group-item text-center"><strong>Role:</strong> Store Attendant</li>
<li class="list-group-item text-center"><strong>Name:</strong> <h4 id="profilename"> </h4></li>
<li class="list-group-item text-center"><strong>Email:</strong> <h4 id="profileemail"></h4></li>
<li class="list-group-item text-center"><strong>Role:</strong> <h4 id="profilerole"></h4></li>
<li class="list-group-item text-center"><strong>Status:</strong> <h4 id="profilestatus"></h4></li>
</ul>
</div>
</div>
</div>
</section>

<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content" id="cartmodaldiv">
<span class="close">&times;</span>
<table >
<thead>
<th>PRODUCT</th>
<th>AMOUNT</th>
<th>QUANTITY</th>
</thead>
<tbody id="carttablebody"></tbody>
</table>
<br>
<div class="text-center">
<button class="button_1">BUY</button>
<button class="button_1" id="clear" onclick="clearCart()">CLEAR</button>
</div>
</div>

</div>


<footer id="footer">
<p>Store Manager Copyright &copy; 2018</p>
</footer>

<script src="js/middleware.js"></script>
<script src="js/main.js"></script>
<script src="js/auth.js"></script>
</body>

</html>
24 changes: 20 additions & 4 deletions server/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,26 @@ class usersController {
* @access Private
*/
static getCurrentUser(req, res) {
res.json({
id: req.user.id,
name: req.user.name,
email: req.user.email,
const { id } = req.user;

const text = queries.userExistWithId;
const userqueryvalue = [
id,
];
db.query(text, userqueryvalue).then((dbresponse) => {
if (dbresponse.rowCount === 0) {
return res.status(400).json({ status: 'error', message: 'User not found.' });
}
const response = {
name: dbresponse.rows[0].name,
email: dbresponse.rows[0].email,
userImage: dbresponse.rows[0].userimage,
type: dbresponse.rows[0].type,
status: dbresponse.rows[0].status,
};
return res.json({ status: 'success', data: response });
}).catch(() => {
return res.status(400).json({ status: 'error', message: 'Error Fetching User Details, Please try again' });
});
}

Expand Down
1 change: 1 addition & 0 deletions server/models/queries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const queries = {
userExist: 'SELECT * FROM users WHERE email = $1',
userExistWithId: 'SELECT * FROM users WHERE id = $1',
userInsert: `INSERT INTO
users(id, name, email, password, type, status, userImage, created_at)
VALUES($1, $2, $3, $4, $5, $6, $7, $8)
Expand Down

0 comments on commit bef1378

Please sign in to comment.