@stacksjs/cms 0.70.55 → 0.70.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -7
- package/src/authors/destroy.ts +0 -55
- package/src/authors/fetch.ts +0 -70
- package/src/authors/index.ts +0 -21
- package/src/authors/store.ts +0 -150
- package/src/authors/update.ts +0 -42
- package/src/build.ts +0 -1382
- package/src/categorizables/destroy.ts +0 -64
- package/src/categorizables/fetch.ts +0 -121
- package/src/categorizables/index.ts +0 -22
- package/src/categorizables/store.ts +0 -140
- package/src/categorizables/update.ts +0 -57
- package/src/commentables/destroy.ts +0 -64
- package/src/commentables/fetch.ts +0 -319
- package/src/commentables/index.ts +0 -25
- package/src/commentables/store.ts +0 -156
- package/src/commentables/update.ts +0 -75
- package/src/database.ts +0 -9
- package/src/index.ts +0 -42
- package/src/pages/destroy.ts +0 -64
- package/src/pages/fetch.ts +0 -82
- package/src/pages/index.ts +0 -21
- package/src/pages/store.ts +0 -42
- package/src/pages/update.ts +0 -39
- package/src/posts/destroy.ts +0 -90
- package/src/posts/fetch.ts +0 -82
- package/src/posts/index.ts +0 -25
- package/src/posts/store.ts +0 -213
- package/src/posts/update.ts +0 -46
- package/src/taggables/destroy.ts +0 -49
- package/src/taggables/fetch.ts +0 -282
- package/src/taggables/index.ts +0 -17
- package/src/taggables/store.ts +0 -122
- package/src/taggables/update.ts +0 -74
- package/src/tests/categorizables.test.ts +0 -66
- package/src/tests/setup.ts +0 -120
- /package/dist/{src/authors → authors}/destroy.d.ts +0 -0
- /package/dist/{src/authors → authors}/fetch.d.ts +0 -0
- /package/dist/{src/authors → authors}/index.d.ts +0 -0
- /package/dist/{src/authors → authors}/store.d.ts +0 -0
- /package/dist/{src/authors → authors}/update.d.ts +0 -0
- /package/dist/{src/categorizables → categorizables}/destroy.d.ts +0 -0
- /package/dist/{src/categorizables → categorizables}/fetch.d.ts +0 -0
- /package/dist/{src/categorizables → categorizables}/index.d.ts +0 -0
- /package/dist/{src/categorizables → categorizables}/store.d.ts +0 -0
- /package/dist/{src/categorizables → categorizables}/update.d.ts +0 -0
- /package/dist/{src/commentables → commentables}/destroy.d.ts +0 -0
- /package/dist/{src/commentables → commentables}/fetch.d.ts +0 -0
- /package/dist/{src/commentables → commentables}/index.d.ts +0 -0
- /package/dist/{src/commentables → commentables}/store.d.ts +0 -0
- /package/dist/{src/commentables → commentables}/update.d.ts +0 -0
- /package/dist/{src/database.d.ts → database.d.ts} +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/pages → pages}/destroy.d.ts +0 -0
- /package/dist/{src/pages → pages}/fetch.d.ts +0 -0
- /package/dist/{src/pages → pages}/index.d.ts +0 -0
- /package/dist/{src/pages → pages}/store.d.ts +0 -0
- /package/dist/{src/pages → pages}/update.d.ts +0 -0
- /package/dist/{src/posts → posts}/destroy.d.ts +0 -0
- /package/dist/{src/posts → posts}/fetch.d.ts +0 -0
- /package/dist/{src/posts → posts}/index.d.ts +0 -0
- /package/dist/{src/posts → posts}/store.d.ts +0 -0
- /package/dist/{src/posts → posts}/update.d.ts +0 -0
- /package/dist/{src/taggables → taggables}/destroy.d.ts +0 -0
- /package/dist/{src/taggables → taggables}/fetch.d.ts +0 -0
- /package/dist/{src/taggables → taggables}/index.d.ts +0 -0
- /package/dist/{src/taggables → taggables}/store.d.ts +0 -0
- /package/dist/{src/taggables → taggables}/update.d.ts +0 -0
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { getDb } from '../database'
|
|
2
|
-
import { fetchById } from './fetch'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Delete a category by ID
|
|
6
|
-
*
|
|
7
|
-
* @param id The ID of the category to delete
|
|
8
|
-
* @returns True if the deletion was successful, false otherwise
|
|
9
|
-
*/
|
|
10
|
-
export async function destroy(id: number): Promise<boolean> {
|
|
11
|
-
const db = await getDb()
|
|
12
|
-
try {
|
|
13
|
-
// First check if the category exists
|
|
14
|
-
const category = await fetchById(id)
|
|
15
|
-
|
|
16
|
-
if (!category) {
|
|
17
|
-
throw new Error(`Category with ID ${id} not found`)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Delete the category
|
|
21
|
-
const result = await db
|
|
22
|
-
.deleteFrom('categorizables')
|
|
23
|
-
.where('id', '=', id)
|
|
24
|
-
.executeTakeFirst()
|
|
25
|
-
|
|
26
|
-
return result.numDeletedRows > 0
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
if (error instanceof Error) {
|
|
30
|
-
throw new TypeError(`Failed to delete category: ${error.message}`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
throw error
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Bulk delete multiple categories
|
|
39
|
-
*
|
|
40
|
-
* @param ids Array of category IDs to delete
|
|
41
|
-
* @returns Number of categories successfully deleted
|
|
42
|
-
*/
|
|
43
|
-
export async function bulkDestroy(ids: number[]): Promise<number> {
|
|
44
|
-
const db = await getDb()
|
|
45
|
-
if (!ids.length)
|
|
46
|
-
return 0
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
// Delete all categories in the array
|
|
50
|
-
const result = await db
|
|
51
|
-
.deleteFrom('categorizables')
|
|
52
|
-
.where('id', 'in', ids)
|
|
53
|
-
.executeTakeFirst()
|
|
54
|
-
|
|
55
|
-
return Number(result.numDeletedRows) || 0
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
throw new TypeError(`Failed to delete categories in bulk: ${error.message}`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
throw error
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { CategorizableTable } from '@stacksjs/orm'
|
|
2
|
-
import { getDb } from '../database'
|
|
3
|
-
import { slugify } from 'ts-slug'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Fetch a category by ID
|
|
7
|
-
*/
|
|
8
|
-
export async function fetchById(id: number): Promise<CategorizableTable | undefined> {
|
|
9
|
-
const db = await getDb()
|
|
10
|
-
return await db
|
|
11
|
-
.selectFrom('categorizables')
|
|
12
|
-
.where('id', '=', id)
|
|
13
|
-
.where('is_active', '=', true)
|
|
14
|
-
.selectAll()
|
|
15
|
-
.executeTakeFirst() as unknown as CategorizableTable | undefined
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Fetch all categories
|
|
20
|
-
*/
|
|
21
|
-
export async function fetchAll(): Promise<CategorizableTable[]> {
|
|
22
|
-
const db = await getDb()
|
|
23
|
-
return await db.selectFrom('categorizables').selectAll().execute() as unknown as CategorizableTable[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Fetch categories by name
|
|
28
|
-
*/
|
|
29
|
-
export async function fetchByName(name: string): Promise<CategorizableTable[]> {
|
|
30
|
-
const db = await getDb()
|
|
31
|
-
return await db
|
|
32
|
-
.selectFrom('categorizables')
|
|
33
|
-
.where('name', '=', name)
|
|
34
|
-
.where('is_active', '=', true)
|
|
35
|
-
.selectAll()
|
|
36
|
-
.execute() as unknown as CategorizableTable[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Fetch category by slug
|
|
41
|
-
*/
|
|
42
|
-
export async function fetchBySlug(slug: string): Promise<CategorizableTable | undefined> {
|
|
43
|
-
const db = await getDb()
|
|
44
|
-
return await db
|
|
45
|
-
.selectFrom('categorizables')
|
|
46
|
-
.where('slug', '=', slug)
|
|
47
|
-
.where('is_active', '=', true)
|
|
48
|
-
.selectAll()
|
|
49
|
-
.executeTakeFirst() as unknown as CategorizableTable | undefined
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Fetch categories with posts
|
|
54
|
-
*/
|
|
55
|
-
export async function fetchWithPosts(id: number): Promise<CategorizableTable | undefined> {
|
|
56
|
-
const db = await getDb()
|
|
57
|
-
return await db
|
|
58
|
-
.selectFrom('categorizables')
|
|
59
|
-
.where('id', '=', id)
|
|
60
|
-
.where('is_active', '=', true)
|
|
61
|
-
.selectAll()
|
|
62
|
-
.executeTakeFirst() as unknown as CategorizableTable | undefined
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Find a category by name or create it if it doesn't exist
|
|
67
|
-
*
|
|
68
|
-
* @param name The name of the category to find or create
|
|
69
|
-
* @param categorizableType Type of the categorizable entity
|
|
70
|
-
* @param description Optional description for the category
|
|
71
|
-
* @returns The existing or newly created category
|
|
72
|
-
*/
|
|
73
|
-
export async function firstOrCreate(
|
|
74
|
-
name: string,
|
|
75
|
-
categorizableType: string,
|
|
76
|
-
description?: string,
|
|
77
|
-
): Promise<CategorizableTable> {
|
|
78
|
-
const db = await getDb()
|
|
79
|
-
try {
|
|
80
|
-
// First try to find the category by name
|
|
81
|
-
const existingCategory = await db
|
|
82
|
-
.selectFrom('categorizables')
|
|
83
|
-
.selectAll()
|
|
84
|
-
.where('name', '=', name)
|
|
85
|
-
.executeTakeFirst()
|
|
86
|
-
|
|
87
|
-
if (existingCategory) {
|
|
88
|
-
return existingCategory as unknown as CategorizableTable
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// If category doesn't exist, create it
|
|
92
|
-
const now = new Date()
|
|
93
|
-
const categoryData = {
|
|
94
|
-
name,
|
|
95
|
-
slug: slugify(name),
|
|
96
|
-
description,
|
|
97
|
-
is_active: true,
|
|
98
|
-
created_at: now.toDateString(),
|
|
99
|
-
categorizable_type: categorizableType,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const result = await db
|
|
103
|
-
.insertInto('categorizables')
|
|
104
|
-
.values(categoryData)
|
|
105
|
-
.returningAll()
|
|
106
|
-
.executeTakeFirst()
|
|
107
|
-
|
|
108
|
-
if (!result) {
|
|
109
|
-
throw new Error('Failed to create category')
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return result as unknown as CategorizableTable
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (error instanceof Error) {
|
|
116
|
-
throw new TypeError(`Failed to find or create category: ${error.message}`)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
throw error
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
bulkDestroy,
|
|
3
|
-
destroy,
|
|
4
|
-
} from './destroy'
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
fetchAll,
|
|
8
|
-
fetchById,
|
|
9
|
-
fetchByName,
|
|
10
|
-
fetchBySlug,
|
|
11
|
-
fetchWithPosts,
|
|
12
|
-
} from './fetch'
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
bulkStore,
|
|
16
|
-
store,
|
|
17
|
-
storeCategorizableModel,
|
|
18
|
-
} from './store'
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
update,
|
|
22
|
-
} from './update'
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import type { CategorizableModelsTable, CategorizableTable } from '@stacksjs/orm'
|
|
2
|
-
import { getDb } from '../database'
|
|
3
|
-
import { slugify } from 'ts-slug'
|
|
4
|
-
|
|
5
|
-
interface CategoryData {
|
|
6
|
-
name: string
|
|
7
|
-
description?: string
|
|
8
|
-
categorizable_type: string
|
|
9
|
-
is_active?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface CategorizableModelData {
|
|
13
|
-
category_id: number
|
|
14
|
-
categorizable_type: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Create a new category and its pivot table entry
|
|
19
|
-
*
|
|
20
|
-
* @param data The category data to create
|
|
21
|
-
* @returns The created category record
|
|
22
|
-
*/
|
|
23
|
-
export async function store(data: CategoryData): Promise<CategorizableTable> {
|
|
24
|
-
const db = await getDb()
|
|
25
|
-
try {
|
|
26
|
-
if (!data.name || data.name.trim() === '') {
|
|
27
|
-
throw new Error('Category name is required')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!data.categorizable_type || data.categorizable_type.trim() === '') {
|
|
31
|
-
throw new Error('Category categorizable_type is required')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const categoryData = {
|
|
35
|
-
name: data.name,
|
|
36
|
-
slug: slugify(data.name),
|
|
37
|
-
description: data.description,
|
|
38
|
-
categorizable_type: data.categorizable_type,
|
|
39
|
-
is_active: data.is_active ?? true,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const category = await db
|
|
43
|
-
.insertInto('categorizables')
|
|
44
|
-
.values(categoryData)
|
|
45
|
-
.returningAll()
|
|
46
|
-
.executeTakeFirst()
|
|
47
|
-
|
|
48
|
-
if (!category)
|
|
49
|
-
throw new Error('Failed to create category')
|
|
50
|
-
|
|
51
|
-
return category as unknown as CategorizableTable
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (error instanceof Error)
|
|
55
|
-
throw new TypeError(`Failed to create category: ${error.message}`)
|
|
56
|
-
|
|
57
|
-
throw error
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Create a new categorizable model relationship
|
|
63
|
-
*
|
|
64
|
-
* @param data The categorizable model data to create
|
|
65
|
-
* @returns The created categorizable model record
|
|
66
|
-
*/
|
|
67
|
-
export async function storeCategorizableModel(data: CategorizableModelData): Promise<CategorizableModelsTable> {
|
|
68
|
-
const db = await getDb()
|
|
69
|
-
try {
|
|
70
|
-
const modelData = {
|
|
71
|
-
category_id: data.category_id,
|
|
72
|
-
categorizable_type: data.categorizable_type,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const result = await db
|
|
76
|
-
.insertInto('categorizable_models')
|
|
77
|
-
.values(modelData)
|
|
78
|
-
.returningAll()
|
|
79
|
-
.executeTakeFirst()
|
|
80
|
-
|
|
81
|
-
if (!result)
|
|
82
|
-
throw new Error('Failed to create categorizable model relationship')
|
|
83
|
-
|
|
84
|
-
return result as unknown as CategorizableModelsTable
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
if (error instanceof Error)
|
|
88
|
-
throw new TypeError(`Failed to create categorizable model relationship: ${error.message}`)
|
|
89
|
-
|
|
90
|
-
throw error
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Create multiple categories and their pivot table entries in a single transaction
|
|
96
|
-
*
|
|
97
|
-
* @param data Array of category data to create
|
|
98
|
-
* @returns Array of created category records
|
|
99
|
-
*/
|
|
100
|
-
export async function bulkStore(data: CategoryData[]): Promise<CategorizableTable[]> {
|
|
101
|
-
const db = await getDb()
|
|
102
|
-
try {
|
|
103
|
-
// Start a transaction to ensure all inserts succeed or fail together
|
|
104
|
-
const results = await db.transaction(async (trx: any) => {
|
|
105
|
-
const categories: CategorizableTable[] = []
|
|
106
|
-
|
|
107
|
-
for (const item of data) {
|
|
108
|
-
const categoryData = {
|
|
109
|
-
name: item.name,
|
|
110
|
-
slug: slugify(item.name),
|
|
111
|
-
description: item.description,
|
|
112
|
-
categorizable_type: item.categorizable_type,
|
|
113
|
-
is_active: item.is_active ?? true,
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Insert into categorizable table
|
|
117
|
-
const category = await trx
|
|
118
|
-
.insertInto('categorizables')
|
|
119
|
-
.values(categoryData)
|
|
120
|
-
.returningAll()
|
|
121
|
-
.executeTakeFirst()
|
|
122
|
-
|
|
123
|
-
if (!category)
|
|
124
|
-
throw new Error(`Failed to create category: ${item.name}`)
|
|
125
|
-
|
|
126
|
-
categories.push(category as CategorizableTable)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return categories
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
return results
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (error instanceof Error)
|
|
136
|
-
throw new TypeError(`Failed to create categories: ${error.message}`)
|
|
137
|
-
|
|
138
|
-
throw error
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { CategorizableTable } from '@stacksjs/orm'
|
|
2
|
-
import { getDb } from '../database'
|
|
3
|
-
import { slugify } from 'ts-slug'
|
|
4
|
-
|
|
5
|
-
interface UpdateCategoryData {
|
|
6
|
-
id: number
|
|
7
|
-
name?: string
|
|
8
|
-
description?: string
|
|
9
|
-
categorizable_type?: string
|
|
10
|
-
is_active?: boolean
|
|
11
|
-
slug?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Update a category
|
|
16
|
-
*
|
|
17
|
-
* @param data The category data to update (must include id)
|
|
18
|
-
* @returns The updated category record
|
|
19
|
-
*/
|
|
20
|
-
export async function update(data: UpdateCategoryData): Promise<CategorizableTable> {
|
|
21
|
-
const db = await getDb()
|
|
22
|
-
try {
|
|
23
|
-
const id = data.id
|
|
24
|
-
|
|
25
|
-
if (!id) {
|
|
26
|
-
throw new Error('Category ID is required for update')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (data.name !== undefined) {
|
|
30
|
-
if (data.name.trim() === '') {
|
|
31
|
-
throw new Error('Category name cannot be empty')
|
|
32
|
-
}
|
|
33
|
-
data.slug = slugify(data.name)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Remove id from the data to avoid updating it
|
|
37
|
-
const { id: _id, ...updateData } = data
|
|
38
|
-
|
|
39
|
-
const result = await db
|
|
40
|
-
.updateTable('categorizables')
|
|
41
|
-
.set(updateData as unknown as Record<string, unknown>)
|
|
42
|
-
.where('id', '=', id)
|
|
43
|
-
.returningAll()
|
|
44
|
-
.executeTakeFirst()
|
|
45
|
-
|
|
46
|
-
if (!result)
|
|
47
|
-
throw new Error('Failed to update category')
|
|
48
|
-
|
|
49
|
-
return result as unknown as CategorizableTable
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
if (error instanceof Error)
|
|
53
|
-
throw new TypeError(`Failed to update category: ${error.message}`)
|
|
54
|
-
|
|
55
|
-
throw error
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { getDb } from '../database'
|
|
2
|
-
import { fetchCommentById } from './fetch'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Delete a comment by ID
|
|
6
|
-
*
|
|
7
|
-
* @param id The ID of the comment to delete
|
|
8
|
-
* @returns True if the deletion was successful, false otherwise
|
|
9
|
-
*/
|
|
10
|
-
export async function destroy(id: number): Promise<boolean> {
|
|
11
|
-
const db = await getDb()
|
|
12
|
-
try {
|
|
13
|
-
// First check if the comment exists
|
|
14
|
-
const comment = await fetchCommentById(id)
|
|
15
|
-
|
|
16
|
-
if (!comment) {
|
|
17
|
-
throw new Error(`Comment with ID ${id} not found`)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Delete the comment
|
|
21
|
-
const result = await db
|
|
22
|
-
.deleteFrom('commentables')
|
|
23
|
-
.where('id', '=', id)
|
|
24
|
-
.executeTakeFirst()
|
|
25
|
-
|
|
26
|
-
return result.numDeletedRows > 0
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
if (error instanceof Error) {
|
|
30
|
-
throw new TypeError(`Failed to delete comment: ${error.message}`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
throw error
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Bulk delete multiple comments
|
|
39
|
-
*
|
|
40
|
-
* @param ids Array of comment IDs to delete
|
|
41
|
-
* @returns Number of comments successfully deleted
|
|
42
|
-
*/
|
|
43
|
-
export async function bulkDestroy(ids: number[]): Promise<number> {
|
|
44
|
-
const db = await getDb()
|
|
45
|
-
if (!ids.length)
|
|
46
|
-
return 0
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
// Delete all comments in the array
|
|
50
|
-
const result = await db
|
|
51
|
-
.deleteFrom('commentables')
|
|
52
|
-
.where('id', 'in', ids)
|
|
53
|
-
.executeTakeFirst()
|
|
54
|
-
|
|
55
|
-
return Number(result.numDeletedRows) || 0
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
throw new TypeError(`Failed to delete comments in bulk: ${error.message}`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
throw error
|
|
63
|
-
}
|
|
64
|
-
}
|