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

User should be informed when books are overdue #33

Merged
Show file tree
Hide file tree
Changes from 8 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
Binary file removed .DS_Store
Binary file not shown.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: npm run start
clock: node server/dist/cron/index.js
Binary file removed client/.DS_Store
Binary file not shown.
Binary file removed client/src/.DS_Store
Binary file not shown.
Binary file removed client/src/app/.DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions client/src/app/actions/actiontype.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const USER_LOG_IN_FAILURE = 'USER_LOG_IN_FAILURE';

export const USER_LOGGED_OUT = 'USER_LOGGED_OUT';

export const FETCHING_BOOKS= 'FETCHING_BOOKS';
export const FETCHING_BOOKS = 'FETCHING_BOOKS';

export const SIGN_UP_USER_FAILURE = 'SIGN_UP_USER_FAILURE';

Expand All @@ -17,7 +17,11 @@ export const FETCH_ALL_BOOKS = 'FETCH_ALL_BOOKS ';

export const FETCH_BOOKS_BY_USER_ID = 'FETCH_BOOKS_BY_USER_ID';

export const FETCH_BOOKS_REJECTED= 'FETCH_BOOKS_REJECTED';
export const FETCH_BOOKS_REJECTED = 'FETCH_BOOKS_REJECTED';

export const FETCH_ALL_OVERDUE_BOOKS = 'FETCH_ALL_OVERDUE_BOOKS';

export const FETCH_ALL_OVERDUE_REJECTED = 'FETCH_ALL_OVERDUE_REJECTED';

export const UPLOAD_TO_CLOUD_IMAGE_SUCCESS = 'UPLOAD_TO_CLOUD_IMAGE_SUCCESS';

Expand Down
3 changes: 3 additions & 0 deletions client/src/app/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ 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),
fetchbooksbyUserId: (offset, limit) => axios
.get(`api/v1/users/borrowedbooks?offset=${offset}&limit=${limit}&returned=false`)
.then(res => res.data),
Expand Down
36 changes: 18 additions & 18 deletions client/src/app/actions/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const userLoggedIn = data =>
data
});

export const userLogInFailure = error =>
export const userLogInFailure = error =>
({
type: USER_LOG_IN_FAILURE,
error
Expand All @@ -41,16 +41,16 @@ export const userLoggedOut = user =>
});

/**
* create action: userAuthFailure : user
* create action: sign : user
* @function userAuthFailure
* @param {object} response
* @returns {object} action: type and response
*/
export const signUpUserFailure = (user) =>
({
type: SIGNUP_USER_FAILURE,
user
});
export const signUpUserFailure = user =>
({
type: SIGNUP_USER_FAILURE,
user
});

/**
* create action: signUpUserSuccess : user
Expand All @@ -59,10 +59,10 @@ export const signUpUserFailure = (user) =>
* @returns {object} action: type and response
*/
export const signUpUserSuccess = user =>
({
type: SIGNUP_USER_SUCCESS,
user
});
({
type: SIGNUP_USER_SUCCESS,
user
});

