Files
habitica/website/server/controllers/api-v3/news.js
Sabe Jones 873ac53e27 Squashed commit of the following:
commit f461c07ca7997362512a366eebc7d3a8fba854ee
Author: Sabe Jones <sabrecat@gmail.com>
Date:   Thu Jun 11 16:37:14 2020 -0500

    fix(sprites): wolf alignment

commit 6ceb4ba6d1ea62892e9b335307043d78971328d0
Author: Sabe Jones <sabrecat@gmail.com>
Date:   Thu Jun 11 14:53:07 2020 -0500

    chore(sprites): compile

commit 8b517309f531c7f151c5c18a5ca9847ab7aa5dbb
Author: Sabe Jones <sabrecat@gmail.com>
Date:   Thu Jun 11 14:52:49 2020 -0500

    feat(content): Fluorite Magic Hatching Potion and quest
2020-06-11 16:38:05 -05:00

82 lines
2.4 KiB
JavaScript

import { authWithHeaders } from '../../middlewares/auth';
const api = {};
// @TODO export this const, cannot export it from here because only routes are exported from
// controllers
const LAST_ANNOUNCEMENT_TITLE = 'NEW QUEST FOR FLUORITE HATCHING POTIONS!';
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">
<div class="media align-items-center">
<div class="mr-3 ${baileyClass}"></div>
<div class="media-body">
<h1 class="align-self-center">${res.t('newStuff')}</h1>
<h2>6/11/2020 - ${LAST_ANNOUNCEMENT_TITLE}</h2>
</div>
</div>
<hr/>
<div class="quest_fluorite center-block"></div>
<p>
Need some color to brighten your day? Get the latest Magic Hatching Potion quest, "A
Bright Fluorite Fright", and defeat the Fluorite Elemental to earn vibrant Fluorite Magic
Hatching Potions by completing your real-life tasks!
</p>
<div class="small"> Art by @nirbhao and @-Tyr- </div>
<div class="small mb-3">Writing by @SphinxWithoutASecret</div>
</div>
`,
});
},
};
/**
* @api {post} /api/v3/news/tell-me-later Allow latest Bailey announcement to be read later
* @apiName TellMeLaterNews
* @apiDescription Add a notification to allow viewing of the latest "New Stuff by Bailey" message.
* Prevent this specific Bailey message from appearing automatically.
* @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.flags.newStuff = false;
const existingNotificationIndex = user.notifications.findIndex(n => 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, {});
},
};
export default api;