diff --git a/server-plugins/contact/src/utils.ts b/server-plugins/contact/src/utils.ts index b07ebafda7..4927edff6d 100644 --- a/server-plugins/contact/src/utils.ts +++ b/server-plugins/contact/src/utils.ts @@ -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> { - 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>((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 { const socialId = ( await control.findAll(control.ctx, contact.class.SocialIdentity, { _id: personId as SocialIdentityRef }) diff --git a/server-plugins/notification-resources/src/index.ts b/server-plugins/notification-resources/src/index.ts index 5a101544ef..ccb6223e7d 100644 --- a/server-plugins/notification-resources/src/index.ts +++ b/server-plugins/notification-resources/src/index.ts @@ -274,6 +274,11 @@ async function getValueCollaborators (value: any, attr: AnyAttribute, control: T if (arrOf._class === core.class.RefTo) { const to = (arrOf as RefTo).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