MCPcopy
hub / github.com/YMFE/yapi / upEnv

Method upEnv

server/controllers/project.js:855–896  ·  view source on GitHub ↗

* 编辑项目 * @interface /project/up_env * @method POST * @category project * @foldnumber 10 * @param {Number} id 项目id,不能为空 * @param {Array} [env] 项目环境配置 * @param {String} [env[].name] 环境名称 * @param {String} [env[].domain] 环境域名 * @param {Array} [env[].header] header * @retu

(ctx)

Source from the content-addressed store, hash-verified

853 * @example
854 */
855 async upEnv(ctx) {
856 try {
857 let id = ctx.request.body.id;
858 let params = ctx.request.body;
859 if (!id) {
860 return (ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空'));
861 }
862
863 if ((await this.checkAuth(id, 'project', 'edit')) !== true) {
864 return (ctx.body = yapi.commons.resReturn(null, 405, '没有权限'));
865 }
866
867 if (!params.env || !Array.isArray(params.env)) {
868 return (ctx.body = yapi.commons.resReturn(null, 405, 'env参数格式有误'));
869 }
870
871 let projectData = await this.Model.get(id);
872 let data = {
873 up_time: yapi.commons.time()
874 };
875
876 data.env = params.env;
877 let isRepeat = this.arrRepeat(data.env, 'name');
878 if (isRepeat) {
879 return (ctx.body = yapi.commons.resReturn(null, 405, '环境变量名重复'));
880 }
881 let result = await this.Model.up(id, data);
882 let username = this.getUsername();
883 yapi.commons.saveLog({
884 content: `<a href="/user/profile/${this.getUid()}">${username}</a> 更新了项目 <a href="/project/${id}/interface/api">${
885 projectData.name
886 }</a> 的环境`,
887 type: 'project',
888 uid: this.getUid(),
889 username: username,
890 typeid: id
891 });
892 ctx.body = yapi.commons.resReturn(result);
893 } catch (e) {
894 ctx.body = yapi.commons.resReturn(null, 402, e.message);
895 }
896 }
897
898 /**
899 * 编辑项目

Callers

nothing calls this directly

Calls 6

arrRepeatMethod · 0.95
getUsernameMethod · 0.80
checkAuthMethod · 0.45
getMethod · 0.45
upMethod · 0.45
getUidMethod · 0.45

Tested by

no test coverage detected