Ejemplo n.º 1
0
    StoryService.prototype.getDraftPreviews = function(match){
        const rxCollection = RxMongo.collection('Drafts');
        const aggregation = [
            { $match: match },
            { $project: {
                    topic: 1,
                    summary: {$substr: ['$story', 0, 500]},
                    username: 1,
                    lastUpdated: 1,
                    storyId: 1
                }
            },
            { $sort: { lastUpdated: -1 } }
        ];
        const rxAggregate = rxCollection.flatMap(coll => RxMongo.aggregate(coll, aggregation));
        const rxStripHtmlTags = rxAggregate.flatMap(stories => Rx.Observable.from(stories))
                                            .map(story => {
                                                const regex = /(<([^>]+)>)/ig
                                                story.summary = story.summary.replace(regex, '');
                                                return story;
                                            })
                                            .toArray();

        return rxStripHtmlTags;
    }
Ejemplo n.º 2
0
    StoryService.prototype.getPreviews = function(match){
        const rxCollection = RxMongo.collection('Stories');
        const aggregation = [
            { $match: match },
            { $lookup: {
                    from: "Users",
                    localField: "username",
                    foreignField: "username",
                    as: "author"
                }
            },
            { $unwind: "$author" },
            { $project: {
                    topic: 1,
                    summary: {$substr: ['$story', 0, 500]},
                    username: 1,
                    datePublished: 1,
                    storyId: 1,
                    author: "$author.fullname"
                }
            },
            { $sort: { datePublished: -1 } }
        ];
        const rxAggregate = rxCollection.flatMap(coll => RxMongo.aggregate(coll, aggregation));
        const rxStripHtmlTags = rxAggregate.flatMap(stories => Rx.Observable.from(stories))
                                            .map(story => {
                                                const regex = /(<([^>]+)>)/ig
                                                story.summary = story.summary.replace(regex, '');
                                                return story;
                                            })
                                            .toArray();

        return rxStripHtmlTags;
    }
Ejemplo n.º 3
0
    StoryService.prototype.saveDraft = function(username, draft){
        draft.username = username;
        const now = new Date();
        const collection = RxMongo.collection('Drafts');
        const updateQuery = {_id: ObjectID(draft._id), username: username};
        const rxInsert = collection.flatMap(coll => RxMongo.insert(coll, draft));
        const rxUpdate = collection.flatMap(coll => RxMongo.updateOne(coll, updateQuery, {$set: {
            topic: sanitizeHtml(draft.topic),
            story: sanitizeHtml(draft.story),
            lastUpdated: now
        }}));

        if(!draft._id){
            return rxInsert;
        } else {
            return rxUpdate;
        }
    }
Ejemplo n.º 4
0
 const rxAggregate = rxCollection.flatMap(coll => RxMongo.aggregate(coll, aggregation));
Ejemplo n.º 5
0
 const rxUpdate = collection.flatMap(coll => RxMongo.updateOne(coll, updateQuery, {$set: {
     topic: sanitizeHtml(draft.topic),
     story: sanitizeHtml(draft.story),
     lastUpdated: now
 }}));
Ejemplo n.º 6
0
 const rxInsert = collection.flatMap(coll => RxMongo.insert(coll, draft));
Ejemplo n.º 7
0
    saveUninitialized: true,
    cookie: {
        secure: false,
        maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week 
    },
    store: store
}));

// controllers
app.use('/account', accountController);
app.use('/profile', profileController);
app.use('/', homeController);
app.use('/', contentController);

// APIs
app.use('/api', contentApiController);

// error handler
app.use((err, req, res, next) => {
    console.log(err);
    if (res.headersSent) {
        return next(err);
    }
});

// start!
const port = process.env.PORT || 3000;
RxMongo.connect(mongoUrl)
       .subscribe(db => app.listen(port,
                  () => console.log(`running on port ${port}`)),
                  error => console.log(error));