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-09-10 22:20:06 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'NEW DISCOUNTED PET QUEST BUNDLE: ROCKING REPTILES' ;
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}" > < / d i v >
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' ) } < / h 1 >
2019-09-10 22:20:06 +00:00
< h2 > 9 / 10 / 2019 - $ { LAST _ANNOUNCEMENT _TITLE } < / h 2 >
2018-08-30 18:56:36 +00:00
< / d i v >
< / d i v >
2018-09-11 20:38:12 +00:00
< hr / >
2019-09-10 22:20:06 +00:00
< div class = "promo_rocking_reptiles_bundle center-block" > < / d i v >
< p > If you 're looking to add some scaly friends to your Habitica stable, you' re in luck ! From now until Sept 30 , you can purchase the Rocking Reptiles Pet Quest Bundle and receive the Alligator , Snake , and Velociraptor quests , all for only 7 Gems ! That 's a discount of 5 Gems from the price of purchasing them separately. Check it out in the <a href=' / shops / quests ' > Quest Shop < / a > t o d a y ! < / p >
< div class = "small" > Art by Gully , Willow The Witty , mfonda , UncommonCriminal , tabbytoes , EmeraldOx , LordDarkly , PainterProphet , Seraphina , Anna Glassman , Procyon , and Lilith of Alfheim < / d i v >
< div class = "small mb-3" > Writing by Mike . Antonacci , lilackbar , Daniel The Bard , and felipena < / d i v >
< p > If snakes are something you 'd prefer not to see in Habitica due to a phobia, check out the <a href=' http : //habitica.wikia.com/wiki/Phobia_Protection_Extension' target='_blank'>Phobia Protection Extension</a> which will hide any pets, mounts, backgrounds, quest bosses, or equipment featuring snakes (as well as spiders, rats, bees, zombies, skeletons, or any combination thereof). We hope that it helps make everyone's Habitica experience fun!</p>
2018-01-31 10:55:39 +00:00
< / d i v >
` ,
} ) ;
} ,
} ;
/ * *
* @ 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 ;