init
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/// 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 };
|
||||
Reference in New Issue
Block a user