fix update

This commit is contained in:
xiaopeng 2025-03-30 16:06:43 +08:00
parent 69536b0da1
commit 671e148c27
5 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "8.0.2",
"version": "8.0.3",
"description": "cool-admin midway core",
"main": "dist/index.js",
"typings": "index.d.ts",

View File

@ -33,6 +33,7 @@ export enum ERRINFO {
NOENTITY = '未设置操作实体',
NOID = '查询参数[id]不存在',
SORTFIELD = '排序参数不正确',
NOTFOUND = '数据不存在~',
}
/**

View File

@ -309,7 +309,10 @@ export abstract class BaseMysqlService {
const upsert = this._coolConfig.crud?.upsert || 'normal';
if (type == 'update') {
if (upsert == 'save') {
const info = await this.entity.findOneBy({ id: param.id });
const info = await this.entity.findOneBy({ id: Equal(param.id) });
if (!info) {
throw new CoolValidateException(ERRINFO.NOTFOUND);
}
param = {
...info,
...param,

View File

@ -5,7 +5,7 @@ import { Application, Context } from '@midwayjs/koa';
import { Scope, ScopeEnum } from '@midwayjs/core';
import { CoolConfig } from '../interface';
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
import { Brackets, In, Repository, SelectQueryBuilder } from 'typeorm';
import { Brackets, Equal, In, Repository, SelectQueryBuilder } from 'typeorm';
import { QueryOp } from '../decorator/controller';
import * as _ from 'lodash';
import { CoolEventManager } from '../event';
@ -365,7 +365,10 @@ export abstract class BasePgService {
const upsert = this._coolConfig.crud?.upsert || 'normal';
if (type == 'update') {
if (upsert == 'save') {
const info = await this.entity.findOneBy({ id: param.id });
const info = await this.entity.findOneBy({ id: Equal(param.id) });
if (!info) {
throw new CoolValidateException(ERRINFO.NOTFOUND);
}
param = {
...info,
...param,

View File

@ -6,7 +6,7 @@ import { Application, Context } from '@midwayjs/koa';
import * as SqlString from 'sqlstring';
import { CoolConfig } from '../interface';
import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
import { Brackets, In, Repository, SelectQueryBuilder } from 'typeorm';
import { Brackets, Equal, In, Repository, SelectQueryBuilder } from 'typeorm';
import { QueryOp } from '../decorator/controller';
import * as _ from 'lodash';
import { CoolEventManager } from '../event';
@ -367,7 +367,10 @@ export abstract class BaseSqliteService {
const upsert = this._coolConfig.crud?.upsert || 'normal';
if (type == 'update') {
if (upsert == 'save') {
const info = await this.entity.findOneBy({ id: param.id });
const info = await this.entity.findOneBy({ id: Equal(param.id) });
if (!info) {
throw new CoolValidateException(ERRINFO.NOTFOUND);
}
param = {
...info,
...param,