Use tags for card labels (#1888)

This commit is contained in:
Alex
2022-05-27 23:43:11 +07:00
committed by GitHub
parent 4e69e4f0d1
commit a224a154e5
24 changed files with 214 additions and 341 deletions
+1 -44
View File
@@ -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 () => ({})
+2 -7
View File
@@ -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, {})