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-07-31 19:08:56 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'HABITICA NAMING DAY; LAST CHANCE FOR SUMMER SPLASH AND JULY 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-06-19 23:24:40 +00:00
< div class = "media align-items-center" >
2018-07-10 17:18:41 +00:00
< div class = "mr-3 ${baileyClass}" > < / d i v >
2018-06-19 23:24:40 +00:00
< div class = "media-body" >
2018-07-10 17:18:41 +00:00
< h1 class = "align-self-center" > $ { res . t ( 'newStuff' ) } < / h 1 >
2018-07-31 19:08:56 +00:00
< h2 > 7 / 31 / 2018 - $ { LAST _ANNOUNCEMENT _TITLE } < / h 2 >
2018-06-29 00:18:13 +00:00
< / d i v >
2018-06-19 23:24:40 +00:00
< / d i v >
2018-07-10 17:18:41 +00:00
< hr / >
2018-07-12 19:05:40 +00:00
< div class = "media align-items-center" >
< div class = "media-body" >
2018-07-31 19:08:56 +00:00
< h3 > Habitica Naming Day and Purple Gryphon Rewards ! < / h 3 >
< p > Happy Habitica Naming day ! In honor of the day when we changed the name of the app from HabitRPG to Habitica , we ' ve given everyone an achievement , as well as some delicious cake for your pets and mounts . < / p >
2018-07-19 19:00:53 +00:00
< / d i v >
2018-07-31 19:08:56 +00:00
< div class = "promo_naming_day_2018 ml-3 mb-3" > < / d i v >
< / d i v >
< p > Speaking of pets and mounts , we 've given all users Royal Purple Gryphon rewards! Depending on how many Naming Days you' ve celebrated with us , you ' ve received Melior ( a Purple Gryphon mount ) , his little sister Meliora ( a Purple Gryphon pet ) , a Purple Gryphon Helm , or the Purple Gryphon Wing Cloak ! < / p >
< p > Thanks for being a Habitica user -- you all mean so much to us . We hope that you enjoy your presents ! < / p >
< div class = "small mb-3" > by Lemoness , Beffymaroo , and Baconsaur < / d i v >
< div class = "media align-items-center" >
< div class = "media-body" >
< div class = "media align-items-center" >
< div class = "promo_mystery_201807 mr-3" > < / d i v >
< div class = "media-body" >
< h3 > Last Chance for Sea Serpent Set < / h 3 >
< p > Reminder : this 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 S e a S e r p e n 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 . T h e l o n g e r y o u r s u b s c r i p t i o n , t h e m o r e G e m s y o u c a n g e t ! < / p >
< p > Thanks so much for your support ! You help keep Habitica running . < / p >
< div class = "small mb-3" > by Beffymaroo < / d i v >
< / d i v >
< / d i v >
< h3 > Last Chance for Glass and Aquatic Hatching Potions < / h 3 >
< p > Reminder : this is the final day to < a href = '/shops/market' target = '_blank' > buy Glass and Aquatic Hatching Potions < / a > I f t h e y c o m e b a c k , i t w o n ' t b e u n t i l n e x t y e a r a t t h e e a r l i e s t , s o d o n ' t d e l a y ! < / p >
< div class = "small mb-3" > by stefalupagus , Beffymaroo , Mako413 , Willow The Witty , and SabreCat < / d i v >
< h3 > Last Chance for Summer Splash Goodies ! < / h 3 >
< p > A reminder that Summer Splash is ending as well ! Be sure to grab your special class gear from your Rewards column and any items you 've been eyeing in the <a href=' / shops / seasonal ' target=' _blank ' > Seasonal Shop < / a > ! < / p >
< / d i v >
< div class = "promo_aquatic_glass_potions ml-3 mb-3" > < / d i v >
2018-07-19 19:00:53 +00:00
< / 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-04-30 15:36:41 +00:00
middlewares : [ authWithHeaders ( {
userFieldsToExclude : [ 'inbox' ] ,
} ) ] ,
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 ;