Browse Source

Temporary disable nodes (prisma)

mantine
cracklesparkle 5 months ago
parent
commit
59fded5cab
  1. 106
      ems/src/api/nodes/index.ts

106
ems/src/api/nodes/index.ts

@ -3,70 +3,70 @@ import { query, validationResult } from 'express-validator';
import { PrismaClient } from '@prisma/client';
const router = express.Router()
const prisma = new PrismaClient()
//const prisma = new PrismaClient()
router.get('/all', async (req: Request, res: Response) => {
try {
const nodes = await prisma.nodes.findMany()
// router.get('/all', async (req: Request, res: Response) => {
// try {
// const nodes = await prisma.nodes.findMany()
res.json(nodes)
} catch (error) {
console.error('Error getting node:', error);
res.status(500).json({ error: 'Failed to get node' });
}
})
// res.json(nodes)
// } catch (error) {
// console.error('Error getting node:', error);
// res.status(500).json({ error: 'Failed to get node' });
// }
// })
router.get('/', query('id').isString().isUUID(), async (req: Request, res: Response) => {
try {
const result = validationResult(req)
if (!result.isEmpty()) {
return res.send({ errors: result.array() })
}
// router.get('/', query('id').isString().isUUID(), async (req: Request, res: Response) => {
// try {
// const result = validationResult(req)
// if (!result.isEmpty()) {
// return res.send({ errors: result.array() })
// }
const { id } = req.params
// const { id } = req.params
const node = await prisma.nodes.findFirst({
where: {
id: id
}
})
// const node = await prisma.nodes.findFirst({
// where: {
// id: id
// }
// })
res.json(node)
// res.json(node)
} catch (error) {
console.error('Error getting node:', error);
res.status(500).json({ error: 'Failed to get node' });
}
})
// } catch (error) {
// console.error('Error getting node:', error);
// res.status(500).json({ error: 'Failed to get node' });
// }
// })
router.post('/', async (req: Request, res: Response) => {
try {
const { coordinates, object_id, type } = req.body;
// router.post('/', async (req: Request, res: Response) => {
// try {
// const { coordinates, object_id, type } = req.body;
// Convert the incoming array of coordinates into the shape structure
const shape = coordinates.map((point: number[]) => ({
object_id: object_id || null,
x: point[0],
y: point[1]
}));
// // Convert the incoming array of coordinates into the shape structure
// const shape = coordinates.map((point: number[]) => ({
// object_id: object_id || null,
// x: point[0],
// y: point[1]
// }));
console.log(shape)
// console.log(shape)
// Create a new node in the database
const node = await prisma.nodes.create({
data: {
object_id: object_id || null, // Nullable if object_id is not provided
shape_type: type, // You can adjust this dynamically
shape: shape, // Store the shape array as Json[]
label: 'Default'
}
});
// // Create a new node in the database
// const node = await prisma.nodes.create({
// data: {
// object_id: object_id || null, // Nullable if object_id is not provided
// shape_type: type, // You can adjust this dynamically
// shape: shape, // Store the shape array as Json[]
// label: 'Default'
// }
// });
res.status(201).json(node);
} catch (error) {
console.error('Error creating node:', error);
res.status(500).json({ error: 'Failed to create node' });
}
})
// res.status(201).json(node);
// } catch (error) {
// console.error('Error creating node:', error);
// res.status(500).json({ error: 'Failed to create node' });
// }
// })
export default router
Loading…
Cancel
Save