/
GlomyWhisper
/
TestWork
Обзор
Документация
Войти
/
GlomyWhisper
/
TestWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
models/user.model.js
45 строк
1 KB
glomywhisper
Initial commit: user service API
17 май 2026, 01:11
17 май 2026, 01:11
9cee241
Код
Авторство
О чём код?
const pool = require('../db/pool'); async function createUser(data) { const { fullName, birthDate, email, passwordHash, role } = data; const [result] = await pool.query( 'INSERT INTO users (full_name, birth_date, email, password_hash, role) VALUES (?, ?, ?, ?, ?)', [fullName, birthDate, email, passwordHash, role || 'user'] ); return result.insertId; } async function findByEmail(email) { const [rows] = await pool.query('SELECT * FROM users WHERE email = ?', [email]); return rows[0] || null; } async function findById(id) { const [rows] = await pool.query( 'SELECT id, full_name, birth_date, email, role, is_active, created_at, updated_at FROM users WHERE id = ?', [id] ); return rows[0] || null; } async function getAllUsers() { const [rows] = await pool.query( 'SELECT id, full_name, birth_date, email, role, is_active, created_at, updated_at FROM users ORDER BY id DESC' ); return rows; } async function deactivateUser(id) { const [result] = await pool.query('UPDATE users SET is_active = FALSE WHERE id = ?', [id]); return result.affectedRows > 0; } module.exports = { createUser, findByEmail, findById, getAllUsers, deactivateUser };