refactor: use pluralize library for folder deletion error messages

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthew Rathbone
2026-02-24 13:54:47 -06:00
parent e4e6149b33
commit 25f5c9d398
4 changed files with 8 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import { Entity, Column, OneToMany, ManyToOne, JoinColumn, BeforeRemove } from 'typeorm'
import { ApplicationEntity } from './application_entity'
import { SavedConnection } from './saved_connection'
import pluralize from 'pluralize'
@Entity({ name: 'connection_folder' })
export class ConnectionFolder extends ApplicationEntity {
@@ -32,7 +33,7 @@ export class ConnectionFolder extends ApplicationEntity {
async preventRemoveIfNotEmpty(): Promise<void> {
const count = await SavedConnection.countBy({ connectionFolderId: this.id })
if (count > 0) {
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${count} connection${count === 1 ? '' : 's'} first.`)
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${pluralize('connection', count, true)} first.`)
}
}
}

View File

@@ -1,6 +1,7 @@
import { Entity, Column, OneToMany, ManyToOne, JoinColumn, BeforeRemove } from 'typeorm'
import { ApplicationEntity } from './application_entity'
import { FavoriteQuery } from './favorite_query'
import pluralize from 'pluralize'
@Entity({ name: 'query_folder' })
export class QueryFolder extends ApplicationEntity {
@@ -32,7 +33,7 @@ export class QueryFolder extends ApplicationEntity {
async preventRemoveIfNotEmpty(): Promise<void> {
const count = await FavoriteQuery.countBy({ queryFolderId: this.id })
if (count > 0) {
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${count} quer${count === 1 ? 'y' : 'ies'} first.`)
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${pluralize('query', count, true)} first.`)
}
}
}

View File

@@ -1,5 +1,6 @@
import Vue from 'vue'
import _ from 'lodash'
import pluralize from 'pluralize'
import { IConnectionFolder } from "@/common/interfaces/IQueryFolder";
import { DataState, DataStore, mutationsFor } from "@/store/modules/data/DataModuleBase";
import { safely } from "@/store/modules/data/StoreHelpers";
@@ -42,7 +43,7 @@ export const LocalConnectionFolderModule: DataStore<IConnectionFolder, State> =
async remove(context, folder) {
const items = await Vue.prototype.$util.send('appdb/saved/find', { options: { where: { connectionFolderId: folder.id } } })
if (items.length > 0) {
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${items.length} connection${items.length === 1 ? '' : 's'} first.`)
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${pluralize('connection', items.length, true)} first.`)
}
await Vue.prototype.$util.send('appdb/connectionFolder/remove', { obj: folder })
context.commit('remove', folder)

View File

@@ -1,5 +1,6 @@
import Vue from 'vue'
import _ from 'lodash'
import pluralize from 'pluralize'
import { IQueryFolder } from "@/common/interfaces/IQueryFolder";
import { DataState, DataStore, mutationsFor } from "@/store/modules/data/DataModuleBase";
import { safely } from "@/store/modules/data/StoreHelpers";
@@ -42,7 +43,7 @@ export const LocalQueryFolderModule: DataStore<IQueryFolder, State> = {
async remove(context, folder) {
const items = await Vue.prototype.$util.send('appdb/query/find', { options: { where: { queryFolderId: folder.id } } })
if (items.length > 0) {
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${items.length} quer${items.length === 1 ? 'y' : 'ies'} first.`)
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${pluralize('query', items.length, true)} first.`)
}
await Vue.prototype.$util.send('appdb/queryFolder/remove', { obj: folder })
context.commit('remove', folder)