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
2018-10-30 21:21:42 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'HABITOWEEN! PLUS LAST CHANCE FOR FALL FESTIVAL AND OCTOBER SUBSCRIBER ITEMS' ;
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 >
2018-10-30 21:21:42 +00:00
< h2 > 10 / 30 / 2018 - $ { 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 / >
2018-10-30 21:21:42 +00:00
< h3 > Happy Habitoween ! < / h 3 >
< p > It ' s the last day of the Fall Festival , and all the NPCs are looking monstrous . Plus , we have lots of fun things in store ... < / p >
< h3 > Jack O ' Lantern Pets and Mounts < / h 3 >
< p > The Flourishing Fields are full of cute carved pumpkins - and it looks like one has < a href = '/inventory/stable' target = '_blank' > followed you home < / a > ! W h a t k i n d o f p u m p k i n ? I t a l l d e p e n d s o n h o w m a n y H a b i t o w e e n s y o u ' v e c e l e b r a t e d w i t h u s . E a c h H a b i t o w e e n , y o u ' l l g e t a n e w a n d e x c i t i n g p u m p k i n v a r i e t y ! < / p >
< div class = "small mb-3" > by Lemoness and Beffymaroo < / d i v >
< div class = "promo_jackolanterns center-block" > < / d i v >
< h3 > Candy for Everyone ! < / h 3 >
< p > It 's a feast for your pets and mounts! In honor of the end of the Fall Festival, we' ve given everyone an assortment of candy . You can feed it to your pets in the < a href = '/inventory/stable' target = '_blank' > Stable < / a > ! E n j o y . < / p >
< div class = "small mb-3" > by SabreCat and Lemoness < / d i v >
2018-10-25 21:31:00 +00:00
< div class = "promo_mystery_201810 center-block" > < / d i v >
2018-10-30 21:21:42 +00:00
< h3 > Last Chance for Fall Festival Items and Dark Forest Set < / h 3 >
< p > This is your last chance to get all Fall Festival items before they vanish at the end of October 31 st ! This includes Limited - Edition Outfits , Seasonal Shop purchases , Seasonal Edition Skins and Hair Colors , and yes , even Ghost and Glow Hatching Potions . Grab them all while you still can ! < / p >
< p > Plus , today is the final day to < a href = '/user/settings/subscription' target = '_blank' > subscribe < / a > a n d r e c e i v e t h e D a r k F o r e s t s e t ! S u b s c r i b i n g a l s o l e t s y o u b u y G e m s f o r G o l d a n d n e t s y o u a s p e c i a l J a c k a l o p e p e t . < / p >
< p > Thanks so much for your supporting the site -- you ' re helping us keep Habitica alive . Happy Habitoween ! < / p >
< div class = "small mb-3" > by Hermi , AaronTheTwin , tricksy . fox , Lemoness , Beffymaroo and SabreCat < / d i v >
< div class = "promo_ghost_potions center-block" > < / d i v >
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 ;