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-02-07 02:03:30 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'NEW PET QUEST AND USE CASE SPOTLIGHT' ;
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" >
< div class = "media" >
2018-02-07 02:03:30 +00:00
< div class = "align-self-center mr-3 ${baileyClass}" > < / d i v >
2018-02-02 00:31:38 +00:00
< div class = "media-body" >
2018-02-07 02:03:30 +00:00
< h1 class = "align-self-center" > $ { res . t ( 'newStuff' ) } < / h 1 >
2018-02-02 00:31:38 +00:00
< / d i v >
2018-01-31 10:55:39 +00:00
< / d i v >
2018-02-07 02:03:30 +00:00
< h2 > 2 / 6 / 2018 - $ { LAST _ANNOUNCEMENT _TITLE } < / h 2 >
< hr / >
2018-01-31 10:55:39 +00:00
< div class = "media" >
2018-02-07 02:03:30 +00:00
< div class = "quest_badger" > < / d i v >
2018-01-31 10:55:39 +00:00
< div class = "media-body" >
2018-02-07 02:03:30 +00:00
< h3 > New Pet Quest : Stop Badgering Me ! < / h 3 >
< p > Winter has come to the Taskwoods , but the Fairies aren 't hibernating yet because the Badgering Bother won' t stop pestering them ! Get the latest pet quest , < em > Stop Badgering Me ! < / e m > , f r o m t h e < a h r e f = " / s h o p s / q u e s t s " > Q u e s t S h o p < / a > , a n d e a r n s o m e b u s t l i n g b a d g e r p e t s b y c o m p l e t i n g y o u r r e a l - l i f e t a s k s . < / p >
< div class = "small mb-3" > by SabreCat and Lemoness < / d i v >
< div class = "small mb-3" > Written by Lil Ackbar and Lemoness < / d i v >
< div class = "small mb-3" > Art by plumilla , LilithofAlfheim , and Willow the Witty < / d i v >
2018-01-31 10:55:39 +00:00
< / d i v >
< / d i v >
2018-02-02 00:31:38 +00:00
< div class = "media" >
< div class = "media-body" >
2018-02-07 02:03:30 +00:00
< h3 class = "mt-5" > Use Case Spotlight : Interpersonal Relationships < / h 3 >
< p > This month ' s < a href = "https://habitica.wordpress.com/2018/02/06/use-case-spotlight-interpersonal-relationships/" target = "_blank" > Use Case Spotlight < / a > i s a b o u t I n t e r p e r s o n a l R e l a t i o n s h i p s ! I t f e a t u r e s a n u m b e r o f g r e a t s u g g e s t i o n s s u b m i t t e d b y H a b i t i c a n s i n t h e < a h r e f = " / g r o u p s / g u i l d / 1 d 3 a 1 0 b f - 6 0 a a - 4 8 0 6 - a 3 8 b - 8 2 d 1 0 8 4 a 5 9 e 6 " > U s e C a s e S p o t l i g h t s G u i l d < / a > . W e h o p e i t h e l p s a n y o f y o u w h o m i g h t b e l o o k i n g f o r a d v i c e t o h e l p n u r t u r e y o u r r e l a t i o n s h i p s . < / p >
2018-02-02 00:31:38 +00:00
< / d i v >
2018-02-07 02:03:30 +00:00
< div class = "scene_tavern ml-3 mb-3" > < / d i v >
2018-02-02 00:31:38 +00:00
< / d i v >
2018-02-07 02:03:30 +00:00
< p > Plus , we ' re collecting user submissions for the next spotlight ! How do you use Habitica for Spring Cleaning ? We ’ ll be featuring player - submitted examples in Use Case Spotlights on the Habitica Blog next month , so post your suggestions in the Use Case Spotlight Guild now . We look forward to learning more about how you use Habitica to improve your life and get things done ! < / p >
< 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' ,
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 => {
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 ;