/**
* async helper function: sign up user
Expand All @@ -75,10 +75,10 @@ export const signup = data => dispatch => api
.signup(data)
.then((user) => {
dispatch(signUpUserSuccess(user));
dispatch(showSuccessNotification({user}));
dispatch(showSuccessNotification({ user }));
return user;
})
.catch((error) =>{
.catch((error) => {
dispatch(showErrorNotification({ error }));
dispatch(signUpUserFailure(error));
});
Expand All @@ -93,17 +93,17 @@ export const login = credentials => dispatch => api
.user
.login(credentials)
.then((user) => {
const token = user.data.token;
const token = user.data.token;
localStorage.setItem('token', token);
dispatch(showSuccessNotification({user}));
dispatch(showSuccessNotification({ user }));
setAuthorizationToken(token);

dispatch(userLoggedIn(user.data));
})
.catch(error =>{
.catch((error) => {
dispatch(showErrorNotification({ error }));
dispatch(userLogInFailure(error))
});
dispatch(userLogInFailure(error));
});

/**
* async helper function: log out user
Expand Down
22 changes: 10 additions & 12 deletions client/src/app/actions/borrowbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ export const LoanBooksRejected = error => ({ type: BORROW_BOOKS_FAIL, error });
* @function BorrowBooks
* @returns {function} asynchronous action
*/
export const borrowbooks = data => dispatch =>{
return api
export const borrowbooks = data => dispatch => api
.book
.loanbook(data)
.then((response)=>{
dispatch(LoanBooksSuccess(response))
dispatch(showSuccessNotification(response))
return (response)
.then((response) => {
dispatch(LoanBooksSuccess(response));
dispatch(showSuccessNotification(response));
return (response);
})
.catch((error)=>{
dispatch(showErrorNotification({error}))
dispatch(LoanBooksRejected({error}))
return ({error})
})
}
.catch((error) => {
dispatch(showErrorNotification({ error }));
dispatch(LoanBooksRejected({ error }));
return ({ error });
});
41 changes: 30 additions & 11 deletions client/src/app/actions/fetchbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import {
FETCH_ALL_BOOKS,
FETCH_BOOKS_REJECTED,
FETCH_BOOKS_BY_USER_ID,
FETCHING_BOOKS
FETCHING_BOOKS,
FETCH_ALL_OVERDUE_BOOKS
} from './actiontype';
import api from './api';


export const fetchBooksRejected = error => ({ type: FETCH_BOOKS_REJECTED, error });
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 fetchingBooks = state => ({ type: FETCHING_BOOKS, state });
export const fetchOverdueBooks = books => ({ type: FETCH_ALL_OVERDUE_BOOKS, books });

/**
* async helper function: log in user
Expand All @@ -35,19 +32,39 @@ export const fetchAllBooks = (offset, limit) => dispatch => api
return response;
})
.catch((error) => {
dispatch(fetchBooksRejected ({ error }));
dispatch(showErrorNotification({ error }))
dispatch(fetchBooksRejected({ error }));
dispatch(fetchingBooks(false));
});

/**
* async helper function: log in user
* @function fetchOverdueBooks
* @param {integer} offset
* @param {integer} limit
* @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 }));
});


/**
* async helper function: fetch books to go on the dashboard
* @function fetchBooksforDashboard
* @param {integer} offset
* @param {integer} limit
* @returns {function} asynchronous action
*/
export const fetchBooksforDashboard = (offset, limit) => dispatch =>
api
export const fetchBooksforDashboard = (offset, limit) => dispatch => api
.book
.fetchRecentBooks(offset, limit)
.then((response) => {
Expand All @@ -56,7 +73,8 @@ api
return response;
})
.catch((error) => {
dispatch(fetchBooksRejected ({ error }));
dispatch(showErrorNotification({ error }))
dispatch(fetchBooksRejected({ error }));
dispatch(fetchingBooks(false));
});

Expand All @@ -74,5 +92,6 @@ export const fetchAllBooksbyId = (offset, limit) => dispatch => api
dispatch(fetchBooksByUserId(response));
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(fetchBooksRejected({ error }));
});
18 changes: 9 additions & 9 deletions client/src/app/actions/loanhistory.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { showErrorNotification } from './notifications';
import {
LOAN_HISTORY_FAILURE,
LOAN_HISTORY_SUCCESS
} from './actiontype';
import { LOAN_HISTORY_FAILURE, LOAN_HISTORY_SUCCESS } from './actiontype';
import api from './api';

export const loanhistorySuccess = bookOperations => ({ type: LOAN_HISTORY_SUCCESS, bookOperations });
export const loanhistoryFailure = error => ({ type: LOAN_HISTORY_SUCCESS, error });
export const loanhistorySuccess = bookOperations => ({
type: LOAN_HISTORY_SUCCESS,
bookOperations
});
export const loanhistoryFailure = error => ({ type: LOAN_HISTORY_FAILURE, error });

