Having recently ventured into Express, I have prior experience with Laravel and PHP.
Currently, my concern lies with a database schema structured like this:
Users table :
created_by
updated_by
In Laravel, I could easily auto-fill the 'created_by' field with the authenticated user's ID using something like this:
$new_user->request('created_by') = \Auth::user()->id; \\ This code retrieves information on the authenticated user
The desired outcome is as follows:
updated_by = 1,
created_by = 1
But how can I achieve the same in Express? How do I fetch details of the authenticated user???
This is the syntax I am currently working with:
User.update(
{
username: req.body.username,
name: req.body.name,
email: req.body.email,
status: req.body.status,
phone: req.body.phone,
keterangan: req.body.keterangan,
role: req.body.role,
password: bcrypt.hashSync(req.body.password, 8),
created_by : // What should I include?,
updated_by : // What should I include?,
},
{
where: { id: id },
}
)
Thank you for taking the time to read this, and apologies for any language barriers.