Skip to content

Commit

Permalink
Merge pull request #36 from benfluleck/chore/153214589/implement-seed…
Browse files Browse the repository at this point in the history
…-logic-to-populate-we-application

implement seed logic to populate we application
  • Loading branch information
Benny committed Nov 29, 2017
2 parents 3b5ceec + 0d74d46 commit da0988c
Show file tree
Hide file tree
Showing 43 changed files with 746 additions and 470 deletions.
8 changes: 4 additions & 4 deletions client/src/app/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export default {
fetchRecentBooks: (offset, limit) => axios
.get(`api/v1/auth/books/recentbooks?offset=${offset}&limit=${limit}`)
.then(res => res.data),
fetchOverdueBooks: (offset,limit) => axios
.get(`api/v1/users/getoverduebooks?offset=${offset}&limit=${limit}`)
.then(res=>res.data),
fetchOverdueBooks: (offset, limit) => axios
.get(`api/v1/users/getoverduebooks?offset=${offset}&limit=${limit}`)
.then(res => res.data),
fetchbooksbyUserId: (offset, limit) => axios
.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),
loanhistory:(offset, limit) => axios
loanhistory: (offset, limit) => axios
.get(`api/v1/users/getloanhistory?offset=${offset}&limit=${limit}`)
.then(res => res.data)
}
Expand Down
10 changes: 5 additions & 5 deletions client/src/app/actions/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import setAuthorizationToken from '../utils/setAuthorizationToken';
/**
* create action: userLoggedIn: user
* @function userLoggedIn
* @param {object} response
* @param {object} data
* @returns {object} action: type and response
*/
export const userLoggedIn = data =>
Expand All @@ -31,7 +31,7 @@ export const userLogInFailure = error =>
/**
* create action: userLoggedIn: user
* @function userLoggedOut
* @param {object} response
* @param {object} user
* @returns {object} action: type and response
*/
export const userLoggedOut = user =>
Expand All @@ -43,7 +43,7 @@ export const userLoggedOut = user =>
/**
* create action: sign : user
* @function userAuthFailure
* @param {object} response
* @param {object} user
* @returns {object} action: type and response
*/
export const signUpUserFailure = user =>
Expand All @@ -55,7 +55,7 @@ export const signUpUserFailure = user =>
/**
* create action: signUpUserSuccess : user
* @function signUpUserSuccess
* @param {object} response
* @param {object} user
* @returns {object} action: type and response
*/
export const signUpUserSuccess = user =>
Expand All @@ -67,7 +67,7 @@ export const signUpUserSuccess = user =>
/**
* async helper function: sign up user
* @function signup
* @param {object} credentials
* @param {object} data
* @returns {function} asynchronous action
*/
export const signup = data => dispatch => api
Expand Down
1 change: 1 addition & 0 deletions client/src/app/actions/borrowbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const LoanBooksRejected = error => ({ type: BORROW_BOOKS_FAIL, error });
/**
* async helper function: log in user
* @function BorrowBooks
* @param {object} data
* @returns {function} asynchronous action
*/
export const borrowbooks = data => dispatch => api
Expand Down
30 changes: 15 additions & 15 deletions client/src/app/actions/fetchbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const fetchRecentBooks = books => ({ type: FETCH_ALL_RECENT_BOOKS, books
export const fetchBooks = books => ({ type: FETCH_ALL_BOOKS, books });
export const fetchBooksByUserId = books => ({ type: FETCH_BOOKS_BY_USER_ID, books });
export const fetchingBooks = state => ({ type: FETCHING_BOOKS, state });
export const fetchOverdueBooks = books => ({ type: FETCH_ALL_OVERDUE_BOOKS, books });
export const fetchOverdueBooks = books => ({ type: FETCH_ALL_OVERDUE_BOOKS, books });

/**
* async helper function: log in user
Expand All @@ -32,7 +32,7 @@ export const fetchAllBooks = (offset, limit) => dispatch => api
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(showErrorNotification({ error }));
dispatch(fetchBooksRejected({ error }));
dispatch(fetchingBooks(false));
});
Expand All @@ -45,16 +45,16 @@ export const fetchAllBooks = (offset, limit) => dispatch => api
* @returns {function} asynchronous action
*/
export const fetchOverdueBookstoDashboard = (offset, limit) => dispatch => api
.book
.fetchOverdueBooks(offset, limit)
.then((response) => {
dispatch(fetchOverdueBooks(response));
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(fetchBooksRejected({ error }));
});
.book
.fetchOverdueBooks(offset, limit)
.then((response) => {
dispatch(fetchOverdueBooks(response));
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }));
dispatch(fetchBooksRejected({ error }));
});


