Skip to content

Commit

Permalink
ICKY-263 (vercel#23)
Browse files Browse the repository at this point in the history
* ICKY-263

* resolve pr comments

* resolve pr comments for customer typescript
  • Loading branch information
kibo-geetanshuchhabra committed Oct 4, 2021
1 parent 8461ba0 commit e30888d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion framework/kibocommerce/api/endpoints/customer/customer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CookieHandler from '@framework/api/utils/cookie-handler'
import type { CustomerEndpoint } from '.'
import { getCustomerAccountQuery } from '../../queries/get-customer-account-query'
import { normalizeCustomer } from '../../../lib/normalize'

const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] = async ({
req,
Expand All @@ -17,7 +18,7 @@ const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
},
})

const customer = data?.customerAccount
const customer = normalizeCustomer(data?.customerAccount)

if (!customer.id) {
return res.status(400).json({
Expand Down
14 changes: 13 additions & 1 deletion framework/kibocommerce/lib/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// import { definitions } from '../api/definitions/store-content'
import update from './immutability'
import getSlug from './get-slug'
import { PrCategory } from '../schema'
import { PrCategory, CustomerAccountInput } from '../schema'
import { Page } from '@framework/types/page';
import { Customer } from '@framework/types/customer'

function normalizeProductOption(productOption: any) {
const {
Expand Down Expand Up @@ -101,6 +102,17 @@ export function normalizeCart(data: any): any {
}
}

export function normalizeCustomer(customer: CustomerAccountInput): Customer {
return {
id: customer.id,
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.emailAddress,
userName: customer.userName,
isAnonymous: customer.isAnonymous
}
}

function normalizeLineItem(item: any): any {
return {
id: item.id,
Expand Down
24 changes: 23 additions & 1 deletion framework/kibocommerce/types/customer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
import * as Core from '@commerce/types/customer'

export type Maybe<T> = T | null
export * from '@commerce/types/customer'
export type Scalars = {
ID: string
String: string
Boolean: boolean
Int: number
Float: number
/** The `AnyScalar` type allows any scalar value by examining the input and passing the serialize, parseValue, and parseLiteral operations to their respective types. */
AnyScalar: any
/** DateTime custom scalar type */
DateTime: any
/** Object custom scalar type */
Object: any
}

export type Customer = {
id: Scalars['Int'],
firstName?: Maybe<Scalars['String']>,
lastName?: Maybe<Scalars['String']>,
email?: Maybe<Scalars['String']>,
userName?: Maybe<Scalars['String']>,
isAnonymous?: Maybe<Scalars['Boolean']>
}

export type CustomerSchema = Core.CustomerSchema

0 comments on commit e30888d

Please sign in to comment.