Skip to content

Commit

Permalink
reverted changes: posthog todos feature flag is active again
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory567 committed Aug 26, 2024
1 parent a4a67b4 commit aff810a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
10 changes: 9 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ var cors = require('cors');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const { PostHog } = require('posthog-node');

const posthog = new PostHog(
'phc_xC1fBU65c02AaFCisiKximyPseHTHIUGSRwtQayUXs0',
{ host: 'https://eu.i.posthog.com' }
);

var todosRouter = require('./routes/todos');

Expand All @@ -12,7 +18,9 @@ app.use(cors());

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// jade or pug
// app.set('view engine', 'jade');
app.set('view engine', 'pug');

app.use(logger('dev'));
app.use(express.json());
Expand Down
27 changes: 14 additions & 13 deletions routes/todos.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
const { body, validationResult } = require('express-validator');
const db = require('../db/db');
var express = require('express')
var router = express.Router();
/* Read all todos */
// Read all todos
router.get('/', async (req, res, next) => {
const todos = await db.models.todo.findAll();
res.status(200).json(todos);
});
/* Create todos */
// Create todos
router.post('/',
body('name').not().isEmpty(),
body('name').isLength({ max: 255 }),
Expand All @@ -29,7 +30,7 @@ router.post('/',
res.status(201).json(todo);
});
/* Update todos with done */
// Update todos with done
router.put('/:id/done',
async (req, res, next) => {
const pk = req.params.id;
Expand All @@ -45,7 +46,7 @@ router.put('/:id/done',
res.status(200).json(todo);
});
/* Update todos with undone */
// Update todos with undone
router.delete('/:id/done',
async (req, res, next) => {
const pk = req.params.id;
Expand All @@ -62,8 +63,10 @@ router.delete('/:id/done',
});
module.exports = router;
*/

/*const { body, validationResult } = require('express-validator');

const { body, validationResult } = require('express-validator');
const db = require('../db/db');
var express = require('express');
var router = express.Router();
Expand All @@ -82,12 +85,11 @@ function getDistinctIdFromCookies(req) {
return null; // Return null if there's an issue with the cookie or it's not found
}

// Helper function to handle todos sorting and date updating
async function processTodos(todos, distinctId) {
//const isFeatureEnabled = await posthog.isFeatureEnabled('move-unfinished-todos', distinctId);
const isFeatureEnabled = await posthog.isFeatureEnabled('move-unfinished-todos', distinctId);

//if (isFeatureEnabled) {
if (isFeatureEnabled) {
// Sort and update todos based on the feature flag
return todos
.sort((a, b) => {
Expand All @@ -101,7 +103,7 @@ async function processTodos(todos, distinctId) {
}
return todo;
});
//}
}

return todos;
}
Expand Down Expand Up @@ -143,12 +145,12 @@ router.post('/',
const distinctId = getDistinctIdFromCookies(req);

if (distinctId) {
//const isFeatureEnabled = await posthog.isFeatureEnabled('move-unfinished-todos', distinctId);
const isFeatureEnabled = await posthog.isFeatureEnabled('move-unfinished-todos', distinctId);

//if (isFeatureEnabled) {
if (isFeatureEnabled) {
todo.date = new Date(new Date().setDate(new Date().getDate() + 1));
todo = await todo.save();
//}
}
}

res.status(201).json(todo);
Expand Down Expand Up @@ -192,4 +194,3 @@ router.delete('/:id/done', async (req, res, next) => {
});

module.exports = router;
*/

0 comments on commit aff810a

Please sign in to comment.