uberf-10222: add logging (#8709)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2025-04-25 15:38:17 +04:00 committed by GitHub
parent 8ec4ba968f
commit 26371196d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 23 deletions

View File

@ -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]
}
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> {
const socialId = (
await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef })

View File

@ -274,6 +274,11 @@ async function getValueCollaborators (value: any, attr: AnyAttribute, control: T
if (arrOf._class === core.class.RefTo) {
const to = (arrOf as RefTo<Doc>).to
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, {
_id: { $in: value },
active: true