mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
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 KICKSTARTER UPDATE!';
|
|
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>8/23/2019 - ${LAST_ANNOUNCEMENT_TITLE}</h2>
|
|
</div>
|
|
</div>
|
|
<hr/>
|
|
<img src="https://habitica-assets.s3.amazonaws.com/mobileApp/images/promo_kickstarter_funded.png" class="center-block mw-100 h-auto"></img>
|
|
<h3>Habitica Class Pins Kickstarter Update</h3>
|
|
<p>Hello Habiticans! We're so excited to say that our <a href='https://www.kickstarter.com/projects/habitica/habitica-class-pins' target='_blank'>Kickstarter campaign</a> for class pins has been fully funded and all of our stretch goals have been met, much more quickly than we expected. We're blown away by all the support you've given us!</p>
|
|
<p>All nine pins as well as the animated pet and mount are now unlocked! If you've been waiting to see if we'd reach all our goals, now's the time to pledge. Thank you all so much for backing us, it means a lot to the team!</p>
|
|
<div class="small mb-3">by The Habitica Team</div>
|
|
</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',
|
|
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;
|