Files
starr-philproperties/apps/e2e/helpers/db.js
T
kennethobsequio 05f27e34d7 asset viewer now viewing on tabs
Tabs is better for this yay

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-08-28 19:34:10 +08:00

24 lines
993 B
JavaScript

// Reuses the app's own Sequelize connection/config instead of duplicating
// DB_HOST/DB_PORT/... wiring — env.js pre-loads apps/api/.env so db.config.js
// picks up the real dev credentials when it runs its own (no-op, already-set)
// dotenv.config() call.
require('./env');
const sequelize = require('../../api/config/db.config');
const Users = require('../../api/models/users/users.mdl');
async function getUserIdByEmail(email) {
const user = await Users.findOne({ where: { email }, attributes: ['user_id'] });
if (!user) throw new Error(`No user found for email ${email} — check the dev DB seed / helpers/env.js USERS config.`);
return String(user.user_id);
}
async function getPendingOtp(user_id) {
const rows = await sequelize.query(
`SELECT otp_code FROM users WHERE user_id = :uid`,
{ replacements: { uid: user_id }, type: sequelize.QueryTypes.SELECT },
);
return rows[0]?.otp_code ?? null;
}
module.exports = { sequelize, getUserIdByEmail, getPendingOtp };