Files
huly-platform/plugins/bitrix/src/hr.ts
T
2026-03-02 19:18:11 +07:00

73 lines
2.1 KiB
TypeScript

import { Organization } from '@hcengineering/contact'
import core, { PersonId, Client, Data, Doc, Ref, Status, TxOperations, generateId } from '@hcengineering/core'
import recruit, { Applicant, Vacancy } from '@hcengineering/recruit'
import task, { ProjectType } from '@hcengineering/task'
export async function createVacancy (
rawClient: Client,
name: string,
typeId: Ref<ProjectType>,
account: PersonId,
company?: Ref<Organization>
): Promise<Ref<Vacancy>> {
const client = new TxOperations(rawClient, account)
const type = await client.findOne(task.class.ProjectType, { _id: typeId })
if (type === undefined) {
throw Error(`Failed to find target project type: ${typeId}`)
}
const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Vacancy })
if (sequence === undefined) {
throw new Error('sequence object not found')
}
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
const id: Ref<Vacancy> = generateId()
await client.createDoc(
recruit.class.Vacancy,
core.space.Space,
{
name,
description: type.shortDescription ?? '',
fullDescription: null,
private: false,
archived: false,
company,
number: (incResult as any).object.sequence,
members: [],
type: typeId
},
id
)
// TODO type.description
return id
}
export async function createApplication (
client: TxOperations,
selectedState: Status,
_space: Ref<Vacancy>,
doc: Doc,
data: Data<Applicant>
): Promise<void> {
if (selectedState === undefined) {
throw new Error(`Please select initial state:${_space}`)
}
const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Applicant })
if (sequence === undefined) {
throw new Error('sequence object not found')
}
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
await client.addCollection(recruit.class.Applicant, _space, doc._id, recruit.mixin.Candidate, 'applications', {
...data,
status: selectedState._id,
number: (incResult as any).object.sequence,
rank: ''
})
}