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.
Files changed (2) hide show
  1. package/core/Repository.js +16 -4
  2. package/package.json +1 -1
@@ -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
- async update({ query, data }={}) {
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
- /** 根据ID更新,返回更新后完整数据(复用 update 走统一 applyQuery 校验) */
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.update({ query: { id }, data });
287
+ const res = await this.#updateRaw({ id }, data);
288
+ if (!res.success) return res;
277
289
  return this.findById(id);
278
290
  }
279
291
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chanjs",
4
- "version": "2.7.15",
4
+ "version": "2.7.16",
5
5
  "description": "chanjs基于 Node.js + Express 5 的标准 HMVC 框架(NHMVC),纯 JavaScript(ESM)开发。",
6
6
  "main": "index.js",
7
7
  "module": "index.js",