@nest-omni/core 4.1.3-7 → 4.1.3-9

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-omni/core",
3
- "version": "4.1.3-7",
3
+ "version": "4.1.3-9",
4
4
  "description": "A comprehensive NestJS framework for building enterprise-grade applications with best practices",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -92,10 +92,9 @@ let IsUniqueValidator = class IsUniqueValidator {
92
92
  let exists;
93
93
  const defCon = findCondition(args);
94
94
  // 获取用于判断是否为新建的字段
95
- // 优先级:手动配置的 uniqueKeys > 实体主键 > 查询条件的 keys
95
+ // 优先级:手动配置的 uniqueKeys > 实体主键
96
96
  let pkCols;
97
- const hasUniqueKeys = (options === null || options === void 0 ? void 0 : options.uniqueKeys) && options.uniqueKeys.length > 0;
98
- if (hasUniqueKeys) {
97
+ if ((options === null || options === void 0 ? void 0 : options.uniqueKeys) && options.uniqueKeys.length > 0) {
99
98
  // 1. 使用手动指定的字段
100
99
  pkCols = options.uniqueKeys;
101
100
  }
@@ -103,14 +102,17 @@ let IsUniqueValidator = class IsUniqueValidator {
103
102
  // 2. 使用实体的主键
104
103
  pkCols = repository.metadata
105
104
  .primaryColumns.map((column) => column.propertyName);
106
- // 3. 如果没有主键,从查询条件的 keys 中提取
107
- if (pkCols.length === 0 && defCon && typeof defCon === 'object') {
108
- pkCols = Object.keys(defCon);
109
- }
105
+ }
106
+ // 如果没有主键也没有 uniqueKeys,使用简化逻辑
107
+ // 查询条件本身表示唯一性,只要存在记录就不允许
108
+ if (pkCols.length === 0) {
109
+ const count = yield repository.count({ where: defCon });
110
+ exists = count < 1;
111
+ return exists;
110
112
  }
111
113
  // 修复:检查是否为新建记录
112
114
  // 如果所有 uniqueKeys/主键都没有值(null/undefined),则为新建
113
- const isNew = pkCols.length === 0 || !pkCols.some((pk) => {
115
+ const isNew = !pkCols.some((pk) => {
114
116
  const pkValue = args.object[pk];
115
117
  return pkValue !== null && pkValue !== undefined && pkValue !== '';
116
118
  });