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

更新作品


控制器:app/controller/video.js

js
	// 更新作品
	async update() {
        let { ctx, app } = this;
        let currentUser = ctx.authUser;

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

        let {
            title,
            cover,
            category_id,
            desc,
        } = ctx.request.body;

        let video = await app.model.Video.findOne({
            where: {
                id: ctx.params.id,
                user_id: currentUser.id
            }
        });

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

        let res = await video.update({
            title,
            cover,
            category_id,
            desc,
        });

        ctx.apiSuccess(res);
    }

路由:app/router.js

js
// 更新视频
router.post("/video/:id", controller.video.update);