///
import {
ApiPayload,
CompassInsertMetricValueByExternalIdInput,
GqlError,
InsertMetricValueByExternalId,
MutationError,
SdkError,
} from '@atlassian/forge-graphql-types';
import { CompassRequests } from '../../compass-requests';
import {
mapGqlErrors,
mapMutationErrors,
parsingResponseError,
} from '../../helpers';
declare module '../../compass-requests' {
interface CompassRequests {
/**
* Inserts a metric value into every metric source that matches the provided
* definition ID and external ID.
*
* **Required Oauth Scopes:** `write:metric:compass`
*/
insertMetricValueByExternalId(
input: CompassInsertMetricValueByExternalIdInput,
): Promise;
}
}
CompassRequests.prototype.insertMetricValueByExternalId = async function (
this: CompassRequests,
input,
): Promise {
let gqlErrors: Array;
let mutationErrors: Array;
let errorsResp: Array = [];
let data;
try {
const resp = await this.api.requestGraph(
InsertMetricValueByExternalId,
{ input },
'insertMetricValueByExternalId',
);
({ errors: gqlErrors, data } = await resp.json());
errorsResp = errorsResp.concat(mapGqlErrors(gqlErrors));
({
insertMetricValueByExternalId: { errors: mutationErrors },
} = data.compass);
errorsResp = errorsResp.concat(mapMutationErrors(mutationErrors));
} catch (e) {
if (errorsResp.length === 0) {
errorsResp.push(parsingResponseError(e));
}
}
return {
errors: errorsResp,
success: errorsResp.length === 0,
};
};