Browse Source

fix: new data apis throwExceptionIfNotExist logic

pull/6537/head
mertmit 1 year ago
parent
commit
307f143d9a
  1. 44
      packages/nocodb/src/db/BaseModelSqlv2.ts

44
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2886,17 +2886,27 @@ class BaseModelSqlv2 {
if (!raw) await this.validate(d);
const pkValues = await this._extractPksValues(d);
if (!pkValues) {
if (!pkValues) {
if (throwExceptionIfNotExist)
// throw or skip if no pk provided
if (throwExceptionIfNotExist) {
NcError.unprocessableEntity(
`Record with pk ${JSON.stringify(pkValues)} not found`,
);
}
continue;
}
if (!raw) {
const oldRecord = await this.readByPk(pkValues);
if (!oldRecord) {
// throw or skip if no record found
if (throwExceptionIfNotExist) {
NcError.unprocessableEntity(
`Record with pk ${JSON.stringify(pkValues)} not found`,
);
else {
continue;
}
continue;
}
prevData.push(oldRecord);
}
if (!raw) prevData.push(await this.readByPk(pkValues));
const wherePk = await this._wherePk(pkValues);
toBeUpdated.push({ d, wherePk });
updatePkValues.push(pkValues);
@ -3024,16 +3034,26 @@ class BaseModelSqlv2 {
for (const d of deleteIds) {
const pkValues = await this._extractPksValues(d);
if (!pkValues) {
// pk not specified - bypass
// throw or skip if no pk provided
if (throwExceptionIfNotExist) {
NcError.unprocessableEntity(
`Record with pk ${JSON.stringify(pkValues)} not found`,
);
}
continue;
}
const oldRecord = await this.readByPk(pkValues);
if (!oldRecord && throwExceptionIfNotExist)
NcError.unprocessableEntity(
`Record with pk ${JSON.stringify(pkValues)} not found`,
);
deleted.push(oldRecord);
const deletedRecord = await this.readByPk(pkValues);
if (!deletedRecord) {
// throw or skip if no record found
if (throwExceptionIfNotExist) {
NcError.unprocessableEntity(
`Record with pk ${JSON.stringify(pkValues)} not found`,
);
}
continue;
}
deleted.push(deletedRecord);
res.push(d);
}

Loading…
Cancel
Save