修复了插件提示的一对警告
This commit is contained in:
parent
b89010ed51
commit
3a86eb8fa2
|
|
@ -29,7 +29,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
const sequence = count + 1;
|
const sequence = count + 1;
|
||||||
data.sequence = sequence;
|
data.sequence = sequence;
|
||||||
data.meta = {};
|
data.meta = {};
|
||||||
return 1;
|
return 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// 在create之前,查询essayId和labelId的组合是否已经存在,如果存在则不允许创建
|
// 在create之前,查询essayId和labelId的组合是否已经存在,如果存在则不允许创建
|
||||||
|
|
@ -83,7 +83,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
if (count3 > 0) {
|
if (count3 > 0) {
|
||||||
throw new OakUserException('该标签已经关联到文章中');
|
throw new OakUserException('该标签已经关联到文章中');
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -143,7 +143,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
// 将其和当前的seq互换
|
// 将其和当前的seq互换
|
||||||
await context.operate(
|
const opres1 = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -157,7 +157,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
await context.operate(
|
const opres2 = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -172,7 +172,10 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
return 1;
|
return (
|
||||||
|
(opres1.essayLabels?.update || 0) +
|
||||||
|
(opres2.essayLabels?.update || 0)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -242,7 +245,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
// 将其和当前的seq互换
|
// 将其和当前的seq互换
|
||||||
await context.operate(
|
const opres1 = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -256,7 +259,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
await context.operate(
|
const opres2 = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -270,7 +273,10 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
return 1;
|
return (
|
||||||
|
(opres1.essayLabels?.update || 0) +
|
||||||
|
(opres2.essayLabels?.update || 0)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -291,6 +297,9 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
id && nextId,
|
id && nextId,
|
||||||
'id and nextId are required when moving essayLabels'
|
'id and nextId are required when moving essayLabels'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let res = 0;
|
||||||
|
|
||||||
// 查询当前 essayLabel 和目标 essayLabel 的信息
|
// 查询当前 essayLabel 和目标 essayLabel 的信息
|
||||||
const [currentLabel, nextLabel] = await Promise.all([
|
const [currentLabel, nextLabel] = await Promise.all([
|
||||||
context.select(
|
context.select(
|
||||||
|
|
@ -342,7 +351,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const label of affectedLabels) {
|
for (const label of affectedLabels) {
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -352,6 +361,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 下移逻辑
|
// 下移逻辑
|
||||||
|
|
@ -371,7 +381,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const label of affectedLabels) {
|
for (const label of affectedLabels) {
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -381,11 +391,13 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新当前 essayLabel 的 sequence
|
// 更新当前 essayLabel 的 sequence
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -395,12 +407,14 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
} else {
|
} else {
|
||||||
// 位置相同,无需移动
|
// 位置相同,无需移动
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -414,6 +428,8 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
const { id } = filter as { id: string };
|
const { id } = filter as { id: string };
|
||||||
assert(id, 'id is required when moving essayLabels to first');
|
assert(id, 'id is required when moving essayLabels to first');
|
||||||
|
|
||||||
|
let res = 0;
|
||||||
|
|
||||||
// 查询当前 essayLabel 的信息
|
// 查询当前 essayLabel 的信息
|
||||||
const [currentLabel] = await context.select(
|
const [currentLabel] = await context.select(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
|
|
@ -450,7 +466,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
|
|
||||||
// 更新受影响的 essayLabels
|
// 更新受影响的 essayLabels
|
||||||
for (const label of affectedLabels) {
|
for (const label of affectedLabels) {
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -460,10 +476,11 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将当前 essayLabels 移到第一位
|
// 将当前 essayLabels 移到第一位
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -473,9 +490,10 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -489,6 +507,8 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
const { id } = filter as { id: string };
|
const { id } = filter as { id: string };
|
||||||
assert(id, 'id is required when moving essayLabels to last');
|
assert(id, 'id is required when moving essayLabels to last');
|
||||||
|
|
||||||
|
let res = 0;
|
||||||
|
|
||||||
// 查询当前 essayLabels 的信息
|
// 查询当前 essayLabels 的信息
|
||||||
const [currentLabel] = await context.select(
|
const [currentLabel] = await context.select(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
|
|
@ -538,7 +558,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
|
|
||||||
// 更新受影响的 essayLabels
|
// 更新受影响的 essayLabels
|
||||||
for (const label of affectedLabels) {
|
for (const label of affectedLabels) {
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -548,10 +568,12 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将当前 essayLabels 移到最后一位
|
// 将当前 essayLabels 移到最后一位
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -561,9 +583,11 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -575,6 +599,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
const { filter } = operation;
|
const { filter } = operation;
|
||||||
assert(filter);
|
assert(filter);
|
||||||
|
|
||||||
|
let res = 0;
|
||||||
// 因为删除可能是一个批量操作,filter可以查询到0-n条记录
|
// 因为删除可能是一个批量操作,filter可以查询到0-n条记录
|
||||||
const essayLabels = await context.select(
|
const essayLabels = await context.select(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
|
|
@ -609,7 +634,7 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
|
|
||||||
// 更新受影响的 essayLabels
|
// 更新受影响的 essayLabels
|
||||||
for (const label of affectedLabels) {
|
for (const label of affectedLabels) {
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -619,9 +644,11 @@ const triggers: Trigger<EntityDict, 'essayLabels', BackendRuntimeContext>[] = [
|
||||||
},
|
},
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
|
res += opres.essayLabels?.update || 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return res;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ const triggers: Trigger<EntityDict, 'label', BackendRuntimeContext>[] = [
|
||||||
const { data } = operation;
|
const { data } = operation;
|
||||||
assert(data && !Array.isArray(data));
|
assert(data && !Array.isArray(data));
|
||||||
data.meta = {};
|
data.meta = {};
|
||||||
return 1;
|
return 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// 在执行addToEssay时,将创建essayLabels,将label关联到essay中
|
// 在执行addToEssay时,将创建essayLabels,将label关联到essay中
|
||||||
|
|
@ -57,7 +57,7 @@ const triggers: Trigger<EntityDict, 'label', BackendRuntimeContext>[] = [
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建关联
|
// 创建关联
|
||||||
await context.operate(
|
const opres = await context.operate(
|
||||||
'essayLabels',
|
'essayLabels',
|
||||||
{
|
{
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
|
|
@ -71,7 +71,7 @@ const triggers: Trigger<EntityDict, 'label', BackendRuntimeContext>[] = [
|
||||||
option
|
option
|
||||||
);
|
);
|
||||||
|
|
||||||
return 1;
|
return opres.essayLabels?.create || 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue