mirror of
https://github.com/hcengineering/platform.git
synced 2025-03-26 09:47:28 +00:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
//
|
|
// Copyright @ 2024 Hardcore Engineering Inc.
|
|
//
|
|
|
|
import { generateId } from '@hcengineering/core'
|
|
import { getClient } from '@hcengineering/presentation'
|
|
import type { Question } from '@hcengineering/questions'
|
|
import { canUpdateQuestion, findPreviousQuestion, updateQuestion } from '../utils'
|
|
import { focusActionWithAvailability } from './ActionWithAvailability'
|
|
|
|
export const questionMoveUpAction = focusActionWithAvailability<Question<unknown>>(
|
|
async (object: Question<unknown>) => {
|
|
if (!canUpdateQuestion(object)) {
|
|
return false
|
|
}
|
|
const prevQuestion = await findPreviousQuestion(object)
|
|
return prevQuestion !== undefined
|
|
},
|
|
async (object: Question<unknown>) => {
|
|
const prevQuestion = await findPreviousQuestion(object)
|
|
if (prevQuestion === undefined) {
|
|
return
|
|
}
|
|
const ops = getClient().apply(generateId() + 'up')
|
|
await updateQuestion(ops, object, { rank: prevQuestion.rank })
|
|
await updateQuestion(ops, prevQuestion, { rank: object.rank })
|
|
await ops.commit()
|
|
}
|
|
)
|