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-08-15 14:47:52 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'WORLDCON HABITICA MEETUP AND BLOG POST ON ROGUES' ;
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-08-15 14:47:52 +00:00
< h2 > 8 / 15 / 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-08-15 14:47:52 +00:00
< div class = "promo_unconventional_armor center-block" > < / d i v >
< h3 > Habitica Meetup at Worldcon ! < / h 3 >
< p > shanaqui and Dewines will be representing Habitica at < a href = 'https://dublin2019.com/' target = '_blank' > Worldcon < / a > t h i s y e a r . I f y o u ’ d l i k e t o m e e t t h e m a l o n g w i t h o t h e r f e l l o w H a b i t i c a n s , j o i n u s a t t h e H a b i t i c a W o r l d c o n M e e t u p ! T h e y ' l l b e h a n d i n g o u t p r o m o c o d e s f o r t h e s p e c i a l U n c o n v e n t i o n a l A r m o r s e t a n d H a b i t i c a s t i c k e r s ( n o t e q u a n t i t i e s m a y b e l i m i t e d ) . L o o k f o r s h a n a q u i ' s H a b i t i c a t - s h i r t ! < / p >
< p > You can find the meetup on Saturday , August 17 , at ground floor foyer of Convention Centre Dublin from 5 : 00 - 6 : 00 PM local time ! Can ’ t wait to meet you : ) < / p >
< div class = "scene_casting_spells center-block" > < / d i v >
< h3 > Blog Post : Rogue < / h 3 >
< p > This month 's <a href=' https : //habitica.wordpress.com/2019/08/14/rogue/' target='_blank'>featured Wiki article</a> is about the Rogue class! We hope that it will help you as you choose the best class for your Habitica play style. Be sure to check it out, and let us know what you think by reaching out on <a href='https://twitter.com/habitica' target='_blank'>Twitter</a>, <a href='http://blog.habitrpg.com' target='_blank'>Tumblr</a>, and <a href='https://facebook.com/habitica' target='_blank'>Facebook</a>.</p>
< div class = "small mb-3" > by shanaqui and the Wiki Wizards < / 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 ;