mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 04:25:03 +02:00
Use tags for card labels (#1888)
This commit is contained in:
@@ -13,48 +13,5 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Tx, TxCreateDoc, TxRemoveDoc } from '@anticrm/core'
|
||||
import type { TriggerControl } from '@anticrm/server-core'
|
||||
import type { Card, CardLabel } from '@anticrm/board'
|
||||
import board from '@anticrm/board'
|
||||
import core, { TxProcessor } from '@anticrm/core'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function OnLabelDelete (tx: Tx, { findAll, hierarchy, txFactory }: TriggerControl): Promise<Tx[]> {
|
||||
if (tx._class !== core.class.TxRemoveDoc) {
|
||||
return []
|
||||
}
|
||||
|
||||
const rmTx = tx as TxRemoveDoc<CardLabel>
|
||||
if (!hierarchy.isDerived(rmTx.objectClass, board.class.CardLabel)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const createTx = (
|
||||
await findAll(
|
||||
core.class.TxCreateDoc,
|
||||
{
|
||||
objectId: rmTx.objectId
|
||||
},
|
||||
{ limit: 1 }
|
||||
)
|
||||
)[0]
|
||||
if (createTx === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
const label = TxProcessor.createDoc2Doc(createTx as TxCreateDoc<CardLabel>)
|
||||
const cards = await findAll<Card>(board.class.Card, { space: label.attachedTo as any, labels: label._id })
|
||||
return cards.map((card) =>
|
||||
txFactory.createTxUpdateDoc<Card>(card._class, card.space, card._id, { $pull: { labels: label._id as any } })
|
||||
)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export default async () => ({
|
||||
trigger: {
|
||||
OnLabelDelete
|
||||
}
|
||||
})
|
||||
export default async () => ({})
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Resource, Plugin } from '@anticrm/platform'
|
||||
import type { Plugin } from '@anticrm/platform'
|
||||
import { plugin } from '@anticrm/platform'
|
||||
import type { TriggerFunc } from '@anticrm/server-core'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -25,8 +24,4 @@ export const serverBoardId = 'server-board' as Plugin
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export default plugin(serverBoardId, {
|
||||
trigger: {
|
||||
OnLabelDelete: '' as Resource<TriggerFunc>
|
||||
}
|
||||
})
|
||||
export default plugin(serverBoardId, {})
|
||||
|
||||
Reference in New Issue
Block a user