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