chanjs 2.7.15 → 2.7.16
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/core/Repository.js +16 -4
- package/package.json +1 -1
package/core/Repository.js
CHANGED
|
@@ -256,8 +256,14 @@ class Repository extends BaseComponent {
|
|
|
256
256
|
return { success:true, code:CODE_OK, msg:"删除成功", data:{ affectedRows:rows } };
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
/**
|
|
260
|
-
|
|
259
|
+
/**
|
|
260
|
+
* 更新内部原语(私有方法):子类无法覆写。
|
|
261
|
+
* 历史教训:此前 updateById 直接调 this.update({query,data}),
|
|
262
|
+
* 业务 Service 普遍以扁平 body 形状覆写 update(body),多态派发回子类后
|
|
263
|
+
* {query,data} 被解构成 id=undefined → 更新静默失效(无 SQL、仍返回旧数据)。
|
|
264
|
+
* 框架内部路径必须走本私有方法,杜绝该类命名冲突。
|
|
265
|
+
*/
|
|
266
|
+
async #updateRaw(query, data) {
|
|
261
267
|
this._checkDB();
|
|
262
268
|
if (!query || !data || !Object.keys(query).length || !Object.keys(data).length) {
|
|
263
269
|
return { success:false, code:CODE_PARAM_INVALID, msg:"参数无效", data:{} };
|
|
@@ -270,10 +276,16 @@ class Repository extends BaseComponent {
|
|
|
270
276
|
return { success:true, code:CODE_OK, msg:"更新成功", data:{ affectedRows:rows } };
|
|
271
277
|
}
|
|
272
278
|
|
|
273
|
-
/**
|
|
279
|
+
/** 按条件更新记录 */
|
|
280
|
+
async update({ query, data }={}) {
|
|
281
|
+
return this.#updateRaw(query, data);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** 根据ID更新,返回更新后完整数据;失败不再被忽略,直接透传错误体 */
|
|
274
285
|
async updateById(id, data={}) {
|
|
275
286
|
if (!id || !Object.keys(data).length) return { success:false, code:CODE_PARAM_INVALID, msg:"参数无效", data:{} };
|
|
276
|
-
await this
|
|
287
|
+
const res = await this.#updateRaw({ id }, data);
|
|
288
|
+
if (!res.success) return res;
|
|
277
289
|
return this.findById(id);
|
|
278
290
|
}
|
|
279
291
|
|