2023-11-20 13:01:43 +03:00
|
|
|
import { type Doc, type Ref, type TxOperations } from '@hcengineering/core'
|
|
|
|
import { type Lead } from '@hcengineering/lead'
|
2022-06-25 20:32:31 +03:00
|
|
|
import lead from './plugin'
|
|
|
|
|
2023-12-11 14:54:36 +03:00
|
|
|
export async function getLeadTitle (client: TxOperations, ref: Ref<Doc>, doc?: Lead): Promise<string> {
|
|
|
|
const object = doc ?? (await client.findOne(lead.class.Lead, { _id: ref as Ref<Lead> }))
|
2022-06-25 20:32:31 +03:00
|
|
|
if (object === undefined) throw new Error(`Lead not found, _id: ${ref}`)
|
|
|
|
return `LEAD-${object.number}`
|
|
|
|
}
|
2024-02-21 07:52:19 +03:00
|
|
|
|
|
|
|
export async function getLeadId (client: TxOperations, ref: Ref<Lead>, doc?: Lead): Promise<string> {
|
|
|
|
const object = doc ?? (await client.findOne(lead.class.Lead, { _id: ref }))
|
|
|
|
if (object === undefined) throw new Error(`Lead not found, _id: ${ref}`)
|
|
|
|
return object.identifier
|
|
|
|
}
|