import { map } from 'rxjs/operators';
import { dataOrThrowErrors, gql, mutateGraphQL, queryGraphQL } from '../backend/graphql';
/**
 * Submits a user satisfaction survey.
 */
export function submitSurvey(input) {
    return mutateGraphQL(gql `
            mutation SubmitSurvey($input: SurveySubmissionInput!) {
                submitSurvey(input: $input) {
                    alwaysNil
                }
            }
        `, { input }).pipe(map(dataOrThrowErrors), map(() => undefined));
}
/**
 * Fetches survey responses.
 */
export function fetchAllSurveyResponses(args) {
    return queryGraphQL(gql `
            query FetchSurveyResponses() {
                surveyResponses {
                    nodes {
                        user {
                            id
                            username
                            emails {
                                email
                            }
                        }
                        email
                        score
                        reason
                        better
                        createdAt
                    }
                    totalCount
                }
            }
        `, Object.assign({}, args)).pipe(map(dataOrThrowErrors), map(data => data.surveyResponses));
}
/**
 * Fetches users, with their survey responses.
 */
export function fetchAllUsersWithSurveyResponses(args) {
    return queryGraphQL(gql `
            query FetchAllUsersWithSurveyResponses($activePeriod: UserActivePeriod, $first: Int, $query: String) {
                users(activePeriod: $activePeriod, first: $first, query: $query) {
                    nodes {
                        id
                        username
                        emails {
                            email
                        }
                        surveyResponses {
                            score
                            reason
                            better
                            createdAt
                        }
                        activity {
                            lastActiveTime
                        }
                    }
                    totalCount
                }
            }
        `, Object.assign({}, args)).pipe(map(dataOrThrowErrors), map(data => data.users));
}
/**
 * Fetches survey response aggregate data.
 */
export function fetchSurveyResponseAggregates() {
    return queryGraphQL(gql `
            query FetchSurveyResponseAggregates() {
                surveyResponses {
                    totalCount
                    last30DaysCount
                    averageScore
                    netPromoterScore
                }
            }
        `).pipe(map(dataOrThrowErrors), map(data => data.surveyResponses));
}
//# sourceMappingURL=backend.js.map