Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove cost id from create quote metric #60

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed
- Removed cost center id from metrics

## [1.6.1] - 2024-06-20

### Fixed
Expand Down
28 changes: 7 additions & 21 deletions react/utils/metrics/createQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const GRAPHQL_URL = (accountName: string, workspace?: string) => {
}

type CreateQuoteFieldsMetric = {
cost_center_id: string
cost_center_name: string
buyer_org_id: string
buyer_org_name: string
Expand All @@ -38,24 +37,20 @@ type CreateQuoteMetric = Metric & { fields: CreateQuoteFieldsMetric }
const fetchMetricsData = async (
accountName: string,
workspace: string,
quoteId: string,
userEmail: string
quoteId: string
) => {
const query = JSON.stringify({
query: `query GetMetricsData($id: String, $email: String!) {
query: `query GetMetricsData($id: String) {
getQuote(id: $id) @context(provider: "vtex.b2b-quotes-graphql") {
organization
organizationName
costCenterName
referenceName
creatorRole
creationDate
},
getUserByEmail(email: $email) @context(provider: "vtex.storefront-permissions") {
costId
}
}`,
variables: { id: quoteId, email: userEmail },
}
}`,
variables: { id: quoteId },
})

const { data, errors } = (
Expand All @@ -67,13 +62,7 @@ const fetchMetricsData = async (
throw new Error('Graphql Errors when trying get quote and user data')
}

const quoteResult = data?.getQuote as Omit<QuoteMetricsData, 'costId'>
const costId = (data?.getUserByEmail?.[0].costId ?? '') as string

return {
...quoteResult,
costId,
}
return data?.getQuote as QuoteMetricsData
}

const buildCreateQuoteMetric = async (
Expand All @@ -85,8 +74,7 @@ const buildCreateQuoteMetric = async (
const metricsData = await fetchMetricsData(
metricsParam.account,
metricsParam.workspace,
metricsParam.quoteId,
userEmail
metricsParam.quoteId
)

const metric: CreateQuoteMetric = {
Expand All @@ -97,7 +85,6 @@ const buildCreateQuoteMetric = async (
fields: {
buyer_org_id: metricsData.organization,
buyer_org_name: metricsData.organizationName,
cost_center_id: metricsData.costId,
cost_center_name: metricsData.costCenterName,
member_id: namespaces?.profile?.id?.value,
member_email: userEmail,
Expand All @@ -115,7 +102,6 @@ const buildCreateQuoteMetric = async (
type QuoteMetricsData = {
organization: string // organizationId
organizationName: string
costId: string
costCenterName: string
referenceName: string // quote reference name
creatorRole: string
Expand Down
Loading