Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory567 committed Aug 28, 2024
2 parents e08e9aa + 206652c commit 32fbeb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Empty file added -w
Empty file.
30 changes: 30 additions & 0 deletions routes/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ function getDistinctIdFromReqHeader(req) {
return null;
}



async function processTodos(todos, distinctId) {
const isFeatureEnabled = await posthog.isFeatureEnabled('move-unfinished-todos', distinctId);

console.log("Feature flag enabled:", isFeatureEnabled);

if (isFeatureEnabled) {
return todos
.sort((a, b) => {
// Unfinished todos to the top
if (!a.done && b.done) return -1;
if (a.done && !b.done) return 1;

// Sort by date
return new Date(a.createdAt) - new Date(b.createdAt);
})
.map(todo => {
// Update date for unfinished todos
if (!todo.done) {
todo.date = new Date(new Date().setDate(new Date().getDate() + 1));
}
return todo;
});
}

return todos;
}
/*
// Helper function to handle todos sorting and date updating
async function processTodos(todos, distinctId) {
console.log("inside processTodos function");
Expand All @@ -113,6 +142,7 @@ async function processTodos(todos, distinctId) {
}
return todos;
}
*/

// Read all todos
router.get('/', async (req, res, next) => {
Expand Down

0 comments on commit 32fbeb9

Please sign in to comment.