From aff810a5c2dd6c768bd210671863ab098ea85426 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 26 Aug 2024 14:46:30 +0200 Subject: [PATCH] reverted changes: posthog todos feature flag is active again --- app.js | 10 +++++++++- routes/todos.js | 27 ++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index 9802488..1650447 100644 --- a/app.js +++ b/app.js @@ -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'); @@ -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()); diff --git a/routes/todos.js b/routes/todos.js index 028c928..cac8440 100644 --- a/routes/todos.js +++ b/routes/todos.js @@ -1,3 +1,4 @@ +/* const { body, validationResult } = require('express-validator'); const db = require('../db/db'); @@ -5,14 +6,14 @@ 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 }), @@ -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; @@ -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; @@ -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(); @@ -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) => { @@ -101,7 +103,7 @@ async function processTodos(todos, distinctId) { } return todo; }); - //} + } return todos; } @@ -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); @@ -192,4 +194,3 @@ router.delete('/:id/done', async (req, res, next) => { }); module.exports = router; -*/ \ No newline at end of file