mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 07:26:59 +00:00
* Implement custom checkout core * Fix elements on core * Add files to providers * Adapt providers * Update types * Update shopify file * Format files
37 lines
900 B
TypeScript
37 lines
900 B
TypeScript
import type { CustomerSchema } from '../../../types/customer'
|
|
import type { GetAPISchema } from '../..'
|
|
|
|
import { CommerceAPIError } from '../../utils/errors'
|
|
import isAllowedOperation from '../../utils/is-allowed-operation'
|
|
|
|
const customerEndpoint: GetAPISchema<
|
|
any,
|
|
CustomerSchema<any>
|
|
>['endpoint']['handler'] = async (ctx) => {
|
|
const { req, res, handlers } = ctx
|
|
|
|
if (
|
|
!isAllowedOperation(req, res, {
|
|
GET: handlers['getLoggedInCustomer'],
|
|
})
|
|
) {
|
|
return
|
|
}
|
|
|
|
try {
|
|
const body = null
|
|
return await handlers['getLoggedInCustomer']({ ...ctx, body })
|
|
} catch (error) {
|
|
console.error(error)
|
|
|
|
const message =
|
|
error instanceof CommerceAPIError
|
|
? 'An unexpected error ocurred with the Commerce API'
|
|
: 'An unexpected error ocurred'
|
|
|
|
res.status(500).json({ data: null, errors: [{ message }] })
|
|
}
|
|
}
|
|
|
|
export default customerEndpoint
|