import { authWithHeaders } from '../../middlewares/auth'; let api = {}; // @TODO export this const, cannot export it from here because only routes are exported from controllers const LAST_ANNOUNCEMENT_TITLE = 'HABITICA ON INSTAGRAM, SELF-IMPOSED CHALLENGE BLOG, AND WHAT\'S THE APRIL FOOL UP TO?'; const worldDmg = { // @TODO bailey: false, }; /** * @api {get} /api/v3/news Get latest Bailey announcement * @apiName GetNews * @apiGroup News * * * @apiSuccess {Object} html Latest Bailey html * */ api.getNews = { method: 'GET', url: '/news', async handler (req, res) { const baileyClass = worldDmg.bailey ? 'npc_bailey_broken' : 'npc_bailey'; res.status(200).send({ html: `

${res.t('newStuff')}

3/30/2018 - ${LAST_ANNOUNCEMENT_TITLE}


Habitica is Now on Instagram!

Habitica's Instagram is now live! Follow us for updates and exclusive peeks at behind-the-scenes fun!

New Blog Post: Self-Imposed Challenges!

This month's featured Wiki article is about Self-Imposed Challenges! We hope that it will help you as you customize Habitica to make it as fun and challenging as you'd like it to be! Be sure to check it out, and let us know what you think by reaching out on Twitter, Tumblr, and Facebook.

by Beffymaroo and the Wiki Wizards

The April Fool Stops By the Tavern...

It's that time of year again, and all Habitica's denizens have been on the lookout for stirrings from the most mischievous Masterclasser: the April Fool. Puzzlingly (and perhaps alarmingly!) he's been unusually quiet considering his favorite day is nearing. He's announced he's keeping his plans small-scale and that they will hardly be noticed, but upon hearing this from Tavern-goers on a visit to Habit City, Lady Glaciate rolled her eyes.

"I'd be interested to know what the Master of Rogues considers a modestly-proportioned prank…" she says irritably.

Perhaps you should check back over the weekend to see what's in store…

`, }); }, }; /** * @api {post} /api/v3/news/tell-me-later Get latest Bailey announcement in a second moment * @apiName TellMeLaterNews * @apiGroup News * * * @apiSuccess {Object} data An empty Object * */ api.tellMeLaterNews = { method: 'POST', middlewares: [authWithHeaders()], url: '/news/tell-me-later', async handler (req, res) { const user = res.locals.user; user.flags.newStuff = false; const existingNotificationIndex = user.notifications.findIndex(n => { return n && n.type === 'NEW_STUFF'; }); if (existingNotificationIndex !== -1) user.notifications.splice(existingNotificationIndex, 1); user.addNotification('NEW_STUFF', { title: LAST_ANNOUNCEMENT_TITLE }, true); // seen by default await user.save(); res.respond(200, {}); }, }; module.exports = api;