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.
1 change: 1 addition & 0 deletions node_modules/delegates/.npmignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
tasks.db
18 changes: 12 additions & 6 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ const initialize = () => {
description TEXT,
priority TEXT DEFAULT 'medium',
completed INTEGER DEFAULT 0,
label TEXT DEFAULT '',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
db.run(`ALTER TABLE tasks ADD COLUMN label TEXT DEFAULT ''`, (err) => {
if (err && !err.message.includes('duplicate column name')) {
console.error('Error adding label column:', err);
}
});
});
};

const createTask = (title, description, priority, callback) => {
const sql = `INSERT INTO tasks (title, description, priority) VALUES (?, ?, ?)`;
db.run(sql, [title, description, priority], function(err) {
const createTask = (title, description, priority, label, callback) => {
const sql = `INSERT INTO tasks (title, description, priority, label) VALUES (?, ?, ?, ?)`;
db.run(sql, [title, description, priority, label], function(err) {
callback(err, this.lastID);
});
};
Expand All @@ -36,13 +42,13 @@ const getTaskById = (id, callback) => {
db.get(sql, [id], callback);
};

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

const deleteTask = (id, callback) => {
Expand Down
49 changes: 40 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ const validateCompleted = (completed) => {
return { valid: true };
};

const validateLabel = (label) => {
if (label && typeof label !== 'string') {
return { valid: false, error: 'Label must be a string' };
}
if (label && label.length > 50) {
return { valid: false, error: 'Label cannot exceed 50 characters' };
}
return { valid: true };
};

const validateTaskId = (id) => {
if (!id || isNaN(parseInt(id))) {
return { valid: false, error: 'Invalid task ID' };
Expand Down Expand Up @@ -89,7 +99,7 @@ app.get('/tasks', (req, res) => {
});

app.post('/tasks', (req, res) => {
const { title, description, priority } = req.body;
const { title, description, priority, label } = req.body;

// Validate title
const titleValidation = validateTitle(title);
Expand All @@ -109,7 +119,13 @@ app.post('/tasks', (req, res) => {
return res.status(400).render('error', { message: priorityValidation.error });
}

db.createTask(title.trim(), description ? description.trim() : '', priority || 'medium', (err, id) => {
// Validate label
const labelValidation = validateLabel(label);
if (!labelValidation.valid) {
return res.status(400).render('error', { message: labelValidation.error });
}

db.createTask(title.trim(), description ? description.trim() : '', priority || 'medium', label ? label.trim() : '', (err, id) => {
if (err) {
console.error('Error creating task:', err);
return res.status(500).render('error', { message: 'Error creating task' });
Expand All @@ -122,7 +138,7 @@ app.post('/tasks', (req, res) => {

// API Routes
app.post('/api/tasks', (req, res) => {
const { title, description, priority } = req.body;
const { title, description, priority, label } = req.body;

// Validate title
const titleValidation = validateTitle(title);
Expand All @@ -142,7 +158,13 @@ app.post('/api/tasks', (req, res) => {
return res.status(400).json({ error: priorityValidation.error });
}

db.createTask(title.trim(), description ? description.trim() : '', priority || 'medium', (err, id) => {
// Validate label
const labelValidation = validateLabel(label);
if (!labelValidation.valid) {
return res.status(400).json({ error: labelValidation.error });
}

db.createTask(title.trim(), description ? description.trim() : '', priority || 'medium', label ? label.trim() : '', (err, id) => {
if (err) {
console.error('Error creating task:', err);
return res.status(500).json({ error: 'Error creating task', details: err.message });
Expand All @@ -151,7 +173,8 @@ app.post('/api/tasks', (req, res) => {
id,
title: title.trim(),
description: description ? description.trim() : '',
priority: priority || 'medium',
priority: priority || 'medium',
label: label ? label.trim() : '',
completed: 0,
created_at: new Date().toISOString()
});
Expand Down Expand Up @@ -188,7 +211,7 @@ app.get('/api/tasks/:id', (req, res) => {
});

app.put('/api/tasks/:id', (req, res) => {
const { title, description, priority, completed } = req.body;
const { title, description, priority, completed, label } = req.body;

// Validate task ID
const idValidation = validateTaskId(req.params.id);
Expand All @@ -197,8 +220,8 @@ app.put('/api/tasks/:id', (req, res) => {
}

// Validate at least one field is provided
if (!title && !description && !priority && completed === undefined) {
return res.status(400).json({ error: 'At least one field (title, description, priority, or completed) must be provided' });
if (!title && !description && !priority && completed === undefined && !label) {
return res.status(400).json({ error: 'At least one field (title, description, priority, completed, or label) must be provided' });
}

// Validate title if provided
Expand Down Expand Up @@ -233,7 +256,15 @@ app.put('/api/tasks/:id', (req, res) => {
}
}

db.updateTask(req.params.id, title, description, priority, completed, (err) => {
// Validate label if provided
if (label !== undefined) {
const labelValidation = validateLabel(label);
if (!labelValidation.valid) {
return res.status(400).json({ error: labelValidation.error });
}
}

db.updateTask(req.params.id, title, description, priority, completed, label, (err) => {
if (err) {
console.error('Error updating task:', err);
return res.status(500).json({ error: 'Error updating task', details: err.message });
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.

Loading