Kar 2023-05-19 19:57:07 +05:30
parent 4ea8d4d839
commit 37786c459e
3 changed files with 26 additions and 7 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
export default function handler(req, res) { export default function handler(req, res) {
const sqlite3 = require('sqlite3').verbose(); const sqlite3 = require('sqlite3').verbose();
console.log(req.body) // console.log(req.body)
// Open a new database connection // Open a new database connection
let uname, status, type, start_month, start_date, end_date, klas, lang, phone, pass, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, school=""; let uname, status, type, start_month, start_date, end_date, klas, lang, phone, pass, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, school="";
@ -26,18 +26,30 @@ export default function handler(req, res) {
if(req.body.address) address =req.body.address; if(req.body.address) address =req.body.address;
if(req.body.school) school =req.body.school; if(req.body.school) school =req.body.school;
const db = new sqlite3.Database('data/appUser.db'); const db = new sqlite3.Database('data/appUser.db');
var msg=null;
console.log(req.body.userId) console.log(req.body.userId)
db.run(`UPDATE user SET uname = ?, status = ?, type = ?, start_month = ?, start_date = ?, end_date = ?, klas = ?, lang = ?, phone = ?, annual = ?, early_start_programme = ?, toddlers = ?, interakto = ?, email = ?, country = ?, state = ?, city = ?, address = ?, school = ? WHERE id = ? `, [ uname, status, type, start_month, start_date, end_date, klas, lang, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, school, req.body.userId], db.run(`UPDATE user SET uname = ?, status = ?, type = ?, start_month = ?, start_date = ?, end_date = ?, klas = ?, lang = ?, phone = ?, annual = ?, early_start_programme = ?, toddlers = ?, interakto = ?, email = ?, country = ?, state = ?, city = ?, address = ?, school = ? WHERE id = ? `, [ uname, status, type, start_month, start_date, end_date, klas, lang, phone, annual, early_start_programme, toddlers, interakto, email, country, state, city, address, school, req.body.userId],
function(err) { function(err) {
if (err) { if (err) {
res.status(400).json({ msg: 'Err400D' }); msg={ msg: 'Err400D' };
return console.log(err.message); // res.status(400).send({ msg: 'Err400D' });
// return console.log(err.message);
} }
res.status(200).json({ msg: 'ok' }); // console.log('message');
msg="{ msg: 'ok' }";
// res.statusCode = 200;
// res.setHeader('Content-Type', 'application/json');
// res.setHeader('Cache-Control', 'max-age=180000');
// res.end(JSON.stringify({ msg: 'ok' }));
// res.status(200).json({ msg: 'ok' });
} }
); );
db.close(); db.close();
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.setHeader('Cache-Control', 'max-age=180000');
res.end(JSON.stringify(msg));
} }

View File

@ -27,9 +27,9 @@ export default function editUser() {
fetch(`/api/getUserDetails?user=${router.query.user}`) fetch(`/api/getUserDetails?user=${router.query.user}`)
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
console.log(data); // console.log(data);
setUser(data[0]) setUser(data[0])
console.log(user) // console.log(user)
}) })
} }
@ -58,7 +58,7 @@ export default function editUser() {
klas: event.target.klas.value klas: event.target.klas.value
} }
const JSONdata = JSON.stringify(data) const JSONdata = JSON.stringify(data)
console.log(data) // console.log(data)
const endpoint = '/api/editUser' const endpoint = '/api/editUser'
const options = { const options = {
method: 'POST', method: 'POST',
@ -68,8 +68,15 @@ export default function editUser() {
body: JSONdata, body: JSONdata,
} }
const response = await fetch(endpoint, options) const response = await fetch(endpoint, options)
// .then(res => res.json())
// .then(data => {
// console.log(data);
// // setUser(data[0])
// // console.log(user)
// })
const result = await response.json() const result = await response.json()
console.log(result)
// alert(`Is this your full name: ${result.data}`) // alert(`Is this your full name: ${result.data}`)
alert(`User data updated`) alert(`User data updated`)