diff --git a/core/package.json b/core/package.json index 99e5854..1c94cf7 100644 --- a/core/package.json +++ b/core/package.json @@ -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", diff --git a/core/src/constant/global.ts b/core/src/constant/global.ts index c98329d..2d99a4f 100644 --- a/core/src/constant/global.ts +++ b/core/src/constant/global.ts @@ -33,6 +33,7 @@ export enum ERRINFO { NOENTITY = '未设置操作实体', NOID = '查询参数[id]不存在', SORTFIELD = '排序参数不正确', + NOTFOUND = '数据不存在~', } /** diff --git a/core/src/service/mysql.ts b/core/src/service/mysql.ts index 15eb65b..57da1cb 100644 --- a/core/src/service/mysql.ts +++ b/core/src/service/mysql.ts @@ -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, diff --git a/core/src/service/postgres.ts b/core/src/service/postgres.ts index 9ecbc85..6623cac 100644 --- a/core/src/service/postgres.ts +++ b/core/src/service/postgres.ts @@ -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, diff --git a/core/src/service/sqlite.ts b/core/src/service/sqlite.ts index 71442a2..2736551 100644 --- a/core/src/service/sqlite.ts +++ b/core/src/service/sqlite.ts @@ -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,