From 91a0cae6322eb6d3afe6473632cb94e9d6b98a34 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 1 Jul 2024 20:15:58 +0500 Subject: [PATCH] Minor hr fixes (#5972) --- models/hr/src/index.ts | 10 +++++----- models/server-hr/src/index.ts | 5 ++--- .../src/components/CreateDepartment.svelte | 3 ++- server-plugins/hr-resources/src/index.ts | 6 +++++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/models/hr/src/index.ts b/models/hr/src/index.ts index 9a0d2403e7..907e857fe3 100644 --- a/models/hr/src/index.ts +++ b/models/hr/src/index.ts @@ -341,7 +341,7 @@ export function createModel (builder: Builder): void { component: hr.component.CreateDepartment, element: 'top', fillProps: { - _id: 'space' + _id: 'parent' } }, label: hr.string.CreateDepartment, @@ -357,9 +357,9 @@ export function createModel (builder: Builder): void { createAction( builder, { - action: view.actionImpl.Archive, - label: view.string.Archive, - icon: view.icon.Archive, + action: view.actionImpl.Delete, + label: view.string.Delete, + icon: view.icon.Delete, input: 'any', category: hr.category.HR, keyBinding: ['Meta + Backspace'], @@ -369,7 +369,7 @@ export function createModel (builder: Builder): void { }, target: hr.class.Department, context: { mode: ['context', 'browser'], group: 'tools' }, - override: [view.action.Archive, view.action.Delete] + override: [view.action.Delete] }, hr.action.ArchiveDepartment ) diff --git a/models/server-hr/src/index.ts b/models/server-hr/src/index.ts index a0b2b2c281..321f7b2796 100644 --- a/models/server-hr/src/index.ts +++ b/models/server-hr/src/index.ts @@ -36,9 +36,8 @@ export function createModel (builder: Builder): void { builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverHr.trigger.OnDepartmentRemove, txMatch: { - _class: core.class.TxCollectionCUD, - 'tx.objectClass': hr.class.Department, - 'tx._class': core.class.TxRemoveDoc + objectClass: hr.class.Department, + _class: core.class.TxRemoveDoc } }) diff --git a/plugins/hr-resources/src/components/CreateDepartment.svelte b/plugins/hr-resources/src/components/CreateDepartment.svelte index b04ed70741..0d31a828fb 100644 --- a/plugins/hr-resources/src/components/CreateDepartment.svelte +++ b/plugins/hr-resources/src/components/CreateDepartment.svelte @@ -16,13 +16,14 @@ import { Employee } from '@hcengineering/contact' import { EmployeeBox } from '@hcengineering/contact-resources' import core, { Ref } from '@hcengineering/core' + import { Department } from '@hcengineering/hr' import { Card, getClient } from '@hcengineering/presentation' import { Button, EditBox, FocusHandler, createFocusManager } from '@hcengineering/ui' import { createEventDispatcher } from 'svelte' import hr from '../plugin' import DepartmentEditor from './DepartmentEditor.svelte' - export let parent = hr.ids.Head + export let parent: Ref = hr.ids.Head const dispatch = createEventDispatcher() diff --git a/server-plugins/hr-resources/src/index.ts b/server-plugins/hr-resources/src/index.ts index 7daf455672..a8c18a6b80 100644 --- a/server-plugins/hr-resources/src/index.ts +++ b/server-plugins/hr-resources/src/index.ts @@ -164,6 +164,11 @@ export async function OnDepartmentRemove (tx: Tx, control: TriggerControl): Prom const department = control.removedMap.get(ctx.objectId) as Department if (department === undefined) return [] + const res: Tx[] = [] + const nested = await control.findAll(hr.class.Department, { parent: department._id }) + for (const dep of nested) { + res.push(control.txFactory.createTxRemoveDoc(dep._class, dep.space, dep._id)) + } const targetAccounts = await control.modelDb.findAll(contact.class.PersonAccount, { _id: { $in: department.members } }) @@ -173,7 +178,6 @@ export async function OnDepartmentRemove (tx: Tx, control: TriggerControl): Prom _id: { $in: employeeIds } }) const removed = await buildHierarchy(department._id, control) - const res: Tx[] = [] employee.forEach((em) => { res.push(control.txFactory.createTxMixin(em._id, em._class, em.space, hr.mixin.Staff, { department: undefined })) })