33 lines
741 B
TypeScript
33 lines
741 B
TypeScript
import { Router } from 'express';
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
const router = Router();
|
|
const prisma = new PrismaClient();
|
|
|
|
// Get all tenants
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const tenants = await prisma.tenant.findMany({
|
|
include: { devices: true }
|
|
});
|
|
res.json(tenants);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
});
|
|
|
|
// Create tenant
|
|
router.post('/', async (req, res) => {
|
|
try {
|
|
const { name } = req.body;
|
|
const newTenant = await prisma.tenant.create({
|
|
data: { name },
|
|
});
|
|
res.status(201).json(newTenant);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Internal server error' });
|
|
}
|
|
});
|
|
|
|
export default router;
|