How to change 2 fields in a database row?

I have a row in Database that returns:

[
  {
    id: 1,
    title: 'Marathon 1',
    video_code: 'xptowwwz',
    description: 'Essa é uma maratona legal pra caramba',
    file_id: 1,
    times_selected: null,
    created_by: 1,
    audited_by: null,
    is_published: false,
    created_at: 2020-01-29T17:04:51.000Z,
    updated_at: 2020-01-29T20:04:55.000Z
  }
]

and I want to change :

audited_by : admin.id,
is_published: true 

But without receiving it via .json through Insomnia.

Here’s the code I have so far:

  async update({ params, request, auth }) {
    const admin = await auth.authenticator('adminAuth').getUser()

    const marathon = await Database.table('marathons').where({
      id: params.id
    })
  }

How do I get this job done?

Thanks a lot!

Hello!

If you have marathons as model, then you can do something like this:
https://adonisjs.com/docs/4.1/lucid#_inserts_updates

let marathon = await Marathon.find(params.id)
marathon.audited_by = admin.id
marathon.is_published: true
await marathon.save()

And with using DB directly
https://adonisjs.com/docs/4.1/query-builder#_updates

await Database.table('marathons')
  .where({ id: params.id })
  .update({ 
    audited_by:  admin.id,
    is_published: true
  })
1 Like