Skip to content

Implement task rating feature (1–5 stars)#4

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/vscode-mmneh064-zedi
Draft

Implement task rating feature (1–5 stars)#4
Copilot wants to merge 4 commits intomasterfrom
copilot/vscode-mmneh064-zedi

Conversation

Copy link

Copilot AI commented Mar 12, 2026

The rating field 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–5
  • PUT /api/tasks/:id now accepts optional rating field alongside existing fields
  • validateRating() added; rejects non-integer and out-of-range values
PUT /api/tasks/42/rating
Content-Type: application/json

{ "rating": 4 }

Database

Added migration on initialize() so existing databases without the column are upgraded automatically:

db.run(`ALTER TABLE tasks ADD COLUMN rating INTEGER DEFAULT 0`, (err) => {
  if (err && !err.message.includes('duplicate column name')) { ... }
});

Frontend

  • loadTasks() renders 5 clickable ★ stars per task using current rating value
  • Click handler calls PUT /api/tasks/:id/rating and updates star state in the DOM
  • CSS hover trick fills stars up to the cursor position; .filled class persists the saved rating

Tests

  • Updated existing updateTask mock signatures to match the new 6-param signature
  • Added test suites for both rating endpoints: success, 404, 500, missing/invalid/out-of-range rating, and zero (clear) rating — 34 tests total
  • Added __mocks__/database.js manual mock to avoid a pre-existing sqlite3 native binary issue in the test environment

Screenshot

Rating feature UI

Original prompt

implement rating feature

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.

Prathyushanuthi-hub and others added 4 commits March 12, 2026 17:14
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
@akshay-online akshay-online requested a review from Copilot March 16, 2026 13:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 extended PUT /api/tasks/:id to accept an optional rating.
  • Introduced GET/PUT /api/tasks/:id/rating endpoints backed by new DB helpers.
  • Extended DB schema with a rating column 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);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants