-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0149672
commit f46e580
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const port = 3000; | ||
|
||
// Fake data for tasks | ||
const tasks = [ | ||
{ | ||
id: 1, | ||
description: 'Complete monthly financial report' | ||
}, | ||
{ | ||
id: 2, | ||
description: 'Plan team building activity' | ||
}, | ||
{ | ||
id: 3, | ||
description: 'Update project documentation' | ||
} | ||
]; | ||
|
||
app.get('/search', (req, res) => { | ||
// Retrieve the query parameter | ||
const query = req.query.query?.toLowerCase() || ''; | ||
|
||
// Filter tasks based on the query | ||
const filteredTasks = tasks.filter(task => task.description.toLowerCase().includes(query)); | ||
|
||
// Sort the filtered tasks alphabetically by description | ||
const sortedTasks = filteredTasks.sort((a, b) => a.description.localeCompare(b.description)); | ||
|
||
res.json(sortedTasks); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Server running on port ${port}`); | ||
}); |