utils.js (hoppscotch-2.0.0) | : | utils.js (hoppscotch-2.1.0) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
* @param {ApolloClient<any>} apollo - Instance of ApolloClient | * @param {ApolloClient<any>} apollo - Instance of ApolloClient | |||
* @param {string} teamID - ID of the team to observe | * @param {string} teamID - ID of the team to observe | |||
* | * | |||
* @returns {{user: {uid: string, email: string}, role: 'OWNER' | 'EDITOR' | 'VI EWER'}} | * @returns {{user: {uid: string, email: string}, role: 'OWNER' | 'EDITOR' | 'VI EWER'}} | |||
*/ | */ | |||
export async function getLiveTeamMembersList(apollo, teamID) { | export async function getLiveTeamMembersList(apollo, teamID) { | |||
const subject = new BehaviorSubject([]) | const subject = new BehaviorSubject([]) | |||
const { data } = await apollo.query({ | const { data } = await apollo.query({ | |||
query: gql` | query: gql` | |||
query GetTeamMembers($teamID: String!) { | query GetTeamMembers($teamID: ID!) { | |||
team(teamID: $teamID) { | team(teamID: $teamID) { | |||
members { | members { | |||
user { | user { | |||
uid | uid | |||
} | } | |||
role | role | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 39 | skipping to change at line 39 | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
subject.next(data.team.members) | subject.next(data.team.members) | |||
const addedSub = apollo | const addedSub = apollo | |||
.subscribe({ | .subscribe({ | |||
query: gql` | query: gql` | |||
subscription TeamMemberAdded($teamID: String!) { | subscription TeamMemberAdded($teamID: ID!) { | |||
teamMemberAdded(teamID: $teamID) { | teamMemberAdded(teamID: $teamID) { | |||
user { | user { | |||
uid | uid | |||
} | } | |||
role | role | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
.subscribe(({ data }) => { | .subscribe(({ data }) => { | |||
subject.next([...subject.value, data.teamMemberAdded]) | subject.next([...subject.value, data.teamMemberAdded]) | |||
}) | }) | |||
const updateSub = apollo | const updateSub = apollo | |||
.subscribe({ | .subscribe({ | |||
query: gql` | query: gql` | |||
subscription TeamMemberUpdated($teamID: String!) { | subscription TeamMemberUpdated($teamID: ID!) { | |||
teamMemberUpdated(teamID: $teamID) { | teamMemberUpdated(teamID: $teamID) { | |||
user { | user { | |||
uid | uid | |||
} | } | |||
role | role | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
skipping to change at line 87 | skipping to change at line 87 | |||
) | ) | |||
if (!val) return | if (!val) return | |||
Object.assign(val, data.teamMemberUpdated) | Object.assign(val, data.teamMemberUpdated) | |||
}) | }) | |||
const removeSub = apollo | const removeSub = apollo | |||
.subscribe({ | .subscribe({ | |||
query: gql` | query: gql` | |||
subscription TeamMemberRemoved($teamID: String!) { | subscription TeamMemberRemoved($teamID: ID!) { | |||
teamMemberRemoved(teamID: $teamID) | teamMemberRemoved(teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
.subscribe(({ data }) => { | .subscribe(({ data }) => { | |||
subject.next( | subject.next( | |||
subject.value.filter( | subject.value.filter( | |||
skipping to change at line 137 | skipping to change at line 137 | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function addTeamMemberByEmail(apollo, userRole, userEmail, teamID) { | export function addTeamMemberByEmail(apollo, userRole, userEmail, teamID) { | |||
return apollo.mutate({ | return apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation addTeamMemberByEmail( | mutation addTeamMemberByEmail( | |||
$userRole: TeamMemberRole! | $userRole: TeamMemberRole! | |||
$userEmail: String! | $userEmail: String! | |||
$teamID: String! | $teamID: ID! | |||
) { | ) { | |||
addTeamMemberByEmail( | addTeamMemberByEmail( | |||
userRole: $userRole | userRole: $userRole | |||
userEmail: $userEmail | userEmail: $userEmail | |||
teamID: $teamID | teamID: $teamID | |||
) { | ) { | |||
role | role | |||
} | } | |||
} | } | |||
`, | `, | |||
skipping to change at line 161 | skipping to change at line 161 | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function updateTeamMemberRole(apollo, userID, newRole, teamID) { | export function updateTeamMemberRole(apollo, userID, newRole, teamID) { | |||
return apollo.mutate({ | return apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation updateTeamMemberRole( | mutation updateTeamMemberRole( | |||
$newRole: TeamMemberRole! | $newRole: TeamMemberRole! | |||
$userUid: String! | $userUid: ID! | |||
$teamID: String! | $teamID: ID! | |||
) { | ) { | |||
updateTeamMemberRole( | updateTeamMemberRole( | |||
newRole: $newRole | newRole: $newRole | |||
userUid: $userUid | userUid: $userUid | |||
teamID: $teamID | teamID: $teamID | |||
) { | ) { | |||
role | role | |||
} | } | |||
} | } | |||
`, | `, | |||
skipping to change at line 184 | skipping to change at line 184 | |||
newRole, | newRole, | |||
userUid: userID, | userUid: userID, | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function renameTeam(apollo, name, teamID) { | export function renameTeam(apollo, name, teamID) { | |||
return apollo.mutate({ | return apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation renameTeam($newName: String!, $teamID: String!) { | mutation renameTeam($newName: String!, $teamID: ID!) { | |||
renameTeam(newName: $newName, teamID: $teamID) { | renameTeam(newName: $newName, teamID: $teamID) { | |||
id | id | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
newName: name, | newName: name, | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export function removeTeamMember(apollo, userID, teamID) { | export function removeTeamMember(apollo, userID, teamID) { | |||
return apollo.mutate({ | return apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation removeTeamMember($userUid: String!, $teamID: String!) { | mutation removeTeamMember($userUid: ID!, $teamID: ID!) { | |||
removeTeamMember(userUid: $userUid, teamID: $teamID) | removeTeamMember(userUid: $userUid, teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
userUid: userID, | userUid: userID, | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export async function deleteTeam(apollo, teamID) { | export async function deleteTeam(apollo, teamID) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($teamID: String!) { | mutation ($teamID: ID!) { | |||
deleteTeam(teamID: $teamID) | deleteTeam(teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export function exitTeam(apollo, teamID) { | export function exitTeam(apollo, teamID) { | |||
return apollo.mutate({ | return apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($teamID: String!) { | mutation ($teamID: ID!) { | |||
leaveTeam(teamID: $teamID) | leaveTeam(teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export async function rootCollectionsOfTeam(apollo, teamID) { | export async function rootCollectionsOfTeam(apollo, teamID) { | |||
const collections = [] | const collections = [] | |||
let cursor = "" | let cursor = "" | |||
while (true) { | while (true) { | |||
const response = await apollo.query({ | const response = await apollo.query({ | |||
query: gql` | query: gql` | |||
query rootCollectionsOfTeam($teamID: String!, $cursor: String!) { | query rootCollectionsOfTeam($teamID: ID!, $cursor: ID!) { | |||
rootCollectionsOfTeam(teamID: $teamID, cursor: $cursor) { | rootCollectionsOfTeam(teamID: $teamID, cursor: $cursor) { | |||
id | id | |||
title | title | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
cursor, | cursor, | |||
}, | }, | |||
skipping to change at line 274 | skipping to change at line 274 | |||
}) | }) | |||
cursor = collections[collections.length - 1].id | cursor = collections[collections.length - 1].id | |||
} | } | |||
return collections | return collections | |||
} | } | |||
export async function getCollectionChildren(apollo, collectionID) { | export async function getCollectionChildren(apollo, collectionID) { | |||
const children = [] | const children = [] | |||
const response = await apollo.query({ | const response = await apollo.query({ | |||
query: gql` | query: gql` | |||
query getCollectionChildren($collectionID: String!) { | query getCollectionChildren($collectionID: ID!) { | |||
collection(collectionID: $collectionID) { | collection(collectionID: $collectionID) { | |||
children { | children { | |||
id | id | |||
title | title | |||
} | } | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
collectionID, | collectionID, | |||
skipping to change at line 300 | skipping to change at line 300 | |||
}) | }) | |||
return children | return children | |||
} | } | |||
export async function getCollectionRequests(apollo, collectionID) { | export async function getCollectionRequests(apollo, collectionID) { | |||
const requests = [] | const requests = [] | |||
let cursor = "" | let cursor = "" | |||
while (true) { | while (true) { | |||
const response = await apollo.query({ | const response = await apollo.query({ | |||
query: gql` | query: gql` | |||
query getCollectionRequests($collectionID: String!, $cursor: String) { | query getCollectionRequests($collectionID: ID!, $cursor: ID) { | |||
requestsInCollection(collectionID: $collectionID, cursor: $cursor) { | requestsInCollection(collectionID: $collectionID, cursor: $cursor) { | |||
id | id | |||
title | title | |||
request | request | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
collectionID, | collectionID, | |||
cursor, | cursor, | |||
skipping to change at line 332 | skipping to change at line 332 | |||
cursor = requests[requests.length - 1].id | cursor = requests[requests.length - 1].id | |||
} | } | |||
return requests | return requests | |||
} | } | |||
export async function renameCollection(apollo, title, id) { | export async function renameCollection(apollo, title, id) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($newTitle: String!, $collectionID: String!) { | mutation ($newTitle: String!, $collectionID: ID!) { | |||
renameCollection(newTitle: $newTitle, collectionID: $collectionID) { | renameCollection(newTitle: $newTitle, collectionID: $collectionID) { | |||
id | id | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
newTitle: title, | newTitle: title, | |||
collectionID: id, | collectionID: id, | |||
}, | }, | |||
}) | }) | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export async function updateRequest(apollo, request, requestName, requestID) { | export async function updateRequest(apollo, request, requestName, requestID) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($data: UpdateTeamRequestInput!, $requestID: String!) { | mutation ($data: UpdateTeamRequestInput!, $requestID: ID!) { | |||
updateRequest(data: $data, requestID: $requestID) { | updateRequest(data: $data, requestID: $requestID) { | |||
id | id | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
data: { | data: { | |||
request: JSON.stringify(request), | request: JSON.stringify(request), | |||
title: requestName, | title: requestName, | |||
}, | }, | |||
skipping to change at line 377 | skipping to change at line 377 | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export async function addChildCollection(apollo, title, id) { | export async function addChildCollection(apollo, title, id) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($childTitle: String!, $collectionID: String!) { | mutation ($childTitle: String!, $collectionID: ID!) { | |||
createChildCollection( | createChildCollection( | |||
childTitle: $childTitle | childTitle: $childTitle | |||
collectionID: $collectionID | collectionID: $collectionID | |||
) { | ) { | |||
id | id | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
childTitle: title, | childTitle: title, | |||
skipping to change at line 401 | skipping to change at line 401 | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export async function deleteCollection(apollo, id) { | export async function deleteCollection(apollo, id) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($collectionID: String!) { | mutation ($collectionID: ID!) { | |||
deleteCollection(collectionID: $collectionID) | deleteCollection(collectionID: $collectionID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
collectionID: id, | collectionID: id, | |||
}, | }, | |||
}) | }) | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export async function deleteRequest(apollo, requestID) { | export async function deleteRequest(apollo, requestID) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($requestID: String!) { | mutation ($requestID: ID!) { | |||
deleteRequest(requestID: $requestID) | deleteRequest(requestID: $requestID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
requestID, | requestID, | |||
}, | }, | |||
}) | }) | |||
if (response !== undefined) break | if (response !== undefined) break | |||
} | } | |||
return response | return response | |||
} | } | |||
export async function createNewRootCollection(apollo, title, id) { | export async function createNewRootCollection(apollo, title, id) { | |||
let response | let response | |||
while (true) { | while (true) { | |||
response = await apollo.mutate({ | response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($title: String!, $teamID: String!) { | mutation ($title: String!, $teamID: ID!) { | |||
createRootCollection(title: $title, teamID: $teamID) { | createRootCollection(title: $title, teamID: $teamID) { | |||
id | id | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
title, | title, | |||
teamID: id, | teamID: id, | |||
}, | }, | |||
}) | }) | |||
skipping to change at line 462 | skipping to change at line 462 | |||
export async function saveRequestAsTeams( | export async function saveRequestAsTeams( | |||
apollo, | apollo, | |||
request, | request, | |||
title, | title, | |||
teamID, | teamID, | |||
collectionID | collectionID | |||
) { | ) { | |||
const x = await apollo.mutate({ | const x = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation ($data: CreateTeamRequestInput!, $collectionID: String!) { | mutation ($data: CreateTeamRequestInput!, $collectionID: ID!) { | |||
createRequestInCollection(data: $data, collectionID: $collectionID) { | createRequestInCollection(data: $data, collectionID: $collectionID) { | |||
id | id | |||
collection { | collection { | |||
id | id | |||
team { | team { | |||
id | id | |||
name | name | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 490 | skipping to change at line 490 | |||
request, | request, | |||
}, | }, | |||
}, | }, | |||
}) | }) | |||
return x.data?.createRequestInCollection | return x.data?.createRequestInCollection | |||
} | } | |||
export async function overwriteRequestTeams(apollo, request, title, requestID) { | export async function overwriteRequestTeams(apollo, request, title, requestID) { | |||
await apollo.mutate({ | await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation updateRequest( | mutation updateRequest($data: UpdateTeamRequestInput!, $requestID: ID!) { | |||
$data: UpdateTeamRequestInput! | ||||
$requestID: String! | ||||
) { | ||||
updateRequest(data: $data, requestID: $requestID) { | updateRequest(data: $data, requestID: $requestID) { | |||
id | id | |||
title | title | |||
} | } | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
requestID, | requestID, | |||
data: { | data: { | |||
request, | request, | |||
skipping to change at line 515 | skipping to change at line 512 | |||
}, | }, | |||
}, | }, | |||
}) | }) | |||
} | } | |||
export async function importFromMyCollections(apollo, collectionID, teamID) { | export async function importFromMyCollections(apollo, collectionID, teamID) { | |||
const response = await apollo.mutate({ | const response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation importFromMyCollections( | mutation importFromMyCollections( | |||
$fbCollectionPath: String! | $fbCollectionPath: String! | |||
$teamID: String! | $teamID: ID! | |||
) { | ) { | |||
importCollectionFromUserFirestore( | importCollectionFromUserFirestore( | |||
fbCollectionPath: $fbCollectionPath | fbCollectionPath: $fbCollectionPath | |||
teamID: $teamID | teamID: $teamID | |||
) { | ) { | |||
id | id | |||
title | title | |||
} | } | |||
} | } | |||
`, | `, | |||
skipping to change at line 537 | skipping to change at line 534 | |||
fbCollectionPath: collectionID, | fbCollectionPath: collectionID, | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
return response.data != null | return response.data != null | |||
} | } | |||
export async function importFromJSON(apollo, collections, teamID) { | export async function importFromJSON(apollo, collections, teamID) { | |||
const response = await apollo.mutate({ | const response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation importFromJSON($jsonString: String!, $teamID: String!) { | mutation importFromJSON($jsonString: String!, $teamID: ID!) { | |||
importCollectionsFromJSON(jsonString: $jsonString, teamID: $teamID) | importCollectionsFromJSON(jsonString: $jsonString, teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
jsonString: JSON.stringify(collections), | jsonString: JSON.stringify(collections), | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
return response.data != null | return response.data != null | |||
} | } | |||
export async function replaceWithJSON(apollo, collections, teamID) { | export async function replaceWithJSON(apollo, collections, teamID) { | |||
const response = await apollo.mutate({ | const response = await apollo.mutate({ | |||
mutation: gql` | mutation: gql` | |||
mutation replaceWithJSON($jsonString: String!, $teamID: String!) { | mutation replaceWithJSON($jsonString: String!, $teamID: ID!) { | |||
replaceCollectionsWithJSON(jsonString: $jsonString, teamID: $teamID) | replaceCollectionsWithJSON(jsonString: $jsonString, teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
jsonString: JSON.stringify(collections), | jsonString: JSON.stringify(collections), | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
return response.data != null | return response.data != null | |||
} | } | |||
export async function exportAsJSON(apollo, teamID) { | export async function exportAsJSON(apollo, teamID) { | |||
const response = await apollo.query({ | const response = await apollo.query({ | |||
query: gql` | query: gql` | |||
query exportAsJSON($teamID: String!) { | query exportAsJSON($teamID: ID!) { | |||
exportCollectionsToJSON(teamID: $teamID) | exportCollectionsToJSON(teamID: $teamID) | |||
} | } | |||
`, | `, | |||
variables: { | variables: { | |||
teamID, | teamID, | |||
}, | }, | |||
}) | }) | |||
return response.data.exportCollectionsToJSON | return response.data.exportCollectionsToJSON | |||
} | } | |||
End of changes. 25 change blocks. | ||||
29 lines changed or deleted | 26 lines changed or added |