Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of return book functionality #30

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/src/app/actions/actiontype.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export const CLOUDINARY_UPLOAD_URL = 'https://api.cloudinary.com/v1_1/digpnxufx/
export const BORROW_BOOKS_SUCCESS = 'BORROW_BOOKS_SUCCESS';

export const BORROW_BOOKS_FAIL = 'BORROW_BOOKS_FAIL';

export const RETURN_BOOKS_SUCCESS = 'RETURN_BOOKS_SUCCESS';

export const RETURN_BOOKS_FAIL = 'RETURN_BOOKS_FAIL';
2 changes: 2 additions & 0 deletions client/src/app/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default {
.get(`api/v1/users/borrowedbooks?offset=${offset}&limit=${limit}&returned=false`)
.then(res => res.data),
loanbook: data => axios.post('api/v1/users/loanbook', data)
.then(res => res.data),
returnbook: data => axios.put('api/v1/users/returnbook', data)
.then(res => res.data)

}
Expand Down
1 change: 0 additions & 1 deletion client/src/app/actions/borrowbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const borrowbooks = data => dispatch => api
.book
.loanbook(data)
.then((response)=>{
console.log(response, '??????')
dispatch(LoanBooksSuccess(response))
dispatch(showSuccessNotification(response))

Expand Down
4 changes: 2 additions & 2 deletions client/src/app/actions/fetchbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const fetchAllBooks = (offset, limit) => dispatch => api
});

/**
* async helper function: log in user
* async helper function: fetch books to go on the dashboard
* @function fetchBooksforDashboard
* @param {integer} offset
* @param {integer} limit
Expand All @@ -54,7 +54,7 @@ export const fetchBooksforDashboard = (offset, limit) => dispatch => api
});

/**
* async helper function: log in user
* async helper function:fetch books by Id
* @function fetchAllBooksbyId
* @param {object} offset
* @param {object} limit
Expand Down
31 changes: 31 additions & 0 deletions client/src/app/actions/returnbooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { showErrorNotification, showSuccessNotification } from './notifications';
import {
RETURN_BOOKS_FAIL,
RETURN_BOOKS_SUCCESS
} from './actiontype';
import api from './api';

export const ReturnBookSuccess = returnedbooks => ({ type: RETURN_BOOKS_SUCCESS, returnedbooks });
export const ReturnBookRejected = error => ({ type: RETURN_BOOKS_FAIL, error });

/**
* async helper function: Return book
* @function ReturnBooks
* @returns {function} asynchronous action
*/
export const returnbook = data => dispatch => api
.book
.returnbook(data)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent

