MCPcopy Index your code
hub / github.com/coderwhy/coderhub / verifyLabelExists

Function verifyLabelExists

src/middleware/label.middleware.js:3–23  ·  view source on GitHub ↗
(ctx, next)

Source from the content-addressed store, hash-verified

1const service = require('../service/label.service');
2
3const verifyLabelExists = async (ctx, next) => {
4 // 1.取出要添加的所有的标签
5 const { labels } = ctx.request.body;
6
7 // 2.判断每一个标签在label表中是否存在
8 const newLabels = [];
9 for (let name of labels) {
10 const labelResult = await service.getLabelByName(name);
11 const label = { name };
12 if (!labelResult) {
13 // 创建标签数据
14 const result = await service.create(name);
15 label.id = result.insertId;
16 } else {
17 label.id = labelResult.id;
18 }
19 newLabels.push(label);
20 }
21 ctx.labels = newLabels;
22 await next();
23}
24
25module.exports = {
26 verifyLabelExists

Callers

nothing calls this directly

Calls 2

getLabelByNameMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected