2018-01-31 10:55:39 +00:00
import { authWithHeaders } from '../../middlewares/auth' ;
2019-10-08 14:57:10 +00:00
const api = { } ;
2018-01-31 10:55:39 +00:00
2019-10-22 17:53:00 +00:00
// @TODO export this const, cannot export it from here because only routes are exported from
// controllers
2019-10-31 20:03:25 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'HABITOWEEN! AND LAST CHANCE FOR OCTOBER AND FALL FESTIVAL 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 >
2019-10-31 20:03:25 +00:00
< h2 > 10 / 31 / 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-10-31 20:03:25 +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 >
< div class = "promo_habitoween_2019 center-block" > < / d i v >
< h3 > Jack O ' Lantern Pets and Mounts ! < / h 3 >
< p > The Flourishing Fields are full of cute carved pumpkins - and it looks like < a href = '/inventory/stable' > one has 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 >
< 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' > Stable < / a > ! E n j o y . < / p >
< div class = "small mb-3" > by SabreCat and Lemoness < / d i v >
< div class = "promo_fall_festival_2019 center-block" > < / d i v >
< h3 > Last Chance for Fall Festival Items , Witchy Familiars Pet Quest Bundle , and Cryptic Flame 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 Glow - in - the - Dark , Spooky , and Shadow Hatching Potions . Grab them all while you still can ! < / p >
< div class = "small mb-3" > by gawrone , jjgame83 , AnnDeLune , ʂʈєƒąʃųƥągųʂ , Katy133 , Lilith of Alfheim , Definitely not a villain , ShoGirlGeek . cataclysms , maxpendragon , Vikte , mariahm , crystalphoenix , AaronTheTwin , tricksy . fox , QuartzFox , Lemoness , Beffymaroo and SabreCat < / d i v >
< p > It 's also the last day to get the Witchy Familiars Pet Quest Bundle and receive the Rat, Spider, and Frog 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 > b e f o r e i t c r a w l s a w a y ! < / p >
< div class = "small" > by Lemoness and SabreCat < / d i v >
< div class = "small" > Art by Pandah , UncommonCriminal , Arcosine , starsystemic , RosemonkeyCT , Jon Arjinborn , and Breadstrings < / d i v >
< div class = "small mb-3" > Writing by Token , Arcosine , and Fluitare < / d i v >
< p > Plus , today is the final day to < a href = '/user/settings/subscription' > subscribe < / a > a n d r e c e i v e t h e C r y p t i c F l a m e s e t a l o n g w i t h o t h e r r a d s u b s c r i b e r p e r k s ! < / p >
< p > Thanks so much for your supporting the site -- you ' re helping us keep Habitica alive . Happy Habitoween ! < / p >
2019-10-24 20:36:32 +00:00
< div class = "small mb-3" > by Beffymaroo < / 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 ) {
2019-10-08 14:57:10 +00:00
const { user } = res . locals ;
2018-01-31 10:55:39 +00:00
user . flags . newStuff = false ;
2019-10-08 14:57:10 +00:00
const existingNotificationIndex = user . notifications . findIndex ( n => 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 , { } ) ;
} ,
} ;
2019-10-02 17:45:27 +00:00
export default api ;