mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 16:25:53 +00:00
* create a jwt token if there is a customerId, move the get customer id to the main utils folder. Need to add in more value to the env file. Updated the env sample. * remove yarn.lock and tsconfig.json * remove build settings * remove build settings * remove build settings * Update tsconfig.json * Delete package-lock.json * fix typescript errors * Update tsconfig.json Co-authored-by: George Fitzgibbons <george.fitzgibbons@c02zw1aqlvdn.lan>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import type { Wishlist } from '../../../types/wishlist'
|
|
import type { WishlistEndpoint } from '.'
|
|
import getCustomerId from '../../utils/get-customer-id'
|
|
import getCustomerWishlist from '../../operations/get-customer-wishlist'
|
|
|
|
// Return wishlist info
|
|
const getWishlist: WishlistEndpoint['handlers']['getWishlist'] = async ({
|
|
res,
|
|
body: { customerToken, includeProducts },
|
|
config,
|
|
commerce,
|
|
}) => {
|
|
let result: { data?: Wishlist } = {}
|
|
|
|
if (customerToken) {
|
|
const customerId =
|
|
customerToken && (await getCustomerId({ customerToken, config }))
|
|
|
|
if (!customerId) {
|
|
// If the customerToken is invalid, then this request is too
|
|
return res.status(404).json({
|
|
data: null,
|
|
errors: [{ message: 'Wishlist not found' }],
|
|
})
|
|
}
|
|
|
|
const { wishlist } = await commerce.getCustomerWishlist({
|
|
variables: { customerId },
|
|
includeProducts,
|
|
config,
|
|
})
|
|
|
|
result = { data: wishlist }
|
|
}
|
|
|
|
res.status(200).json({ data: result.data ?? null })
|
|
}
|
|
|
|
export default getWishlist
|