ecommerce-website/util.js

37 lines
754 B
JavaScript
Raw Normal View History

2024-03-10 20:04:53 +00:00
const sql = require('mssql');
module.exports.htmlPage = (body, title='Nat & Samira\'s Grocery Services') => `
<!DOCTYPE html>
<html lang='en'>
<head>
<title>${title}</title>
</head>
<body>
${body}
</body>
</html>
`;
module.exports.getUser = (req) => {
return req.session.user;
};
module.exports.getCustomerRecord = async (pool, id) => {
let stmt;
try {
stmt = new sql.PreparedStatement(pool);
stmt.input('id', sql.Int);
await stmt.prepare(`
select * from customer where customerId = @id
`);
const results = await stmt.execute({id: id});
return results.recordset[0];
} catch (err) {
console.error(err);
return null;
} finally {
if (stmt) stmt.unprepare();
}
};