@things-factory/organization 6.0.6 → 6.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/organization",
3
- "version": "6.0.6",
3
+ "version": "6.0.8",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -30,9 +30,9 @@
30
30
  "@operato/data-tree": "^1.0.0",
31
31
  "@operato/graphql": "^1.0.0",
32
32
  "@operato/shell": "^1.0.0",
33
- "@things-factory/auth-base": "^6.0.5",
34
- "@things-factory/contact": "^6.0.6",
35
- "@things-factory/shell": "^6.0.5"
33
+ "@things-factory/auth-base": "^6.0.7",
34
+ "@things-factory/contact": "^6.0.8",
35
+ "@things-factory/shell": "^6.0.7"
36
36
  },
37
- "gitHead": "483b3f62690284db348d176ccc1b82825fda0c98"
37
+ "gitHead": "c883904927d790f21f9e821ddbb4b74be370040e"
38
38
  }
@@ -7,6 +7,17 @@ import { Employee } from './employee'
7
7
  import { EmployeeList } from './employee-type'
8
8
  import { Department } from '../department/department'
9
9
 
10
+ async function getContactItem(contactId: String, type: String, label: String, context: ResolverContext) {
11
+ const { domain } = context.state
12
+ const contact: Contact = await getRepository(Contact).findOne({ where: { domain: { id: domain.id }, id: contactId } })
13
+ const { items } = contact
14
+
15
+ if (!items || !(items instanceof Array)) {
16
+ return ''
17
+ }
18
+
19
+ return items?.find(item => item.type === type && item.label === label)?.value || ''
20
+ }
10
21
  @Resolver(Employee)
11
22
  export class EmployeeQuery {
12
23
  @Query(returns => Employee!, { nullable: true, description: 'To fetch a Employee' })
@@ -48,42 +59,30 @@ export class EmployeeQuery {
48
59
  }
49
60
 
50
61
  @FieldResolver(type => String)
51
- async phone(@Root() employee: Employee): Promise<string> {
62
+ async phone(@Root() employee: Employee, @Ctx() context: ResolverContext): Promise<string> {
52
63
  if (!employee.contactId) {
53
64
  return
54
65
  }
55
- const phone = (await getRepository(ContactItem).findOneBy({
56
- contact: { id: employee.contactId },
57
- type: ContactField.Phone,
58
- label: 'work'
59
- })) as any
60
- return phone?.value
66
+
67
+ await getContactItem(employee.contactId, ContactField.Phone, 'work', context)
61
68
  }
62
69
 
63
70
  @FieldResolver(type => String)
64
- async address(@Root() employee: Employee): Promise<string> {
71
+ async address(@Root() employee: Employee, @Ctx() context: ResolverContext): Promise<string> {
65
72
  if (!employee.contactId) {
66
73
  return
67
74
  }
68
- const address = (await getRepository(ContactItem).findOneBy({
69
- contact: { id: employee.contactId },
70
- type: ContactField.Address,
71
- label: 'work'
72
- })) as any
73
- return address?.value
75
+
76
+ await getContactItem(employee.contactId, ContactField.Address, 'work', context)
74
77
  }
75
78
 
76
79
  @FieldResolver(type => String)
77
- async email(@Root() employee: Employee): Promise<string> {
80
+ async email(@Root() employee: Employee, @Ctx() context: ResolverContext): Promise<string> {
78
81
  if (!employee.contactId) {
79
82
  return
80
83
  }
81
- const email = (await getRepository(ContactItem).findOneBy({
82
- contact: { id: employee.contactId },
83
- type: ContactField.Email,
84
- label: 'work'
85
- })) as any
86
- return email?.value
84
+
85
+ await getContactItem(employee.contactId, ContactField.Email, 'work', context)
87
86
  }
88
87
 
89
88
  @FieldResolver(type => Profile)
@@ -11,6 +11,9 @@ export class ObjectRefForEmployee extends ObjectRef {
11
11
  @Field({ nullable: true })
12
12
  controlNo?: string
13
13
 
14
+ @Field({ nullable: true })
15
+ photo?: string
16
+
14
17
  @Field({ nullable: true })
15
18
  email?: string
16
19
  }