-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhygraphService.js
75 lines (67 loc) · 1.86 KB
/
hygraphService.js
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
// import { request, gql, GraphQLClient } from 'graphql-request'
require('dotenv').config()
const graphql = require('graphql-request')
const requst = graphql.request
const GraphQLClient = graphql.GraphQLClient
const gql = graphql.gql
const myUrl = process.env.MY_URL
const authToken = process.env.AUTH_TOKEN
const graphClient = new GraphQLClient(myUrl, {
headers: { authorization: `Bearer ${authToken}` }
})
const fetchDoorFunc = async () => {
const FetchDoorQuery = gql`
query DoorAccounts {
doorAccountDetails {
id
doorId
userName
password
tempPassword
tempPasswordDateTime
email
}
}
`;
try {
const results = await requst(myUrl, FetchDoorQuery)
return results.doorAccountDetails
}
catch {
return "Error"
}
}
const updateDoorAccount = async (body) => {
const updateQuery = gql`
mutation gef($id:ID!,$tempPassword:String!,$tempPasswordDateTime:DateTime!){
updateDoorAccountDetail(where:{id:$id}data: {tempPassword:$tempPassword,tempPasswordDateTime:$tempPasswordDateTime}) {
id
userName
password
doorId
tempPassword
tempPasswordDateTime
email
}
}`
const publishQuery = gql`
mutation gef($id:ID!){
publishDoorAccountDetail(where:{id:$id},to:PUBLISHED){
id
password
userName
doorId
tempPassword
tempPasswordDateTime
}
}`
// try {
const result = await graphClient.request(updateQuery, body)
const publish = await graphClient.request(publishQuery, { 'id': body.id })
return publish.publishDoorAccountDetail
// }
// catch {
// return 'Error'
// }
}
module.exports = { fetchDoorFunc, updateDoorAccount }