Итак, я пытаюсь зашифровать фамилию (только для тестирования), и она не работает.
Вот мой код:
function getEmployeeFromRec(req) {
let employee;
bcrypt.hash(req.body.lastname, 10, (err, hash) => {
employee = {
id: req.body.id,
firstname: req.body.firstname,
lastname: hash,
datebirth: req.body.datebirth,
}
});
return employee;
}
Это мой SQL код оператора:
const createSql =
`insert into sys.test_table (
id,
firstname,
lastname,
datebirth
) values (
:id,
:firstname,
:lastname,
:datebirth
)`;
async function create(emp) {
const employee = Object.assign({}, emp);
const result = await database.simpleExecute(createSql, employee);
return employee;
}
SimpleExecute () выполняет SqlStatement с данными, которые я в него вставил.
Вот мой почтовый индекс:
async function post(req, res, next) {
try {
let employee = getEmployeeFromRec(req);
employee = await employees.create(employee);
res.status(201).json(employee);
} catch (err) {
next(err);
}
}
I Я новичок, поэтому, если бы вы могли дать мне несколько новых советов для изучения, я был бы признателен. Это мой первый учебник, с которым я работал: https://jsao.io/2018/03/creating-a-rest-api-with-node-js-and-oracle-database/
РЕДАКТИРОВАТЬ: Я нашел решение, спасибо nopassport1 за помощь!
Новый код:
function getEmployeeFromRec(req) {
var employee;
let hash = bcrypt.hashSync(req.body.lastname, 10);
employee = {
id: req.body.id,
firstname: req.body.firstname,
lastname: hash,
datebirth: req.body.datebirth,
};
return employee;
}