// 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 };