diff --git a/api/src/storages/file.ts b/api/src/storages/file.ts index e25c905a..0d21586d 100644 --- a/api/src/storages/file.ts +++ b/api/src/storages/file.ts @@ -24,11 +24,16 @@ function getUserOrgas (organizations: StoredOrganization[], user: User) { for (const orga of organizations) { for (const member of orga.members) { if (member.id === user.id) { - userOrgas.push({ + const userOrga: Record = { ...member, id: orga.id, name: orga.name - }) + } + if (member.department) { + const dep = orga.departments?.find(d => d.id === member.department) + if (dep) userOrga.departmentName = dep.name + } + userOrgas.push(userOrga) } } } diff --git a/tests/features/file-storage.unit.spec.ts b/tests/features/file-storage.unit.spec.ts index 079598f9..854dcb59 100644 --- a/tests/features/file-storage.unit.spec.ts +++ b/tests/features/file-storage.unit.spec.ts @@ -44,4 +44,13 @@ test.describe('file storage interface', () => { assert.equal(res.organizations[0].name, 'Fivechat') assert.equal(res.organizations[0].role, 'admin') }) + + test('Resolve departmentName in user organizations', async () => { + const res = await storage.getUser('test_dhannan8') + assert.ok(res) + const ntag = res.organizations.find((o: any) => o.id === 'test_3sSi7xDIK') + assert.ok(ntag, 'user should be a member of Ntag') + assert.equal(ntag.department, 'dep1') + assert.equal(ntag.departmentName, 'Dep 1') + }) })