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

删除视频


控制器:app/controller/video_detail.js

js
	// 删除
    async destroy() {
        let { ctx, app } = this;
        let currentUser = ctx.authUser;

        ctx.validate({
            id: {
                type: "int",
                required: true,
                desc: "视频ID"
            }
        });

        let { id } = ctx.request.body;

        let video = await app.model.VideoDetail.findOne({
            where: {
                id,
            },
            include: [{
                model: app.model.Video,
                where: {
                    user_id: currentUser.id
                }
            }]
        });

        if (!video) {
            return ctx.throw(404, '该记录不存在');
        }

        await video.destroy();

        ctx.apiSuccess('ok');
    }

路由:app/router.js

js
router.post("/video_detail/destroy", controller.videoDetail.destroy);