@nest-omni/core 4.1.3-6 → 4.1.3-8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -92,24 +92,22 @@ let IsUniqueValidator = class IsUniqueValidator {
|
|
|
92
92
|
let exists;
|
|
93
93
|
const defCon = findCondition(args);
|
|
94
94
|
// 获取用于判断是否为新建的字段
|
|
95
|
-
//
|
|
95
|
+
// 优先级:手动配置的 uniqueKeys > 实体主键
|
|
96
96
|
let pkCols;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// 使用手动指定的字段
|
|
97
|
+
if ((options === null || options === void 0 ? void 0 : options.uniqueKeys) && options.uniqueKeys.length > 0) {
|
|
98
|
+
// 1. 使用手动指定的字段
|
|
100
99
|
pkCols = options.uniqueKeys;
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
103
|
-
// 使用实体的主键
|
|
102
|
+
// 2. 使用实体的主键
|
|
104
103
|
pkCols = repository.metadata
|
|
105
104
|
.primaryColumns.map((column) => column.propertyName);
|
|
106
105
|
}
|
|
107
106
|
// 如果没有主键也没有 uniqueKeys,使用简化逻辑
|
|
108
|
-
//
|
|
107
|
+
// 查询条件本身表示唯一性,只要存在记录就不允许
|
|
109
108
|
if (pkCols.length === 0) {
|
|
110
109
|
const count = yield repository.count({ where: defCon });
|
|
111
|
-
|
|
112
|
-
exists = count <= 1;
|
|
110
|
+
exists = count < 1;
|
|
113
111
|
return exists;
|
|
114
112
|
}
|
|
115
113
|
// 修复:检查是否为新建记录
|