Is there a cleaner/more appropriate way to auto-create this entity relationship in the Middleware?

Hello, my current middleware to additionally create a Profile entitiy for the newly registered user looks like this:

module.exports = async (req, res, manifest) => {
    const user = await manifest.from('users').where('name = ' + req.body.name).find();
    const userId = user.data[0].id;
        await manifest.from('profiles').create({
            userId: userId,
        });
}



Is there a better, or rather, more sanitized way to additionally create the entity like this?
Was this page helpful?