{"size": 1414, "ext": "js", "max_stars_repo_path": "back/routes/hashtag.js", "max_stars_repo_name": "jiindev/study_reactNodebird", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "back/routes/hashtag.js", "max_issues_repo_name": "jiindev/study_reactNodebird", "max_issues_repo_issues_event_min_datetime": "2021-12-09T01:25:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-09T01:25:23.000Z", "max_forks_repo_path": "back/routes/hashtag.js", "max_forks_repo_name": "jiindev/study_reactNodebird", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 27.1923076923, "max_line_length": 103, "alphanum_fraction": 0.3925035361}
const express = require('express');
const db = require('../models');

const router = express.Router();

router.get('/:tag', async(req, res, next)=>{
    try{
        let where= {}
        if(parseInt(req.query.lastId, 10)){
            where = {
                id: {
                    [db.Sequelize.Op.lt]: parseInt(req.query.lastId, 10),
                }
            }
        }
        const posts = await db.Post.findAll({
            where,
            include: [{
                model: db.Hashtag,
                where: {name:decodeURIComponent(req.params.tag)}, // 특수문자, 한자를 제대로 처리하기 위해 제대로된 글자로 바꿔줌
            },{
                model: db.User,
                attributes: ['id', 'nickname'],
            },{
                model: db.Image
            }, {
                model: db.User,
                through: 'Like',
                as: 'Likers',
                attributes: ['id']
            }, {
                model: db.Post,
                as: 'Retweet',
                include: [{
                    model: db.User,
                    attributes: ['id', 'nickname'],
                },{
                    model: db.Image
                }]
            }],
            order: [['createdAt', 'DESC']],
            limit: parseInt(req.query.limit, 10)
        });
        res.json(posts);
    }catch(e){
        console.error(e);
        next(e);
    }
});

module.exports = router;