.then((response)=>{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent
Missing space before => arrow-spacing
Missing space after => arrow-spacing

const message = response.message;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 2 indent
Trailing spaces not allowed no-trailing-spaces

dispatch(showSuccessNotification({message}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 2 indent
A space is required after '{' object-curly-spacing
A space is required before '}' object-curly-spacing
Missing semicolon semi

dispatch(ReturnBookSuccess(response))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 2 indent
Missing semicolon semi

})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent

.catch((error)=>{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent
Missing space before => arrow-spacing
Missing space after => arrow-spacing

dispatch(showErrorNotification({error}))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 2 indent
A space is required after '{' object-curly-spacing
A space is required before '}' object-curly-spacing
Missing semicolon semi

dispatch(ReturnBookRejected(error))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 4 spaces but found 2 indent
Missing semicolon semi

})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 2 spaces but found 0 indent
Missing semicolon semi


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines at the end of file. Max of 1 allowed no-multiple-empty-lines




Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const Book = books => (
$(`#modal-${books.id}`).modal('open')
}}
tabIndex="-1">

<div
<div
className="card-image"
data-tip={`<h4>Title: ${books.title}</h4><hr/> <p>Author: ${books.author}</p> <p>Category:${books.category}</p> <p>Description:${books.description}</p>`}
data-html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { connect } from 'react-redux';
import { Modal, Button, Row, Col } from 'react-materialize';
import DisplayBook from './DisplayBook.jsx';
import { borrowbooks } from '../../../../actions/borrowbooks';
import { returnbook } from '../../../../actions/returnbooks';

import 'react-datepicker/dist/react-datepicker.css';

Expand All @@ -29,6 +30,16 @@ class DisplayBookModal extends React.Component {
}

handleChange = date => this.setState({ returndate: date });

handleReturnClick = (event) =>{
event.preventDefault();
console.log({...this.state})
this.
props.
returnbook({...this.state})

}

handleClick = (event) => {
event.preventDefault();
const dateString = this.state.returndate.format("YYYY-MM-DD")
Expand All @@ -46,7 +57,6 @@ render(){

});

// console.log(isBorrowed) console.log(isBorrowed)<div>{!isBorrowed ? }
if(!this.props.isAuthenticated){
return(
<Modal id={`modal-${this.props.id}`} fixedFooter header="Loan Book">
Expand Down Expand Up @@ -77,7 +87,7 @@ else{
return (
<Modal id={`modal-${this.props.id}`} fixedFooter header="Loan Book" actions={<div>
<Button className="loan-button" onClick={this.handleClick}> Loan </Button>
<Button className="return-button"> Return </Button></div>}>
<Button className="return-button" onClick={this.handleReturnClick}> Return </Button></div>}>
<Row>
<div className="loan-book">
<Col m={12}l={6}>
Expand Down Expand Up @@ -111,4 +121,4 @@ const mapStateToProps = state => ({
});


export default connect(mapStateToProps, {borrowbooks})(DisplayBookModal);
export default connect(mapStateToProps,{returnbook,borrowbooks})(DisplayBookModal);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import {imageUploadToCloud, imageUploadToDb} from '../../../../actions/uploadImage';
import { imageUploadToCloud, imageUploadToDb } from '../../../../actions/uploadImage';
import ShowProgressBar from '../Preloader/ShowProgressBar.jsx'

/**
Expand Down
8 changes: 4 additions & 4 deletions client/src/app/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$font-stack: 'Coiny', sans-serif;
$font-stack2: 'Purple Purse', sans-serif;
$base-orange: #f2751c;
$base-white: white;
$base-white: #ffffff;
$base-background: rgb(204, 204, 204);
$secondary-color: #0089ec;

Expand Down Expand Up @@ -43,7 +43,7 @@ body {
font-family: $font-stack2;
background-color: rgb(204, 204, 204);
display: flex;
min-height: 100vh;
// min-height: 100vh;
flex-direction: column;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ form p {
.root-wrapper {
min-height: 100%;
display: flex;
min-height: 100vh;
min-height: 95vh;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line should be indented with spaces, not tabs
Property min-height already defined on line 77

flex-direction: column;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ form p {
}
}

/**
/*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use // comments everywhere

* Footer css
*/
.footer-copyright {
Expand Down
22 changes: 19 additions & 3 deletions client/src/app/reducers/bookReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
FETCH_BOOKS_BY_USER_ID,
FETCH_BOOKS_FULFILLED_BY_USER_ID,
BORROW_BOOKS_FAIL,
BORROW_BOOKS_SUCCESS
BORROW_BOOKS_SUCCESS,
RETURN_BOOKS_FAIL,
RETURN_BOOKS_SUCCESS
} from '../actions/actiontype';

/**
Expand All @@ -24,8 +26,7 @@ export default function bookReducer(state = {
books: { books: [] },
borrowedbooks: { books: [] },
fetching: false,
fetched: false,
error: null
fetched: false
}, action) {
switch (action.type) {
case FETCH_BOOKS:
Expand Down Expand Up @@ -77,6 +78,21 @@ export default function bookReducer(state = {
error: action
}
}
case RETURN_BOOKS_SUCCESS:
{
return {
...state,
returnedbooks: action
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon semi

}
case RETURN_BOOKS_FAIL:
{
return {
...state,
returnedbooks:{},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before value for key 'returnedbooks' key-spacing

error: action
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon semi

}
default:
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/utils/localSave.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* saves application state to disk
* @param {Object} state application state
* @return {undefined} wites to disk
* @return {undefined} writes to disk
*/
export const saveState = (state) => {
try {
Expand Down
28 changes: 0 additions & 28 deletions server/src/controllers/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ export default {
.catch(error => res.status(400).send({ success: false, error }));
},

/**
*
*
* @param {any} req
* @param {any} res
* @returns {any} delete books
*
*
*/
// destroybooks(req, res) {
// if (req.params.bookId === 'undefined') {
// return res.status(404).send({ success: false, message: 'Book not found' });
// }
// return Books
// .findById({
// where: {
// id: req.params.bookId,
// },
// })
// .then((book) => {
// if (!book) {
// return res.status(404).send({ success: false, message: 'Book not found' });
// }
// book.destroy();
// return res.status(200).send({ success: true, message: 'Book successfully deleted' });
// })
// .catch(() => res.status(400).send({ success: false, message: 'Enter valid inputs!' }));
// },

/**
* Route: GET: /books
Expand Down
55 changes: 0 additions & 55 deletions server/src/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import bcrypt from 'bcrypt';
import models from '../models';
// import sendResetPasswordEmail from '../mailer/mailer';
import generateToken from '../controllers/middleware/authenticate';

const User = models.User;
Expand Down Expand Up @@ -107,58 +106,4 @@ export default {
})
.catch(error => res.status(500).send(error.message));
}

/**
*
*
* @param {any} req
* @param {any} res
* @returns {any} reset password
*
*/
// reset_password(req, res) {
// User
// .findOne({ email: req.body.email })
// .then((user) => {
// if (user) {
// sendResetPasswordEmail(user);
// res.json({});
// } else {
// res
// .status(400)
// .json({
// errors: {
// global: 'There is no user with such email'
// }
// });
// }
// });
// },

/**
* Edit user Information
* @public
* @method
* @param {object} req - express http request object
* @param {object} res - express http response object
* @return {mixed} - sends an http response
*/
// updateUserInfo(req, res) {
// User
// .findById(req.params.userId)
// .then((user) => {
// user
// .update(req.body, {
// returning: true,
// plain: true
// })
// .then(() => res.status(202).send({ success: true, user, message:
// 'Your information was successfully updated' }), (error) => {
// res
// .status(500)
// .send({ success: false, error });
// });
// })
// .catch(error => res.status(500).send({ success: false, error }));
// }
};
17 changes: 0 additions & 17 deletions server/src/mailer/mailer.js
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
// import nodemailer from 'nodemailer';


// export function sendResetPasswordEmail(user) {
// const tranport = setup();
// const email = {
// from,
// to: user.email,
// subject: 'Reset Password',
// text: `
// To reset password follow this link
// ${user.generateResetPasswordLink()}
// `
// };

// tranport.sendMail(email);
// }
2 changes: 0 additions & 2 deletions server/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ Router.post('/users/loanbook', authdecodeToken, UserBooksController.loanbook);
Router.put('/users/returnbook', authdecodeToken, UserBooksController.returnbook);

Router.get('/users/borrowedbooks', authdecodeToken, UserBooksController.getborrowedBooklist);
// Router.delete('books/:bookId', BooksController.destroybooks);
// Router.put('/users/:userId', UserController.updateUserInfo);

export default Router;