Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const leftSidebarReducer = (state = initialState, action ) => {
- async function categoryQuery(json)
- await fetch('/category_query', { //post request in Server.js
- method: 'POST',
- headers: {
- "Content-Type": "application/json",
- },
- body: json //currently returns the user inputs
- })
- .then(function(response){
- return response.json(); //**Data I want in store here**
- })
- .catch(err => console.log(err));
- }
- //--- Further down in the Reducer: ---//
- case actionTypes.QUERY_DB:
- var newdata = [];
- var testStr = JSON.stringify({
- cat: state.leftMenu.catDrop,
- subCat: state.leftMenu.subCatDrop,
- insCat: state.leftMenu.insDrop,
- langCat: state.leftMenu.langDrop,
- });
- categoryQuery(testStr) //Run the async function above with state values
- return {
- ...state,
- data: newdata //Where the data should be updating ***
- }
- app.post('/category_query', (req, res) => { //this is the main category query
- console.log(req); //this is an attempt to see if we receive the reqs
- db.any(
- `SELECT * FROM med_services
- WHERE cat_name = $1 AND subCat = $2 AND insurance = $3`
- ,['Medical Care', 'clinic', 'blue-cross']
- //normally would be [req.body.cat, req.body.subCat, req.body.insCat]
- )
- .then(data => {
- console.log('DATA:', data); // print data;
- res.send(data);
- console.log('category query sent successfully')
- })
- .catch(error => {
- res.send('Error processing query');
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement