2018-01-31 10:55:39 +00:00
|
|
|
import { authWithHeaders } from '../../middlewares/auth';
|
|
|
|
|
|
|
|
|
|
let api = {};
|
|
|
|
|
|
|
|
|
|
// @TODO export this const, cannot export it from here because only routes are exported from controllers
|
2019-02-28 22:02:46 +00:00
|
|
|
const LAST_ANNOUNCEMENT_TITLE = 'LAST CHANCE FOR LOTS OF GOODIES!';
|
2018-01-31 10:55:39 +00:00
|
|
|
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: `
|
|
|
|
|
<div class="bailey">
|
2018-08-30 18:56:36 +00:00
|
|
|
<div class="media align-items-center">
|
2018-09-11 20:38:12 +00:00
|
|
|
<div class="mr-3 ${baileyClass}"></div>
|
2018-06-19 23:24:40 +00:00
|
|
|
<div class="media-body">
|
2018-09-11 20:38:12 +00:00
|
|
|
<h1 class="align-self-center">${res.t('newStuff')}</h1>
|
2019-02-28 22:02:46 +00:00
|
|
|
<h2>2/28/2019 - ${LAST_ANNOUNCEMENT_TITLE}</h2>
|
2018-08-30 18:56:36 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-09-11 20:38:12 +00:00
|
|
|
<hr/>
|
2019-02-25 22:58:56 +00:00
|
|
|
<div class="promo_mystery_201902 center-block"></div>
|
2019-02-28 22:02:46 +00:00
|
|
|
<h3>Last Chance for Cryptic Crush Set</h3>
|
|
|
|
|
<p>Reminder: this is the final day to <a href='/user/settings/subscription'>subscribe</a> and receive the Cryptic Crush Set! Subscribing also lets you buy Gems for Gold. The longer your subscription, the more Gems you get!</p>
|
|
|
|
|
<p>Thanks so much for your support! You help keep Habitica running.</p>
|
2019-02-25 22:58:56 +00:00
|
|
|
<div class="small mb-3">by Beffymaroo</div>
|
2019-02-28 22:02:46 +00:00
|
|
|
<div class="promo_valentines_potions center-block"></div>
|
|
|
|
|
<h3>Last Chance for Cupid and Rose Quartz Hatching Potions</h3>
|
|
|
|
|
<p>Reminder: this is the final day to <a href='/shops/market'>buy Cupid and Rose Quartz Hatching Potions</a>! If they come back, it won't be until next year at the earliest, so don't delay!</p>
|
|
|
|
|
<div class="small mb-3">by Vampitch and Willow the Witty</div>
|
|
|
|
|
<div class="promo_mythical_marvels_bundle center-block"></div>
|
|
|
|
|
<h3>Last Chance for Mythical Marvels Pet Quest Bundle</h3>
|
|
|
|
|
<p>This is also the final day to buy the discounted Mythical Marvels Pet Quest Bundle, featuring the Unicorn, Gryphon, and Sea Serpent quests all for seven Gems! Be sure to check it out in the <a href='/shops/quests'>Quest Shop</a>before it fades into legend!</p>
|
|
|
|
|
<div class="small">Art by greenpencil, UncommonCriminal, RosieSully, Lukreja, Baconsaur, Witticaster, Aries Faries, Mara, Seraphina, 1920-kun, RBrinks, and Erikari</div>
|
|
|
|
|
<div class="small mb-3">Writing by Laurel, Daniel the Bard, and gwyllgi</div>
|
2018-01-31 10:55:39 +00:00
|
|
|
</div>
|
|
|
|
|
`,
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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',
|
2018-09-21 13:12:20 +00:00
|
|
|
middlewares: [authWithHeaders()],
|
2018-01-31 10:55:39 +00:00
|
|
|
url: '/news/tell-me-later',
|
|
|
|
|
async handler (req, res) {
|
|
|
|
|
const user = res.locals.user;
|
|
|
|
|
|
|
|
|
|
user.flags.newStuff = false;
|
|
|
|
|
|
|
|
|
|
const existingNotificationIndex = user.notifications.findIndex(n => {
|
2018-02-04 12:28:05 +00:00
|
|
|
return n && n.type === 'NEW_STUFF';
|
2018-01-31 10:55:39 +00:00
|
|
|
});
|
|
|
|
|
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, {});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-02 00:31:38 +00:00
|
|
|
module.exports = api;
|