56 lines
2.6 KiB
JavaScript
56 lines
2.6 KiB
JavaScript
export default function handler(req, res) {
|
|
const sqlite3 = require('sqlite3').verbose();
|
|
|
|
// 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="";
|
|
|
|
if(req.body.uname) uname =req.body.uname;
|
|
if(req.body.status) status =req.body.status;
|
|
if(req.body.type) type =req.body.type;
|
|
if(req.body.start_date) start_date =req.body.start_date;
|
|
if(req.body.end_date) end_date =req.body.end_date;
|
|
if(req.body.klas) klas =req.body.klas;
|
|
if(req.body.lang) lang =req.body.lang;
|
|
if(req.body.lang) lang =req.body.lang;
|
|
if(req.body.phone) phone =req.body.phone;
|
|
if(req.body.pass) pass =req.body.pass;
|
|
if(req.body.annual) annual =req.body.annual;
|
|
if(req.body.early_start_programme) early_start_programme =req.body.early_start_programme;
|
|
if(req.body.toddlers) toddlers =req.body.toddlers;
|
|
if(req.body.interakto) interakto =req.body.interakto;
|
|
if(req.body.email) email =req.body.email;
|
|
if(req.body.country) country =req.body.country;
|
|
if(req.body.state) state =req.body.state;
|
|
if(req.body.city) city =req.body.city;
|
|
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) {
|
|
msg={ msg: 'Err400D' };
|
|
res.status(400).send({ msg: 'Err400D' });
|
|
// return console.log(err.message);
|
|
}
|
|
// 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));
|
|
|
|
|
|
}
|
|
|