-
Notifications
You must be signed in to change notification settings - Fork 1
E-commerce App with Tensei #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Annysah
wants to merge
7
commits into
tenseijs:master
Choose a base branch
from
Annysah:feat/ecommerce
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aca1189
E-commerce App with Tensei
Annysah f6283b6
Updated files
Annysah 8e711ae
Files
Annysah 53c3f5c
Updated client files
Annysah 68543ef
setup stripe payment integration with tensei and react client
bahdcoder a997361
e-commerce application with react and tensei
Annysah cd963ae
Updated e-commerce application with react and tensei
Annysah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| node_modules | ||
| build | ||
| coverage | ||
| .vscode | ||
| .DS_STORE | ||
| .env | ||
| tmp |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "api", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "main": "server.ts", | ||
| "scripts": { | ||
| "dev": "npx tensei serve --watch", | ||
| "build": "npx tensei build --production", | ||
| "start": "node build/index.js" | ||
| }, | ||
| "devDependencies": { | ||
| "@tensei/cli": "^0.9.9", | ||
| "typescript": "^4.3.5" | ||
| }, | ||
| "dependencies": { | ||
| "@mikro-orm/sqlite": "^4.5.9", | ||
| "@tensei/auth": "^0.9.9", | ||
| "@tensei/core": "^0.9.9", | ||
| "@tensei/graphql": "^0.9.9", | ||
| "stripe": "^8.184.0" | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { Stripe } from 'stripe' | ||
| import { ProductModel } from '@tensei/orm' | ||
| import { auth } from '@tensei/auth' | ||
| import { graphql } from '@tensei/graphql' | ||
| import { welcome, tensei, cors, resource, text, textarea, integer, graphQlQuery } from '@tensei/core' | ||
|
|
||
| const stripe = new Stripe('sk_test_51JjsxtJnZnb1n2GnbebKQgYe73xTZtT1147z1dLFU9CGmkfbZKvcrW1VX4jA10Wav82slFIGjp9AW6puPURjibMP00z7Fw14Em', { | ||
| apiVersion: '2020-08-27' | ||
| }) | ||
|
|
||
| interface ProductCartItem { | ||
| productId: string | ||
| quantity: number | ||
| } | ||
|
|
||
| export default tensei() | ||
| .root(__dirname) | ||
| .graphQlTypeDefs([` | ||
| input ProductCartItem { | ||
| productId: ID | ||
| quantity: Int | ||
| } | ||
|
|
||
| extend type Mutation { | ||
| createPaymentIntent(productCartItems: [ProductCartItem]!): String! | ||
| } | ||
| `]) | ||
| .graphQlQueries([ | ||
| graphQlQuery('Create payment intent') | ||
| .path('createPaymentIntent') | ||
| .mutation() | ||
| .handle(async (src, args, ctx, info) => { | ||
| const products = await ctx.repositories.products().find({ | ||
| id: { | ||
| $in: ctx.body.productCartItems.map((item: ProductCartItem) => item.productId) | ||
| } | ||
| }) | ||
|
|
||
| const totalPrice = products.reduce((total: number, product: ProductModel) => total + (product.price), 0) | ||
|
|
||
| const paymentIntent = await stripe.paymentIntents.create({ | ||
| amount: totalPrice * 100, | ||
| currency: 'usd' | ||
| }) | ||
|
|
||
| return paymentIntent.client_secret | ||
| }) | ||
| ]) | ||
| .resources([ | ||
| resource('Product') | ||
| .fields([ | ||
| text('Image'), | ||
| text('Name'), | ||
| integer('Price'), | ||
| textarea('Description') | ||
| ]) | ||
| ]) | ||
| .plugins([ | ||
| welcome(), | ||
| auth().plugin(), | ||
| graphql().plugin(), | ||
| cors() | ||
| ]) | ||
| .start() | ||
| .catch(console.error) | ||
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "include": [ | ||
| "**/*" | ||
| ], | ||
| "moduleResolution": "node", | ||
| "exclude": [ | ||
| "node_modules", | ||
| "build" | ||
| ], | ||
| "compilerOptions": { | ||
| "outDir": "build", | ||
| "rootDir": "./", | ||
| "sourceMap": true, | ||
| "target": "ES2020", | ||
| "strict": true, | ||
| "baseUrl": "./", | ||
| "module": "commonjs", | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
process.env.STRIPE_SECREThere. The article should note that this key will be set in environment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted