Files
yuyueguahao/server/src/modules/hospital/service.js
T
2026-07-05 14:43:34 +08:00

25 lines
622 B
JavaScript

/// modules/hospital/service.js
/// 描述:医院资源的业务逻辑层(所有 SQL 集中在这里)
const { getPool } = require('../../db');
/**
* 列出所有医院
* @returns {Promise<Array<object>>}
*/
const listAll = async () => {
const [rows] = await getPool().query('SELECT * FROM hospitals ORDER BY id');
return rows;
};
/**
* 按 ID 获取医院
* @param {string} id
* @returns {Promise<object|null>}
*/
const findById = async (id) => {
const [rows] = await getPool().query('SELECT * FROM hospitals WHERE id = ?', [id]);
return rows[0] || null;
};
module.exports = { listAll, findById };