Saturday 19 January 2019

Confused on the order these are fired

I have an API that updates a user's profile and then gets the user's information again, send it back to the client.In my API, I haveawait client.query(`UPDATE user_profiles SET user_business_name = $1, user_address = $2, user_phone = $3, user_city_code = $4, user_country = $6, user_region = $7, user_city = $8 WHERE user_profile_id = $5`, [req.body.businessName, req.body.address, req.body.phone, req.body.code, req.session.user.user_id, req.body.country, req.body.region, req.body.city]); let user = await controller.session.retrieve(req.session.user.user_id); But it seems the controller is still getting the old user data before the above the query. This is my controller.jsconst db = require('../db'); module.exports = { session: { retrieve: async(id) => { let user = await db.query(`SELECT users.username, users.user_email, users.account_type, users.user_status, users.is_subscribed, users.plan_id, users.user_last_login, users.user_level, users.subscription_end_date, user_profiles.*, user_settings.*, user_listings.listing_status FROM users LEFT JOIN user_profiles ON user_profiles.user_profile_id = users.user_id LEFT JOIN user_settings ON user_settings.user_setting_id = users.user_id LEFT JOIN user_listings ON users.username = user_listings.listing_user WHERE users.user_id = $1`, [id]); if (user && user.rows.length === 1) { return user.rows[0]; } else { return false; } } } } When I change user's business name from BC #1 to BC's #1 and log it on my client side, I still see BC #1. Shouldn't the UPDATE fire first and then the controller selects the new updated data in controller?

Submitted January 20, 2019 at 05:10AM by eggtart_prince

No comments:

Post a Comment