mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-03 17:05:16 +03:00
UBERF-4843 Assign new employee to default HR organization (#4310)
Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
parent
800f846228
commit
a4e713af74
@ -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"
|
||||
|
@ -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: {
|
||||
|
@ -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<Tx[]> {
|
||||
const ctx = TxProcessor.extractTx(tx) as TxMixin<Person, Employee>
|
||||
|
||||
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,
|
||||
|
@ -28,6 +28,7 @@ export const serverHrId = 'server-hr' as Plugin
|
||||
*/
|
||||
export default plugin(serverHrId, {
|
||||
trigger: {
|
||||
OnEmployee: '' as Resource<TriggerFunc>,
|
||||
OnDepartmentStaff: '' as Resource<TriggerFunc>,
|
||||
OnDepartmentRemove: '' as Resource<TriggerFunc>,
|
||||
OnRequestCreate: '' as Resource<TriggerFunc>,
|
||||
|
Loading…
Reference in New Issue
Block a user