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

Method listByCat

server/controllers/interface.js:515–564  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

513 }
514
515 async listByCat(ctx) {
516 let catid = ctx.request.query.catid;
517 let page = ctx.request.query.page || 1,
518 limit = ctx.request.query.limit || 10;
519 let status = ctx.request.query.status,
520 tag = ctx.request.query.tag;
521
522 if (!catid) {
523 return (ctx.body = yapi.commons.resReturn(null, 400, 'catid不能为空'));
524 }
525 try {
526 let catdata = await this.catModel.get(catid);
527
528 let project = await this.projectModel.getBaseInfo(catdata.project_id);
529 if (project.project_type === 'private') {
530 if ((await this.checkAuth(project._id, 'project', 'view')) !== true) {
531 return (ctx.body = yapi.commons.resReturn(null, 406, '没有权限'));
532 }
533 }
534
535
536 let option = {catid}
537 if (status) {
538 if (Array.isArray(status)) {
539 option.status = {"$in": status};
540 } else {
541 option.status = status;
542 }
543 }
544 if (tag) {
545 if (Array.isArray(tag)) {
546 option.tag = {"$in": tag};
547 } else {
548 option.tag = tag;
549 }
550 }
551
552 let result = await this.Model.listByOptionWithPage(option, page, limit);
553
554 let count = await this.Model.listCount(option);
555
556 ctx.body = yapi.commons.resReturn({
557 count: count,
558 total: Math.ceil(count / limit),
559 list: result
560 });
561 } catch (err) {
562 ctx.body = yapi.commons.resReturn(null, 402, err.message + '1');
563 }
564 }
565
566 async listByMenu(ctx) {
567 let project_id = ctx.params.project_id;

Callers

nothing calls this directly

Calls 5

getBaseInfoMethod · 0.80
listByOptionWithPageMethod · 0.80
getMethod · 0.45
checkAuthMethod · 0.45
listCountMethod · 0.45

Tested by

no test coverage detected