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

Method add

server/controllers/project.js:189–264  ·  view source on GitHub ↗

* 添加项目分组 * @interface /project/add * @method POST * @category project * @foldnumber 10 * @param {String} name 项目名称,不能为空 * @param {String} basepath 项目基本路径,不能为空 * @param {Number} group_id 项目分组id,不能为空 * @param {Number} group_name 项目分组名称,不能为空 * @param {String} project_type pri

(ctx)

Source from the content-addressed store, hash-verified

187 * @example ./api/project/add.json
188 */
189 async add(ctx) {
190 let params = ctx.params;
191
192 if ((await this.checkAuth(params.group_id, 'group', 'edit')) !== true) {
193 return (ctx.body = yapi.commons.resReturn(null, 405, '没有权限'));
194 }
195
196 let checkRepeat = await this.Model.checkNameRepeat(params.name, params.group_id);
197
198 if (checkRepeat > 0) {
199 return (ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名'));
200 }
201
202 params.basepath = params.basepath || '';
203
204 if ((params.basepath = this.handleBasepath(params.basepath)) === false) {
205 return (ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误'));
206 }
207
208 let data = {
209 name: params.name,
210 desc: params.desc,
211 basepath: params.basepath,
212 members: [],
213 project_type: params.project_type || 'private',
214 uid: this.getUid(),
215 group_id: params.group_id,
216 group_name: params.group_name,
217 icon: params.icon,
218 color: params.color,
219 add_time: yapi.commons.time(),
220 up_time: yapi.commons.time(),
221 is_json5: false,
222 env: [{ name: 'local', domain: 'http://127.0.0.1' }]
223 };
224
225 let result = await this.Model.save(data);
226 let colInst = yapi.getInst(interfaceColModel);
227 let catInst = yapi.getInst(interfaceCatModel);
228 if (result._id) {
229 await colInst.save({
230 name: '公共测试集',
231 project_id: result._id,
232 desc: '公共测试集',
233 uid: this.getUid(),
234 add_time: yapi.commons.time(),
235 up_time: yapi.commons.time()
236 });
237 await catInst.save({
238 name: '公共分类',
239 project_id: result._id,
240 desc: '公共分类',
241 uid: this.getUid(),
242 add_time: yapi.commons.time(),
243 up_time: yapi.commons.time()
244 });
245 }
246 let uid = this.getUid();

Callers 1

arrRepeatMethod · 0.45

Calls 9

handleBasepathMethod · 0.95
checkNameRepeatMethod · 0.80
getRoleMethod · 0.80
getUserdataMethod · 0.80
getUsernameMethod · 0.80
checkAuthMethod · 0.45
getUidMethod · 0.45
saveMethod · 0.45
addMemberMethod · 0.45

Tested by

no test coverage detected