Skip to content
关注公众号,获取新课通知

取消关注


控制器:app/controller/user.js

js
	// 取消关注
    async unfollow() {
        const { ctx, service, app } = this;
        let currentUser = ctx.authUser;

        ctx.validate({
            follow_id: {
                type: 'int',
                required: true,
                desc: '用户ID'
            },
        });

        let { follow_id } = ctx.request.body;

        let where = {
            user_id: currentUser.id,
            follow_id
        }

        let follow = await app.model.Follow.findOne({ where });

        if (!follow) {
            return ctx.apiFail('你还没关注对方');
        }

        let res = await follow.destroy();

        ctx.apiSuccess({
            status: false,
            msg: "取消关注成功"
        });
    }

路由:app/router.js

js
// 取消关注
router.post("/user/unfollow", controller.user.unfollow);