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-11-30 20:21:12 +00:00
const LAST _ANNOUNCEMENT _TITLE = 'LAST CHANCE! SPLENDID SORCERER SET, FROST HATCHING POTIONS, ODDBALLS QUEST BUNDLE' ;
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-11-30 20:21:12 +00:00
< h2 > 11 / 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-11-28 20:50:43 +00:00
< div class = "promo_mystery_201811 center-block" > < / d i v >
2018-11-30 20:21:12 +00:00
< h3 > Last Chance for Splendid Sorcerer Item Set < / h 3 >
< p > Reminder : this is the final weekend to < a href = '/user/settings/subscription' target = '_blank' > subscribe < / a > a n d r e c e i v e t h e S p l e n d i d S o r c e r e r 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 g e t ! < / p >
< p > Thanks so much for your support ! You help keep Habitica running . < / p >
2018-11-28 20:50:43 +00:00
< div class = "small mb-3" > by Beffymaroo < / d i v >
2018-11-30 20:21:12 +00:00
< div class = "promo_frost_potions center-block" > < / d i v >
< h3 > Last Chance for Frost and Thunderstorm Hatching Potions < / h 3 >
< p > This weekend is also your last chance to < a href = '/shops/market' target = '_blank' > buy Frost and Thunderstorm 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 Balduranne < / d i v >
< div class = "promo_oddballs_bundle center-block" > < / d i v >
< h3 > Last Chance for Oddball Pet Quest Bundle < / h 3 >
< p > And finally , this weekend is all that 's left to buy the discounted Oddballs Pet Quest Bundle, featuring the Yarn, Rock, and Marshmallow Slime quests all for seven Gems! Be sure to glomp it from the <a href=' / shops / quests ' target=' _blank ' > Quest Shop < / a > r i g h t a w a y ! < / p >
< div class = "small" > Art by PainterProphet , Pfeffernusse , Zorelya , intune , starsystemic , Leephon , Arcosine , stefalupagus , Hachiseiko , TheMushroomKing , khdarkwolf , Vampitch , JinjooHat , UncommonCriminal , Oranges , Darkly , overomega , celticdragon , and Shaner < / d i v >
< div class = "small mb-3" > Writing by Bartelmy , Faelwyn the Rising Phoenix , Theothermeme , Bethany Woll , itokro , and Lemoness < / 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 ;