Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions node_modules/delegates/.npmignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
*.db
.env
26 changes: 20 additions & 6 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const initialize = () => {
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
db.run(`CREATE INDEX IF NOT EXISTS idx_tasks_completed ON tasks(completed)`);
db.run(`CREATE INDEX IF NOT EXISTS idx_tasks_priority ON tasks(priority)`);
db.run(`CREATE INDEX IF NOT EXISTS idx_tasks_created_at ON tasks(created_at DESC)`);
});
};

Expand All @@ -37,12 +40,23 @@ const getTaskById = (id, callback) => {
};

const updateTask = (id, title, description, priority, completed, callback) => {
const sql = `
UPDATE tasks
SET title = ?, description = ?, priority = ?, completed = ?, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
`;
db.run(sql, [title, description, priority, completed, id], callback);
const fields = [];
const values = [];

if (title !== undefined) { fields.push('title = ?'); values.push(title); }
if (description !== undefined) { fields.push('description = ?'); values.push(description); }
if (priority !== undefined) { fields.push('priority = ?'); values.push(priority); }
if (completed !== undefined) { fields.push('completed = ?'); values.push(completed); }

if (fields.length === 0) {
return callback(new Error('No fields to update'));
}

fields.push('updated_at = CURRENT_TIMESTAMP');
values.push(id);

const sql = `UPDATE tasks SET ${fields.join(', ')} WHERE id = ?`;
db.run(sql, values, callback);
};

const deleteTask = (id, callback) => {
Expand Down
17 changes: 5 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const validateTaskId = (id) => {
};

// Routes
app.get('/', (req, res) => {
const renderTasks = (req, res) => {
db.getAllTasks((err, tasks) => {
if (err) {
console.error('Error retrieving tasks:', err);
Expand All @@ -74,19 +74,12 @@ app.get('/', (req, res) => {
}
res.render('index', { tasks });
});
});
};

app.get('/', renderTasks);

// Add routes for tasks: GET all tasks, POST new task
app.get('/tasks', (req, res) => {
db.getAllTasks((err, tasks) => {
if (err) {
console.error('Error retrieving tasks:', err);
res.status(500).render('error', { message: 'Error retrieving tasks' });
return;
}
res.render('index', { tasks });
});
});
app.get('/tasks', renderTasks);

app.post('/tasks', (req, res) => {
const { title, description, priority } = req.body;
Expand Down
16 changes: 0 additions & 16 deletions node_modules/.bin/baseline-browser-mapping

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/baseline-browser-mapping.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/baseline-browser-mapping.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/.bin/browserslist

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/browserslist.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/browserslist.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/.bin/color-support

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/color-support.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/color-support.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/.bin/create-jest

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/create-jest.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/create-jest.ps1

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/.bin/ejs

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/ejs.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions node_modules/.bin/ejs.ps1

This file was deleted.

Loading