Skip to content

Commit

Permalink
feat: RN04: Valor mínimo para transações é R$ 1,00.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Brasileiro authored and Fabio Brasileiro committed Sep 18, 2024
1 parent 5d51334 commit 7a6e04b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Api gateway pdv.
- [ ] RN01: Pagamento via PIX deve ser concluído em 30 minutos.
- [ ] RN02: Produtos com pagamentos pendentes não podem ser deletados.
- [ ] RN03: Pagamentos só podem ser feitos para produtos com estoque disponível.
- [ ] RN04: Valor mínimo para transações é R$ 1,00.
- [x] RN04: Valor mínimo para transações é R$ 1,00.
- [ ] RN05: Cada pagamento deve estar vinculado a um produto.
- [ ] RN06: Notificação por e-mail após compra.
- [ ] RN07: Preço de produto só pode ser atualizado sem pedidos pendentes.
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
"lint": "npx @biomejs/biome lint --write ./",
"lint:check": "npx @biomejs/biome check --write ./"
},
"keywords": [
"api",
"api gateway"
],
"keywords": ["api", "api gateway"],
"author": "fabio",
"license": "MIT",
"dependencies": {
Expand Down
7 changes: 5 additions & 2 deletions src/@types/PaymentData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface PaymentData {
// Defina a estrutura esperada para o paymentData aqui
amount: number
transaction_amount: number
description: string
payment_method_id: string
payer: {
email: string
}
// Adicione outros campos conforme necessário
}
3 changes: 1 addition & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ app.use(express.json())

app.use(cors())

app.get('/', (_req, res) => {
app.get('/', (_req, res) => {
res.send('🚀 Api next payment funcionando')
})

Expand All @@ -19,5 +19,4 @@ app.use('/api/products', productRoutes)
app.use('/api/payments', paymentRoutes)
app.use('/api', authRoutes) // Adicione '/api' como prefixo para as rotas de autenticação


export default app
10 changes: 8 additions & 2 deletions src/controllers/paymentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import * as paymentService from '../services/paymentService'
export const createPayment = async (req: Request, res: Response) => {
try {
const paymentData: PaymentData = req.body
console.log(req.body)

if (paymentData.transaction_amount < 1.0) {
return res.status(400).json('Valor deve ser maior que 1 real') // Added return here
}

console.log('🚀 ~ createPayment ~ paymentData:', paymentData)
const paymentResponse = await paymentService.createPayment(paymentData)
res.status(201).json(paymentResponse)
return res.status(201).json(paymentResponse) // Ensure you return after sending a response
} catch (error) {
res.status(400).json({ message: (error as Error).message })
return res.status(400).json({ message: (error as Error).message }) // Added return here too
}
}
4 changes: 1 addition & 3 deletions src/controllers/productController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as productService from '../services/productService'
import { uploadImage } from '../services/imgBbServices'
import axios from 'axios'


import imgbbUploader from 'imgbb-uploader'
export const createProduct = async (req: Request, res: Response) => {
try {
Expand All @@ -21,7 +20,7 @@ export const createProduct = async (req: Request, res: Response) => {
'https://api.imgbb.com/1/upload',
{
key: process.env.IMGBB_API_KEY, // Substitua pela sua chave de API
image: imageData
image: imageData,
},
{
headers: {
Expand All @@ -42,7 +41,6 @@ export const createProduct = async (req: Request, res: Response) => {
}
}


export const getProducts = async (req: Request, res: Response) => {
try {
const products = await productService.getProducts()
Expand Down
2 changes: 1 addition & 1 deletion src/services/imgBbServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const uploadImage = async (imagePath: string) => {
try {
const response = await imgbbUploader({
apiKey,
imagePath
imagePath,
})
return response.url
} catch (error) {
Expand Down

0 comments on commit 7a6e04b

Please sign in to comment.