-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fabio Brasileiro
authored and
Fabio Brasileiro
committed
Oct 28, 2024
1 parent
ee6068f
commit 1c1dba6
Showing
7 changed files
with
66 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PrismaClient } from "@prisma/client" | ||
|
||
const prisma = new PrismaClient() | ||
|
||
// Novo controlador para listar todas as empresas e seus produtos | ||
export const getAllCompaniesWithProducts = async () => { | ||
return prisma.company.findMany({ | ||
include: { | ||
products: true, // Inclui os produtos associados a cada empresa | ||
}, | ||
}) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import express from 'express' | ||
import { getAllCompaniesWithProducts } from '@/controllers/getAllCompaniesWithProducts' | ||
|
||
const publicRouter = express.Router() | ||
|
||
// Rota pública para listar todas as empresas e seus produtos | ||
publicRouter.get('/companies', async (req, res) => { | ||
try { | ||
const companies = await getAllCompaniesWithProducts() | ||
res.status(200).json(companies) | ||
} catch (error) { | ||
console.error('Erro ao buscar empresas e produtos:', error) | ||
res.status(500).json({ message: 'Erro ao buscar empresas e produtos' }) | ||
} | ||
}) | ||
|
||
export default publicRouter |
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