//http://localhost:3009/test1?id=100
app.get("/test1", (req, res) => {
try {
var request = new sqlClient.Request();
const id = req.query.id;
if (id) {
//request.query("select uid,edate,email from login with(nolock) where uid="+id,
request.query(`exec temp_login @uid=`+id+`,`,
function (err, recordset) {
if (err) {
console.log(err);
res.status(400).send({ success: false, data: err });
} else {
res.status(200).send({
success: true,
data: recordset
});
}
}
);
} else {
res
.status(400)
.send({ success: false, data: "please send id in params" });
}
} catch (e) {
res.status(400).send({ success: false, data: e });
}
});
//Post
app.post("/test2", async (req, res) => {
try {
let pool = await sql.connect(config);
var request = new sql.Request(pool);
request.input("uid", req.body.id);
request.output("nor", "");
request.output("result", "");
let e = await request.execute(`temp_login`);
res.status(200).send({
success: true,
data: e,
});
} catch (e) {
console.log(e);
res.status(400).send({ success: false, data: e });
}
});
No comments:
Post a Comment