Skip to content

Commit

Permalink
refactor: improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavxc committed May 24, 2024
1 parent fb6058b commit 8f51e0a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/nocodb/src/meta/meta.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export class MetaService {

// Check if a condition is present in the query builder and throw an error if not.
if (!force) {
this.checkConditionPresent(query);
this.checkConditionPresent(query, 'delete');
}

return query.del();
Expand Down Expand Up @@ -717,7 +717,7 @@ export class MetaService {

// Check if a condition is present in the query builder and throw an error if not.
if (!force) {
this.checkConditionPresent(query);
this.checkConditionPresent(query, 'update');
}

return await query;
Expand Down Expand Up @@ -1197,7 +1197,10 @@ export class MetaService {
*
* @param queryBuilder - The Knex QueryBuilder instance to check.
*/
private checkConditionPresent(queryBuilder: Knex.QueryBuilder) {
private checkConditionPresent(
queryBuilder: Knex.QueryBuilder,
operation: 'delete' | 'update',
) {
// Convert the query builder to a SQL string to inspect the presence of a WHERE clause.
const sql = queryBuilder.toString();

Expand All @@ -1210,7 +1213,7 @@ export class MetaService {

// Throw an error if no condition is found in the query builder.
NcError.metaError({
message: 'Condition is required',
message: 'A condition is required to ' + operation + ' records.',
sql,
});
}
Expand Down

0 comments on commit 8f51e0a

Please sign in to comment.