diff --git a/db/device.db.js b/db/device.db.js index b92b754..1b2581c 100644 --- a/db/device.db.js +++ b/db/device.db.js @@ -12,6 +12,25 @@ const getAllDevicesDb = async () => { return result.recordset; }; +// Search devices by keyword +const searchDevicesDb = async (keyword) => { + const queryText = ` + SELECT * + FROM m_device + WHERE deleted_at IS NULL + AND ( + device_name LIKE '%' + $1 + '%' + OR device_code LIKE '%' + $1 + '%' + OR device_location LIKE '%' + $1 + '%' + OR ip_address LIKE '%' + $1 + '%' + OR device_description LIKE '%' + $1 + '%' + ) + ORDER BY device_id ASC + `; + const result = await pool.query(queryText, [keyword]); + return result.recordset; +}; + // Get device by ID const getDeviceByIdDb = async (id) => { const queryText = ` @@ -73,4 +92,5 @@ module.exports = { createDeviceDb, updateDeviceDb, softDeleteDeviceDb, + searchDevicesDb, };