Skip to content

Instantly share code, notes, and snippets.

@supermacro
Created January 23, 2022 01:39
Show Gist options
  • Save supermacro/9cd3df429756b60208ea872f42b54734 to your computer and use it in GitHub Desktop.
Save supermacro/9cd3df429756b60208ea872f42b54734 to your computer and use it in GitHub Desktop.
Example request handler from the codebase inherited by Giorgio
const express = require("express");
const jwt = require("jsonwebtoken");
const db = require("../../../db.config");
const router = express.Router();
router.use("/editCustomer/:id", async (req, res) => {
const {
fname,
lname,
cemail,
cphone,
bday,
street,
apt,
// ops,
city,
state,
zcode,
advisorId,
// ctypes,
} = req.body;
const token = advisorId.accessToken;
jwt.verify(token, process.env.SECRET, (err, getId) => {
if (err) {
res.send(err);
}
const userId = getId.id;
let email = req.params.id;
const sqlSelect =
"UPDATE contact SET firstname = ?, lastname = ?, email = ?, phone = ?, birth_date = ?, address = ?, apt = ?, city = ?, state = ?, zipcode = ? WHERE _uid = ? AND advisor_id = ?";
db.query(
sqlSelect,
[
fname,
lname,
cemail,
cphone,
bday || null,
street,
apt,
city,
state,
zcode,
email,
userId,
],
(error, result) => {
if (error) {
res.status(401).send({ error });
}
if (result) {
res.status(200).send({
message: "You have successfully update information!",
});
} else {
res.status(401).send({ message: "User dosen't exist!" });
}
}
);
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment