From a4e713af747f96e1350e8a7fd02777d0e9995872 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Sat, 6 Jan 2024 20:26:58 +0700 Subject: [PATCH] UBERF-4843 Assign new employee to default HR organization (#4310) Signed-off-by: Alexander Onnikov --- models/server-hr/package.json | 1 + models/server-hr/src/index.ts | 9 ++++++++ server-plugins/hr-resources/src/index.ts | 26 +++++++++++++++++++++++- server-plugins/hr/src/index.ts | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/models/server-hr/package.json b/models/server-hr/package.json index cc618b4d64..59355999d9 100644 --- a/models/server-hr/package.json +++ b/models/server-hr/package.json @@ -29,6 +29,7 @@ "@hcengineering/model": "^0.6.7", "@hcengineering/platform": "^0.6.9", "@hcengineering/hr": "^0.6.12", + "@hcengineering/contact": "^0.6.20", "@hcengineering/server-notification": "^0.6.1", "@hcengineering/server-hr": "^0.6.0", "@hcengineering/server-core": "^0.6.1" diff --git a/models/server-hr/src/index.ts b/models/server-hr/src/index.ts index e95867458b..a0b2b2c281 100644 --- a/models/server-hr/src/index.ts +++ b/models/server-hr/src/index.ts @@ -15,6 +15,7 @@ import { type Builder } from '@hcengineering/model' +import contact from '@hcengineering/contact' import core from '@hcengineering/core' import hr from '@hcengineering/hr' import serverCore from '@hcengineering/server-core' @@ -68,6 +69,14 @@ export function createModel (builder: Builder): void { } }) + builder.createDoc(serverCore.class.Trigger, core.space.Model, { + trigger: serverHr.trigger.OnEmployee, + txMatch: { + _class: core.class.TxMixin, + mixin: contact.mixin.Employee + } + }) + builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverHr.trigger.OnPublicHolidayCreate, txMatch: { diff --git a/server-plugins/hr-resources/src/index.ts b/server-plugins/hr-resources/src/index.ts index 3dafcbf8ac..ca3e1d9a54 100644 --- a/server-plugins/hr-resources/src/index.ts +++ b/server-plugins/hr-resources/src/index.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import contact, { Contact, Employee, PersonAccount, formatName, getName } from '@hcengineering/contact' +import contact, { Contact, Employee, Person, PersonAccount, formatName, getName } from '@hcengineering/contact' import core, { Doc, Ref, @@ -190,6 +190,29 @@ export async function OnDepartmentRemove (tx: Tx, control: TriggerControl): Prom return res } +/** + * @public + */ +export async function OnEmployee (tx: Tx, control: TriggerControl): Promise { + const ctx = TxProcessor.extractTx(tx) as TxMixin + + const person = (await control.findAll(contact.class.Person, { _id: ctx.objectId }))[0] + if (person === undefined) { + return [] + } + + const employee = control.hierarchy.as(person, ctx.mixin) + if (control.hierarchy.hasMixin(person, hr.mixin.Staff) || !employee.active) { + return [] + } + + return [ + control.txFactory.createTxMixin(ctx.objectId, ctx.objectClass, ctx.objectSpace, hr.mixin.Staff, { + department: hr.ids.Head + }) + ] +} + /** * @public */ @@ -422,6 +445,7 @@ export async function PublicHolidayTextPresenter (doc: Doc, control: TriggerCont // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export default async () => ({ trigger: { + OnEmployee, OnRequestCreate, OnRequestUpdate, OnRequestRemove, diff --git a/server-plugins/hr/src/index.ts b/server-plugins/hr/src/index.ts index a9f4fd9270..8ee4a36dd4 100644 --- a/server-plugins/hr/src/index.ts +++ b/server-plugins/hr/src/index.ts @@ -28,6 +28,7 @@ export const serverHrId = 'server-hr' as Plugin */ export default plugin(serverHrId, { trigger: { + OnEmployee: '' as Resource, OnDepartmentStaff: '' as Resource, OnDepartmentRemove: '' as Resource, OnRequestCreate: '' as Resource,