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

删除作品


控制器:app/controller/video.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.Video.findOne({
            where: {
                id,
                user_id: currentUser.id
            }
        });

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

        await video.destroy();

        ctx.apiSuccess('ok');
    }

路由:app/router.js

js
// 删除视频
router.post("/video/destroy", controller.video.destroy);