Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How do you reload this page / popup in Node?

Here's where my user starts:

User generated image
They click on the pencil and they get this pop up:

User generated image
After they finish updating their record, they get a popup that says, "Good job!" I'm working on that now.

But how do I refresh the screen they're looking at?

I can't reload the page because that eliminates the window they're looking at.

How do you do it?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

Chris, this is awesome!

But...

I'm getting an undefined" for my "resp.data.activity.notes" etc.

When I do a console.log(resp), I get Object Object.

Here's my code:


router.post('/companies/update-activity', async (req, res) => {

    try {
        let _data = {
            notes : req.body.notes,
            date : req.body.date,
            company : req.body.company,
            type : req.body.activityType
        }
      
      console.log(_data.notes);
      console.log(req.body.activityId);

        Activity.model.updateOne({ _id: req.body.activityId }, {
         $set: {
         // set up the data you want to persist to the DB
         meta : {
            notes: _data.notes,
            date: _data.date,
         },
         type: _data.type,
         }
        },
      { runValidators: true }, (err) => {
            if (err) {
                console.log(err)
                return res.send(Activity.error('Sorry! Something went wrong! Try again!'))
            }
            res.send(Activity.success({notes: "hello"} ))
        });


    } catch (err) {
        res.send(Company.error(err))
    }

This: res.send(Activity.success({notes: "hello"} )) was just me fooling around with some different ideas.

What am I missing?
If you just send this back:

res.send(Activity.success({notes: "hello"} ))

Then you'll only have access to that as resp.data.notes

If you want to send a full Activity back, then you need to do this:

let activity = ... // make sure this is a fully populated activity (built or queried)
res.send(Activity.success({activity: activity} ))

Where the second acticity in the coed above is a variable holding a fully populated activity. The you resp will have an activity property and that property will have the relevant proeprties from the activity (phew - so many activities, I need a lie down!)

resp.data.activity.notes;
Excellent.

On the Delete question, have you tried the code already posted - Leakim looks like he's got a handle on that one but I'll keep an eye on it.