add: device search db
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user