Skip to content

Instantly share code, notes, and snippets.

@supermacro
Created January 23, 2022 01:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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