/**
* async helper function: loan history
Expand All @@ -15,14 +15,14 @@ export const loanhistoryFailure = error => ({ type: LOAN_HISTORY_SUCCESS, error
* @param {integer} limit
* @returns {function} asynchronous action
*/
export const loanhistory = (offset, limit) => dispatch =>
api
export const loanhistory = (offset, limit) => dispatch => api
.book
.loanhistory(offset, limit)
.then((response) => {
dispatch(loanhistorySuccess(response))
dispatch(loanhistorySuccess(response));
return response;
})
.catch((error) => {
dispatch(showErrorNotification({ error }))
dispatch(loanhistoryFailure({ error }));
});
10 changes: 4 additions & 6 deletions client/src/app/actions/notifications.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { reducer as notifReducer, actions as notifActions, Notifs } from 'redux-notifications';
import { actions as notifActions } from 'redux-notifications';
import setAuthorizationToken from '../utils/setAuthorizationToken';

const { notifSend } = notifActions;
import { Redirect, browserHistory } from 'react-router';
import { React } from 'react';
import setAuthorizationToken from '../utils/setAuthorizationToken';
import logout from '../actions/authenticate';


/**
* @description async notifications: show error notification
Expand Down Expand Up @@ -40,7 +38,7 @@ export const showErrorNotification = ({ message, error }) => (dispatch) => {
*/
export const showSuccessNotification = ({ message, user }) => (dispatch) => {
dispatch(notifSend({
message: message || user.data.message || data.message,
message: message || user.data.message,
kind: 'success',
dismissAfter: 2500
}));
Expand Down
30 changes: 11 additions & 19 deletions client/src/app/actions/returnbooks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { showErrorNotification, showSuccessNotification } from './notifications';
import {
RETURN_BOOKS_FAIL,
RETURN_BOOKS_SUCCESS
} from './actiontype';
import { RETURN_BOOKS_FAIL, RETURN_BOOKS_SUCCESS } from './actiontype';
import api from './api';

export const ReturnBookSuccess = returnedBook => ({ type: RETURN_BOOKS_SUCCESS, returnedBook });
Expand All @@ -14,18 +11,13 @@ export const ReturnBookRejected = error => ({ type: RETURN_BOOKS_FAIL, error });
* @returns {function} asynchronous action
*/
export const returnbook = data => dispatch => api
.book
.returnbook(data)
.then((response)=>{
dispatch(ReturnBookSuccess(response.returnedBook))
dispatch(showSuccessNotification(response))

})
.catch((error)=>{
dispatch(showErrorNotification({error}))
dispatch(ReturnBookRejected(error))
})




.book
.returnbook(data)
.then((response) => {
dispatch(ReturnBookSuccess(response.returnedBook));
dispatch(showSuccessNotification(response));
})
.catch((error) => {
dispatch(showErrorNotification({ error }));
dispatch(ReturnBookRejected(error));
});
19 changes: 10 additions & 9 deletions client/src/app/actions/uploadImage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { showErrorNotification, showSuccessNotification } from './notifications';
import request from 'superagent';
import { showErrorNotification } from './notifications';

import { UPLOAD_TO_CLOUD_IMAGE_SUCCESS,
UPLOAD_TO_CLOUD_IMAGE_FAILURE,
import { UPLOAD_TO_CLOUD_IMAGE_SUCCESS,
UPLOAD_TO_CLOUD_IMAGE_FAILURE,
CLOUDINARY_UPLOAD_PRESET,
CLOUDINARY_UPLOAD_URL } from './actiontype';

Expand All @@ -12,14 +12,15 @@ export const UploadImageToCloudFailure = error => ({ type: UPLOAD_TO_CLOUD_IMAGE
export const imageUploadToCloud = (username, imageData) => (dispatch) => {
return request
.post(CLOUDINARY_UPLOAD_URL)
.field({'upload_preset': CLOUDINARY_UPLOAD_PRESET})
.field({ upload_preset: CLOUDINARY_UPLOAD_PRESET })
.field('file', imageData)
.field('public_id', `${username}`)
.then((response) => {
dispatch(UploadImageToCloud(response.body))
return (response.body)
dispatch(UploadImageToCloud(response.body));
return (response.body);
})
.catch(error => {
UploadImageToCloudFailure(error)
.catch((error) => {
dispatch(showErrorNotification({ error }))
UploadImageToCloudFailure(error);
});
}
};
4 changes: 2 additions & 2 deletions client/src/app/components/container/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Dashboard.defaultProps = {

};

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