parent
							
								
									43209070cd
								
							
						
					
					
						commit
						e16c429aa6
					
				@ -0,0 +1,46 @@ | 
				
			||||
module.exports = (app, router) => { | 
				
			||||
    const Anime = app.db.models.ani.series; | 
				
			||||
 | 
				
			||||
    const editCheck = (series, req, res) => { | 
				
			||||
        if (!series) {res.status(400).send("A series with that ID doesn't exist!"); return 0;} | 
				
			||||
        if (series.meta.locked) {res.status(401).send("This series has been locked. Nobody can edit it unless it has been unlocked. Please contact API admin to have it unlocked if you believe there is erroneous information."); return 0;} | 
				
			||||
        if (series.meta.approved && !series.meta.locked && req.unauthorized) {res.status(401).send("This series has been approved, so you must have series approval permissions in order to do that."); return 0;} | 
				
			||||
        if (series.meta.creator !== req.authenticatedUser && req.unauthorized) {res.status(401).send("You must have series approval permissions or be the series' creator to do that !"); return 0;} | 
				
			||||
        if (!req.authenticatedUser || !req.authenticatedUser.id) {res.status(401).send("You are not authorized to do that!"); return 0;} | 
				
			||||
        return true; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    router.route('/:id/synopsis') //completed i think?
 | 
				
			||||
        .patch(app.auth.token, app.auth.perms('series-submit'), async (req, res, next) => { | 
				
			||||
            const series = await Anime.findOne({id: req.params.id.toLowerCase()}); | 
				
			||||
            if (!editCheck(series, req, res)) {return;} | 
				
			||||
            if (!req.body.synopsis) {return res.status(400).send("You did not provide a new synopsis in your body.");} | 
				
			||||
            if (req.body.synopsis.length > 1000) {return res.status(400).send("Your new synopsis is too long!");} | 
				
			||||
            try { | 
				
			||||
                series.synopsis.synopsis = req.body.synopsis; | 
				
			||||
                if (!series.synopsis.by) {series.synopsis.by = req.authenticatedUser.id;} | 
				
			||||
                if (req.body.updateAuthor === true && series.synopsis.by !== req.authenticatedUser.id) {series.synopsis.by = req.authenticatedUser.id;} | 
				
			||||
            } | 
				
			||||
            catch {return res.status(500).send("There was an error trying to update your synopsis. Please try again.");} | 
				
			||||
            series.meta.edits.push({ | 
				
			||||
                user: req.authenticatedUser.id, | 
				
			||||
                timestamp: new Date().getTime(), | 
				
			||||
                action: "Updated synopsis" | 
				
			||||
            }); | 
				
			||||
            series.markModified('synopsis.synopsis'); | 
				
			||||
            series.markModified('meta.edits'); | 
				
			||||
            return series.save() | 
				
			||||
                .then(() => res.send("Synopsis updated.")) | 
				
			||||
                .catch(() => res.status(500).send("There was an error trying to update your synopsis. Please try again.")); | 
				
			||||
        }) | 
				
			||||
        .get(app.auth.tokenPass, app.auth.permsPass('series-approve'), async (req, res) => { //working
 | 
				
			||||
            const series = await Anime.findOne({id: req.params.id.toLowerCase()}); | 
				
			||||
            if (!series || (series && !series.meta.completed && req.unauthorized)) {return res.status(400).send("A series with that ID doesn't exist!");} | 
				
			||||
            return res.send({synopsis: series.synopsis.synopsis, by: series.synopsis.by}); | 
				
			||||
        }); | 
				
			||||
 | 
				
			||||
    //router.route()
 | 
				
			||||
 | 
				
			||||
    router.use('/:id/altnames', app.auth.tokenPass, app.auth.permsPass('series-approve')) | 
				
			||||
 | 
				
			||||
}; | 
				
			||||
@ -0,0 +1,7 @@ | 
				
			||||
module.exports = (app, router) => { | 
				
			||||
    router.use('/queue', app.auth.token, app.auth.perms('series-approve'), | 
				
			||||
        (req, res, next) => {req.listData = app.cache.seriesQueue; next();}, | 
				
			||||
        app.util.list(router, '/queue') | 
				
			||||
    ); | 
				
			||||
     //i dont know why i made a whole file for this but oh well here we are
 | 
				
			||||
}; | 
				
			||||
					Loading…
					
					
				
		Reference in new issue