-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,31 +13,24 @@ const action = async ( | |
req: Request, | ||
ctx: AppContext, | ||
): Promise<WishlistItem[]> => { | ||
const { vcs } = ctx; | ||
const { io } = ctx; | ||
const { cookie, payload } = parseCookie(req.headers, ctx.account); | ||
const user = payload?.sub; | ||
|
||
if (!user) { | ||
return []; | ||
} | ||
|
||
await vcs["POST /api/io/_v/private/graphql/v1"]({}, { | ||
body: { | ||
operationName: "AddToWishlist", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
listItem: props, | ||
}, | ||
query: | ||
`mutation AddToWishlist($listItem: ListItemInputType!, $shopperId: String!, $name: String!, $public: Boolean) { addToList(listItem: $listItem, shopperId: $shopperId, name: $name, public: $public) @context(provider: "[email protected]") }`, | ||
await io.query({ | ||
operationName: "AddToWishlist", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
listItem: props, | ||
}, | ||
headers: { | ||
"content-type": "application/json", | ||
accept: "application/json", | ||
cookie, | ||
}, | ||
}); | ||
query: | ||
`mutation AddToWishlist($listItem: ListItemInputType!, $shopperId: String!, $name: String!, $public: Boolean) { addToList(listItem: $listItem, shopperId: $shopperId, name: $name, public: $public) @context(provider: "[email protected]") }`, | ||
}, { headers: { cookie } }); | ||
|
||
return wishlistLoader({ count: Infinity }, req, ctx); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ const action = async ( | |
req: Request, | ||
ctx: AppContext, | ||
): Promise<WishlistItem[]> => { | ||
const { vcs } = ctx; | ||
const { io } = ctx; | ||
const { cookie, payload } = parseCookie(req.headers, ctx.account); | ||
const user = payload?.sub; | ||
const { id } = props; | ||
|
@@ -19,23 +19,16 @@ const action = async ( | |
return []; | ||
} | ||
|
||
await vcs["POST /api/io/_v/private/graphql/v1"]({}, { | ||
body: { | ||
operationName: "RemoveFromList", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
id, | ||
}, | ||
query: | ||
`mutation RemoveFromList($id: ID!, $shopperId: String!, $name: String) { removeFromList(id: $id, shopperId: $shopperId, name: $name) @context(provider: "[email protected]") }`, | ||
await io.query({ | ||
operationName: "RemoveFromList", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
id, | ||
}, | ||
headers: { | ||
"content-type": "application/json", | ||
accept: "application/json", | ||
cookie, | ||
}, | ||
}); | ||
query: | ||
`mutation RemoveFromList($id: ID!, $shopperId: String!, $name: String) { removeFromList(id: $id, shopperId: $shopperId, name: $name) @context(provider: "[email protected]") }`, | ||
}, { headers: { cookie } }); | ||
|
||
return wishlistLoader({ count: Infinity }, req, ctx); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ const loader = async ( | |
req: Request, | ||
ctx: AppContext, | ||
): Promise<WishlistItem[]> => { | ||
const { vcs } = ctx; | ||
const { io } = ctx; | ||
const url = new URL(req.url); | ||
const page = Number(url.searchParams.get("page")) || 0; | ||
const count = props.count || Infinity; | ||
|
@@ -28,28 +28,26 @@ const loader = async ( | |
} | ||
|
||
try { | ||
const { data } = await vcs["POST /api/io/_v/private/graphql/v1"]({}, { | ||
body: { | ||
operationName: "GetWithlist", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
}, | ||
query: | ||
`query GetWithlist($shopperId: String!, $name: String!, $from: Int, $to: Int) { viewList(shopperId: $shopperId, name: $name, from: $from, to: $to) @context(provider: "[email protected]") { name data { id productId sku title } } }`, | ||
const { viewList } = await io.query< | ||
{ viewList: { name?: string; data: WishlistItem[] } }, | ||
{ name: string; shopperId: string } | ||
>({ | ||
operationName: "GetWithlist", | ||
variables: { | ||
name: "Wishlist", | ||
shopperId: user, | ||
}, | ||
query: | ||
`query GetWithlist($shopperId: String!, $name: String!, $from: Int, $to: Int) { viewList(shopperId: $shopperId, name: $name, from: $from, to: $to) @context(provider: "[email protected]") { name data { id productId sku title } } }`, | ||
}, { | ||
headers: { | ||
"content-type": "application/json", | ||
accept: "application/json", | ||
cookie, | ||
}, | ||
}).then((res) => | ||
res.json() as { | ||
data?: { viewList: { name?: string; data: WishlistItem[] } }; | ||
} | ||
); | ||
}); | ||
|
||
return data?.viewList.data?.slice(count * page, count * (page + 1)) ?? []; | ||
return viewList.data?.slice(count * page, count * (page + 1)) ?? []; | ||
} catch { | ||
return []; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters