Draft
Conversation
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add rating feature implementation
Implement task rating feature (1–5 stars)
Mar 12, 2026
There was a problem hiding this comment.
Pull request overview
Wires the existing rating field into the API/UI by adding rating validation and dedicated rating endpoints, plus a DB migration path for older SQLite files.
Changes:
- Added
validateRating()and extendedPUT /api/tasks/:idto accept an optionalrating. - Introduced
GET/PUT /api/tasks/:id/ratingendpoints backed by new DB helpers. - Extended DB schema with a
ratingcolumn and added a Jest manual mock for the DB module.
Reviewed changes
Copilot reviewed 3 out of 7306 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
index.js |
Adds rating validation and new rating endpoints; extends task update to include rating. |
database.js |
Adds rating column + migration and implements setTaskRating/getTaskRating; extends updateTask. |
__mocks__/database.js |
Provides Jest manual mock for DB calls including new rating methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+61
to
+66
| if (rating !== undefined && rating !== null) { | ||
| const ratingNum = parseInt(rating); | ||
| if (isNaN(ratingNum) || ratingNum < 0 || ratingNum > 5) { | ||
| return { valid: false, error: 'Rating must be between 0 and 5' }; | ||
| } | ||
| } |
Comment on lines
+246
to
+254
| // Validate rating if provided | ||
| if (rating !== undefined) { | ||
| const ratingValidation = validateRating(rating); | ||
| if (!ratingValidation.valid) { | ||
| return res.status(400).json({ error: ratingValidation.error }); | ||
| } | ||
| } | ||
|
|
||
| db.updateTask(req.params.id, title, description, priority, completed, rating !== undefined ? parseInt(rating) : undefined, (err) => { |
Comment on lines
+302
to
+306
| db.setTaskRating(req.params.id, parseInt(rating), (err) => { | ||
| if (err) { | ||
| console.error('Error updating task rating:', err); | ||
| return res.status(500).json({ error: 'Error updating task rating', details: err.message }); | ||
| } |
Comment on lines
+52
to
+62
| db.run(sql, [title, description, priority, completed, rating, id], callback); | ||
| }; | ||
|
|
||
| const deleteTask = (id, callback) => { | ||
| const sql = `DELETE FROM tasks WHERE id = ?`; | ||
| db.run(sql, [id], callback); | ||
| }; | ||
|
|
||
| const setTaskRating = (id, rating, callback) => { | ||
| const sql = `UPDATE tasks SET rating = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?`; | ||
| db.run(sql, [rating, id], callback); |
Comment on lines
9
to
+25
| CREATE TABLE IF NOT EXISTS tasks ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| title TEXT NOT NULL, | ||
| description TEXT, | ||
| priority TEXT DEFAULT 'medium', | ||
| completed INTEGER DEFAULT 0, | ||
| rating INTEGER DEFAULT 0, | ||
| created_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at DATETIME DEFAULT CURRENT_TIMESTAMP | ||
| ) | ||
| `); | ||
| // Add rating column for existing databases that predate this feature | ||
| db.run(`ALTER TABLE tasks ADD COLUMN rating INTEGER DEFAULT 0`, (err) => { | ||
| if (err && !err.message.includes('duplicate column name')) { | ||
| console.error('Error adding rating column:', err); | ||
| } | ||
| }); |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
ratingfield and DB functions (setTaskRating,getTaskRating) existed but were never wired up to the API or UI.API
GET /api/tasks/:id/rating→{ rating: N }PUT /api/tasks/:id/rating→ sets rating, validates 0–5PUT /api/tasks/:idnow accepts optionalratingfield alongside existing fieldsvalidateRating()added; rejects non-integer and out-of-range valuesDatabase
Added migration on
initialize()so existing databases without the column are upgraded automatically:Frontend
loadTasks()renders 5 clickable ★ stars per task using currentratingvaluePUT /api/tasks/:id/ratingand updates star state in the DOM.filledclass persists the saved ratingTests
updateTaskmock signatures to match the new 6-param signature__mocks__/database.jsmanual mock to avoid a pre-existing sqlite3 native binary issue in the test environmentScreenshot
Original prompt
Created from VS Code.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.