4
0
forked from crowetic/commerce

Added op to get the logged in customer

This commit is contained in:
Luis Alvarez
2020-10-21 09:53:19 -05:00
parent 377015ceac
commit 2aae613f1b
5 changed files with 83 additions and 95 deletions

View File

@@ -0,0 +1,44 @@
import { GetLoggedInCustomerQuery } from '@lib/bigcommerce/schema'
import type { CustomersHandlers } from '..'
export const getLoggedInCustomerQuery = /* GraphQL */ `
query getLoggedInCustomer {
customer {
entityId
firstName
lastName
email
company
customerGroupId
notes
phone
addressCount
attributeCount
storeCredit {
value
currencyCode
}
}
}
`
const getLoggedInCustomer: CustomersHandlers['getLoggedInCustomer'] = async ({
res,
config,
}) => {
const data = await config.fetch<GetLoggedInCustomerQuery>(
getLoggedInCustomerQuery
)
const { customer } = data
if (!customer) {
return res.status(400).json({
data: null,
errors: [{ message: 'Customer not found', code: 'not_found' }],
})
}
res.status(200).json({ data: { customer } })
}
export default getLoggedInCustomer