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 NAMING DAY; LAST CHANCE FOR SUMMER SPLASH AND JULY SUBSCRIBER ITEMS'; 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')}

7/31/2018 - ${LAST_ANNOUNCEMENT_TITLE}


Habitica Naming Day and Purple Gryphon Rewards!

Happy Habitica Naming day! In honor of the day when we changed the name of the app from HabitRPG to Habitica, we've given everyone an achievement, as well as some delicious cake for your pets and mounts.

Speaking of pets and mounts, we've given all users Royal Purple Gryphon rewards! Depending on how many Naming Days you've celebrated with us, you've received Melior (a Purple Gryphon mount), his little sister Meliora (a Purple Gryphon pet), a Purple Gryphon Helm, or the Purple Gryphon Wing Cloak !

Thanks for being a Habitica user -- you all mean so much to us. We hope that you enjoy your presents!

by Lemoness, Beffymaroo, and Baconsaur

Last Chance for Sea Serpent Set

Reminder: this is the final day to subscribe and receive the Sea Serpent Set! Subscribing also lets you buy Gems for Gold. The longer your subscription, the more Gems you can get!

Thanks so much for your support! You help keep Habitica running.

by Beffymaroo

Last Chance for Glass and Aquatic Hatching Potions

Reminder: this is the final day to buy Glass and Aquatic Hatching Potions If they come back, it won't be until next year at the earliest, so don't delay!

by stefalupagus, Beffymaroo, Mako413, Willow The Witty, and SabreCat

Last Chance for Summer Splash Goodies!

A reminder that Summer Splash is ending as well! Be sure to grab your special class gear from your Rewards column and any items you've been eyeing in the Seasonal Shop!

`, }); }, }; /** * @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({ userFieldsToExclude: ['inbox'], })], 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;