24 lines
629 B
JavaScript
24 lines
629 B
JavaScript
import { GET_BY_EMAIL } from '../../sql/companyuser.js';
|
|
|
|
/**
|
|
* Returns the company user ids associated with the given email address.
|
|
*
|
|
* @param {object} pool - The mssql connection pool.
|
|
* @returns {Function} An async function that resolves the company user ids for an email.
|
|
*
|
|
* @example
|
|
* const fn = getByEmail(pool);
|
|
* const ids = await fn('user@example.com');
|
|
* // => [1, 2, 3]
|
|
*/
|
|
export default function getByEmail(pool) {
|
|
return async (email) => {
|
|
const result = await pool
|
|
.request()
|
|
.input('email', email)
|
|
.query(GET_BY_EMAIL);
|
|
|
|
return result.recordset.map((row) => row.id);
|
|
};
|
|
}
|