main2
parent
4ea8d4d839
commit
37786c459e
BIN
data/appUser.db
BIN
data/appUser.db
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
export default function handler(req, res) {
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
console.log(req.body)
|
||||
// console.log(req.body)
|
||||
// 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="";
|
||||
|
||||
|
@ -26,18 +26,30 @@ export default function handler(req, res) {
|
|||
if(req.body.address) address =req.body.address;
|
||||
if(req.body.school) school =req.body.school;
|
||||
const db = new sqlite3.Database('data/appUser.db');
|
||||
var msg=null;
|
||||
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],
|
||||
function(err) {
|
||||
if (err) {
|
||||
res.status(400).json({ msg: 'Err400D' });
|
||||
return console.log(err.message);
|
||||
msg={ msg: 'Err400D' };
|
||||
// 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();
|
||||
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.setHeader('Cache-Control', 'max-age=180000');
|
||||
res.end(JSON.stringify(msg));
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ export default function editUser() {
|
|||
fetch(`/api/getUserDetails?user=${router.query.user}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
// console.log(data);
|
||||
setUser(data[0])
|
||||
console.log(user)
|
||||
// console.log(user)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ export default function editUser() {
|
|||
klas: event.target.klas.value
|
||||
}
|
||||
const JSONdata = JSON.stringify(data)
|
||||
console.log(data)
|
||||
// console.log(data)
|
||||
const endpoint = '/api/editUser'
|
||||
const options = {
|
||||
method: 'POST',
|
||||
|
@ -68,8 +68,15 @@ export default function editUser() {
|
|||
body: JSONdata,
|
||||
}
|
||||
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()
|
||||
console.log(result)
|
||||
// alert(`Is this your full name: ${result.data}`)
|
||||
alert(`User data updated`)
|
||||
|
||||
|
|
Loading…
Reference in New Issue