mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-11 18:01:59 +00:00
uberf-10222: add logging (#8709)
Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
parent
8ec4ba968f
commit
26371196d8
@ -102,29 +102,6 @@ export async function getPerson (control: TriggerControl, personId: PersonId): P
|
|||||||
return (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0]
|
return (await control.findAll(control.ctx, contact.class.Person, { _id: socialId.attachedTo }))[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPersonsBySocialIds (
|
|
||||||
control: TriggerControl,
|
|
||||||
personIds: PersonId[]
|
|
||||||
): Promise<Record<PersonId, Person>> {
|
|
||||||
const socialIds = await control.findAll(control.ctx, contact.class.SocialIdentity, {
|
|
||||||
_id: { $in: personIds as SocialIdentityRef[] }
|
|
||||||
})
|
|
||||||
const persons = toIdMap(
|
|
||||||
await control.findAll(control.ctx, contact.class.Person, { _id: { $in: socialIds.map((s) => s.attachedTo) } })
|
|
||||||
)
|
|
||||||
|
|
||||||
return socialIds.reduce<Record<PersonId, Person>>((acc, s) => {
|
|
||||||
const person = persons.get(s.attachedTo)
|
|
||||||
if (person !== undefined) {
|
|
||||||
acc[s._id] = person
|
|
||||||
} else {
|
|
||||||
console.error('No person found for social id', s.key)
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getEmployee (control: TriggerControl, personId: PersonId): Promise<Employee | undefined> {
|
export async function getEmployee (control: TriggerControl, personId: PersonId): Promise<Employee | undefined> {
|
||||||
const socialId = (
|
const socialId = (
|
||||||
await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef })
|
await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef })
|
||||||
|
@ -274,6 +274,11 @@ async function getValueCollaborators (value: any, attr: AnyAttribute, control: T
|
|||||||
if (arrOf._class === core.class.RefTo) {
|
if (arrOf._class === core.class.RefTo) {
|
||||||
const to = (arrOf as RefTo<Doc>).to
|
const to = (arrOf as RefTo<Doc>).to
|
||||||
if (hierarchy.isDerived(to, contact.class.Person)) {
|
if (hierarchy.isDerived(to, contact.class.Person)) {
|
||||||
|
if (value.length === 0) return []
|
||||||
|
if ((value as any[]).every((it) => it === null)) {
|
||||||
|
control.ctx.error('Null-values array of person refs when getting value collaborators', { attr, value })
|
||||||
|
}
|
||||||
|
|
||||||
const employees = await control.findAll(control.ctx, contact.mixin.Employee, {
|
const employees = await control.findAll(control.ctx, contact.mixin.Employee, {
|
||||||
_id: { $in: value },
|
_id: { $in: value },
|
||||||
active: true
|
active: true
|
||||||
|
Loading…
Reference in New Issue
Block a user