fix tests
This commit is contained in:
@ -12,12 +12,22 @@ export interface BulkActionData {
|
||||
labelIds: string[]
|
||||
batchSize: number
|
||||
args?: unknown
|
||||
useFolders?: boolean
|
||||
}
|
||||
|
||||
export const BULK_ACTION_JOB_NAME = 'bulk-action'
|
||||
|
||||
export const bulkAction = async (data: BulkActionData) => {
|
||||
const { userId, action, query, labelIds, count, args, batchSize } = data
|
||||
const {
|
||||
userId,
|
||||
action,
|
||||
query,
|
||||
labelIds,
|
||||
count,
|
||||
args,
|
||||
batchSize,
|
||||
useFolders,
|
||||
} = data
|
||||
|
||||
const queue = await getBackendQueue()
|
||||
if (!queue) {
|
||||
@ -31,6 +41,7 @@ export const bulkAction = async (data: BulkActionData) => {
|
||||
size: batchSize,
|
||||
from: offset,
|
||||
query,
|
||||
useFolders,
|
||||
}
|
||||
|
||||
const searchResult = await searchLibraryItems(searchArgs, userId)
|
||||
|
||||
@ -879,15 +879,13 @@ export const bulkActionResolver = authorized<
|
||||
},
|
||||
})
|
||||
|
||||
const searchResult = await searchLibraryItems(
|
||||
{
|
||||
query,
|
||||
includePending: true,
|
||||
includeDeleted: true,
|
||||
useFolders: query.includes('use:folders'),
|
||||
},
|
||||
uid
|
||||
)
|
||||
const useFolders = query.includes('use:folders')
|
||||
const searchArgs = {
|
||||
query,
|
||||
size: 0,
|
||||
useFolders,
|
||||
}
|
||||
const searchResult = await searchLibraryItems(searchArgs, uid)
|
||||
const count = searchResult.count
|
||||
if (count === 0) {
|
||||
log.info('No items found for bulk action')
|
||||
@ -897,16 +895,7 @@ export const bulkActionResolver = authorized<
|
||||
const batchSize = 100
|
||||
if (count <= batchSize) {
|
||||
// if there are less than 100 items, update them synchronously
|
||||
await batchUpdateLibraryItems(
|
||||
action,
|
||||
{
|
||||
query,
|
||||
useFolders: query.includes('use:folders'),
|
||||
},
|
||||
uid,
|
||||
labelIds,
|
||||
args
|
||||
)
|
||||
await batchUpdateLibraryItems(action, searchArgs, uid, labelIds, args)
|
||||
|
||||
return { success: true }
|
||||
}
|
||||
@ -925,6 +914,7 @@ export const bulkActionResolver = authorized<
|
||||
count,
|
||||
args,
|
||||
batchSize,
|
||||
useFolders,
|
||||
}
|
||||
await queue.add(BULK_ACTION_JOB_NAME, data, {
|
||||
attempts: 1,
|
||||
|
||||
Reference in New Issue
Block a user