Skip to content

Commit

Permalink
general bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fawzi-iit committed Dec 3, 2023
1 parent 0071a50 commit 151b9e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const indexRouter = require('./routes/index');
const projectsRouter = require('./routes/projects');
const tasksRouter = require('./routes/tasks');


const app = express();

// MongoDB connection
Expand All @@ -22,12 +21,20 @@ db.on('error', console.error.bind(console, 'MongoDB connection error:'));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// Logger middleware
app.use(logger('dev'));

// Body parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// Cookie parsing middleware
app.use(cookieParser());

// Static file serving middleware
app.use(express.static(path.join(__dirname, 'public')));

// Route handlers
app.use('/', indexRouter);
app.use('/projects', projectsRouter);
app.use('/tasks', tasksRouter);
Expand All @@ -47,5 +54,6 @@ app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error');
});
app.listen(3000)

app.listen(3000);
module.exports = app;
11 changes: 11 additions & 0 deletions models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ const taskSchema = new mongoose.Schema({

// Static method to update a task
taskSchema.statics.updateTask = async function(taskId, status, progress, priority) {
// Validate input here
if (!['Not Started', 'In Progress', 'Completed'].includes(status)) {
throw new Error('Invalid status value');
}
if (progress < 0 || progress > 100) {
throw new Error('Progress must be between 0 and 100');
}
if (!['High', 'Medium', 'Low'].includes(priority)) {
throw new Error('Invalid priority value');
}

try {
return await this.findByIdAndUpdate(taskId, { status, progress, priority }, { new: true });
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ document.addEventListener('DOMContentLoaded', function() {
});

document.querySelectorAll('.task-priority, .task-status, .task-progress').forEach(element => {
console.log("Attaching event listener to:", element);
element.addEventListener('change', async (event) => {
const taskId = event.target.dataset.taskId;
let propertyName = '';
Expand All @@ -26,6 +27,7 @@ document.querySelectorAll('.task-priority, .task-status, .task-progress').forEac
}

const updatedValue = { [propertyName]: event.target.value };


// Debugging: Log the data being sent
console.log("Updating task:", taskId, "Property:", propertyName, "Value:", event.target.value);
Expand Down Expand Up @@ -86,6 +88,7 @@ function handleTaskUpdate(e) {
document.addEventListener('DOMContentLoaded', function() {
const updateForms = document.querySelectorAll('.task-update-form'); // Adjust selector as needed
updateForms.forEach(form => form.addEventListener('submit', handleTaskUpdate));
console.log("Event listener triggered for task update");
});
});

Expand Down

0 comments on commit 151b9e9

Please sign in to comment.