{"size": 757, "ext": "js", "max_stars_repo_path": "functions/update.js", "max_stars_repo_name": "nailaparwin/db-crud-app-with-netlify-functions", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "functions/update.js", "max_issues_repo_name": "nailaparwin/db-crud-app-with-netlify-functions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "functions/update.js", "max_forks_repo_name": "nailaparwin/db-crud-app-with-netlify-functions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.9393939394, "max_line_length": 98, "alphanum_fraction": 0.5825627477}
const faunadb = require("faunadb"),
  q = faunadb.query

require("dotenv").config()

exports.handler = async (event) => {
  if (process.env.FAUNADB_SERVER_SECRET) {
  }
  try {
    var client = new faunadb.Client({
      secret: process.env.FAUNADB_ADMIN_SECRET,
    })
    let reqObj = JSON.parse(event.body)

    var result = await client.query(
      q.Update(q.Ref(q.Collection("students"), reqObj.id), {        
        data: { name: reqObj.name, age: reqObj.age, course: reqObj.course, gender: reqObj.gender},
      })
    )
    
    return {
      statusCode: 200,
      body: JSON.stringify({
        id: `${result.ref.id}`,
        message: "update done",
      }),
    }
  } catch (error) {
    console.log("Error: ")
    console.log(error)
  }
}