/**
Expand All @@ -64,7 +64,7 @@ export const fetchOverdueBookstoDashboard = (offset, limit) => dispatch => api
* @param {integer} limit
* @returns {function} asynchronous action
*/
export const fetchBooksforDashboard = (offset, limit) => dispatch => api
export const fetchAllRecentBooks = (offset, limit) => dispatch => api
.book
.fetchRecentBooks(offset, limit)
.then((response) => {
Expand All @@ -73,7 +73,7 @@ export const fetchBooksforDashboard = (offset, limit) => dispatch => api
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(showErrorNotification({ error }));
dispatch(fetchBooksRejected({ error }));
dispatch(fetchingBooks(false));
});
Expand All @@ -92,6 +92,6 @@ export const fetchAllBooksbyId = (offset, limit) => dispatch => api
dispatch(fetchBooksByUserId(response));
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(showErrorNotification({ error }));
dispatch(fetchBooksRejected({ error }));
});
2 changes: 1 addition & 1 deletion client/src/app/actions/loanhistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const loanhistory = (offset, limit) => dispatch => api
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(showErrorNotification({ error }));
dispatch(loanhistoryFailure({ error }));
});
1 change: 1 addition & 0 deletions client/src/app/actions/returnbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ReturnBookRejected = error => ({ type: RETURN_BOOKS_FAIL, error });
/**
* async helper function: Return book
* @function ReturnBooks
* @param {object} data
* @returns {function} asynchronous action
*/
export const returnbook = data => dispatch => api
Expand Down
5 changes: 3 additions & 2 deletions client/src/app/actions/uploadImage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { showErrorNotification, showSuccessNotification } from './notifications';
import request from 'superagent';
import { showErrorNotification } from './notifications';


import { UPLOAD_TO_CLOUD_IMAGE_SUCCESS,
UPLOAD_TO_CLOUD_IMAGE_FAILURE,
Expand All @@ -20,7 +21,7 @@ export const imageUploadToCloud = (username, imageData) => (dispatch) => {
return (response.body);
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(showErrorNotification({ error }));
UploadImageToCloudFailure(error);
});
};
5 changes: 3 additions & 2 deletions client/src/app/components/container/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ Dashboard.propTypes = {

Dashboard.defaultProps = {
username: '',
firstname:'',
firstname: '',
email: '',

};

const mapStateToProps = state => ({
username: state.userReducer.user.username,
firstname: state.userReducer.user.firstname,
email: state.userReducer.user.email
email: state.userReducer.user.email,
profilePic: state.userReducer.user.profilePic
});

export default connect(mapStateToProps)(Dashboard);
3 changes: 3 additions & 0 deletions client/src/app/components/container/authentication/Logout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Logout extends Component {

Logout.propTypes = {
logout: PropTypes.func.isRequired,
history: PropTypes.shape({
push: PropTypes.object
}).isRequired
};


Expand Down
36 changes: 27 additions & 9 deletions client/src/app/components/container/booklist/DisplayAllBooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ import PaginationWrapper from '../common/Pagination.jsx';
* @extends {Component}
*/
class DisplayAllBooks extends React.Component {
/**
* Creates an instance of DisplayAllBooks.
* @param {any} props
* @param {object} offset
* @param {object} limit
* @memberOf DisplayAllBooks
*/
constructor(props) {
super(props);
this.state = {
limit: 8,
offset: 0
};
}

/**
* @description dispatch actions that help populate the dashboard with books
* fetch books for the dashboard
Expand All @@ -33,7 +39,7 @@ class DisplayAllBooks extends React.Component {
/**
* render Display All Books page component
* @method render
* @member Display All Books
* @member DisplayAllBooks
* @returns {object} component
*/
render() {
Expand All @@ -47,9 +53,8 @@ this.props.allBooksList.books.map(book => (
id={book.id}
title={book.title}
author={book.author}
category={book.category}
description={book.description}
image={book.bookimage}
image={book.bookImage}
quantity={book.quantity}
/>
));
Expand All @@ -58,7 +63,6 @@ this.props.allBooksList.books.map(book => (
items: pagination.pageCount,
activePage: pagination.page
};

return (
<div>
<Row>
Expand All @@ -72,15 +76,29 @@ this.props.allBooksList.books.map(book => (
numberOfRecords={this.state.limit}
fetch={this.props.fetchAllBooks}
/>

</div>
);
}
}

// DisplayAllBooks.propTypes = {
// allBooksList: PropTypes.
// };
DisplayAllBooks.propTypes = {
allBooksList: PropTypes.shape({
title: PropTypes.string,
author: PropTypes.string,
quantity: PropTypes.number,
description: PropTypes.string,
id: PropTypes.number,
map: PropTypes.object,
pagination: PropTypes.object,
books: PropTypes.arrayOf(PropTypes.shape({
title: PropTypes.string.isRequired,
author: PropTypes.string.isRequired,
quantity: PropTypes.number.isRequired,
description: PropTypes.string,
}))
}),
fetchAllBooks: PropTypes.func.isRequired
};

DisplayAllBooks.defaultProps = {
allBooksList: null
Expand Down
Loading

0 comments on commit da0988c

Please sign in to comment.