backend/controller/transparency.js

32 lines
863 B
JavaScript
Raw Normal View History

2023-03-03 16:44:40 +00:00
const { PrismaClient } = require('@prisma/client')
2024-02-15 15:13:12 +00:00
const redis = require('../utils/redis.js')
2023-03-03 16:44:40 +00:00
const prisma = new PrismaClient()
exports.getReports = async (req, res) => {
2024-02-15 15:13:12 +00:00
let json
const cached = await redis.get('transparency')
if (cached) {
json = JSON.parse(cached)
} else {
json = (await prisma.reports.findMany()).map(r => {
return {
...r,
details: (r.details).split('<').join('&lt;').split('>').join('&gt;'),
date: (r.date).toISOString().slice(0,10)
}
})
await redis.set('transparency', JSON.stringify(json), 'EX', 3600)
}
res.json(json)
2023-03-03 16:44:40 +00:00
}
2024-03-15 17:11:12 +00:00
exports.getReports = async (req, res) => {
const reports = await prisma.reports.findMany({
2023-03-03 16:44:40 +00:00
where: {
target: req.params.id
}
})
2024-03-15 17:11:12 +00:00
res.json(reports)
2023-03-03 16:44:40 +00:00
}