forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-personal.js
More file actions
84 lines (81 loc) · 2.78 KB
/
Copy pathuser-personal.js
File metadata and controls
84 lines (81 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import crypto from 'crypto'
import { GraphQLBoolean, GraphQLObjectType, GraphQLString } from 'graphql'
import { connectionArgs, globalIdField } from 'graphql-relay'
import { GraphQLEmailAddress, GraphQLPhoneNumber } from 'graphql-scalars'
import { affiliationConnection } from '../../affiliation/objects'
import { LanguageEnums, TfaSendMethodEnum } from '../../enums'
import { nodeInterface } from '../../node'
const { CIPHER_KEY } = process.env
export const userPersonalType = new GraphQLObjectType({
name: 'PersonalUser',
fields: () => ({
id: globalIdField('users'),
userName: {
type: GraphQLEmailAddress,
description: 'Users email address.',
resolve: ({ userName }) => userName,
},
displayName: {
type: GraphQLString,
description: 'Name displayed to other users.',
resolve: ({ displayName }) => displayName,
},
phoneNumber: {
type: GraphQLPhoneNumber,
description: 'The phone number the user has setup with tfa.',
resolve: ({ phoneDetails }) => {
if (typeof phoneDetails === 'undefined') { return null }
const { iv, tag, phoneNumber: encrypted } = phoneDetails
const decipher = crypto.createDecipheriv(
'aes-256-ccm',
String(CIPHER_KEY),
Buffer.from(iv, 'hex'),
{ authTagLength: 16 },
)
decipher.setAuthTag(Buffer.from(tag, 'hex'))
let decrypted = decipher.update(encrypted, 'hex', 'utf8')
decrypted += decipher.final('utf8')
return decrypted
},
},
preferredLang: {
type: LanguageEnums,
description: 'Users preferred language.',
resolve: ({ preferredLang }) => preferredLang,
},
phoneValidated: {
type: GraphQLBoolean,
description: 'Has the user completed phone validation.',
resolve: ({ phoneValidated }) => phoneValidated,
},
emailValidated: {
type: GraphQLBoolean,
description: 'Has the user email verified their account.',
resolve: ({ emailValidated }) => emailValidated,
},
tfaSendMethod: {
type: TfaSendMethodEnum,
description: 'The method in which TFA codes are sent.',
resolve: ({ tfaSendMethod }) => tfaSendMethod,
},
affiliations: {
type: affiliationConnection.connectionType,
description: 'Users affiliations to various organizations.',
args: connectionArgs,
resolve: async (
{ _id },
args,
{ loaders: { affiliationLoaderByUserId } },
) => {
const affiliations = await affiliationLoaderByUserId({
uId: _id,
...args,
})
return affiliations
},
},
}),
interfaces: [nodeInterface],
description: `This object is used for showing personal user details,
and is used for only showing the details of the querying user.`,
})