fix: filter analysis_summary in JS instead of Prisma WHERE clause
Prisma 5 rejects both null and Prisma.DbNull as WHERE filter values for Json? fields (no clean IS NOT NULL operator). Filter the result array in JS after the query — the output is immediately cached so this only runs once per cache period. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const router = require('express').Router();
|
||||
const { body } = require('express-validator');
|
||||
const { Prisma } = require('@prisma/client');
|
||||
const prisma = require('../lib/prisma');
|
||||
const cache = require('../lib/cache');
|
||||
const auditMiddleware = require('../middleware/auditMiddleware');
|
||||
@@ -373,11 +372,8 @@ router.get('/:id/daily-statuses', async (req, res, next) => {
|
||||
const next = new Date(d); next.setUTCDate(next.getUTCDate() + 1);
|
||||
where.date = { gte: d, lt: next };
|
||||
}
|
||||
if (analysisOnly) {
|
||||
where.NOT = { analysis_summary: Prisma.DbNull };
|
||||
}
|
||||
|
||||
const statuses = await prisma.dailyStatus.findMany({
|
||||
let statuses = await prisma.dailyStatus.findMany({
|
||||
where,
|
||||
select: {
|
||||
id: true,
|
||||
@@ -393,6 +389,12 @@ router.get('/:id/daily-statuses', async (req, res, next) => {
|
||||
orderBy: { date: 'asc' },
|
||||
});
|
||||
|
||||
// Prisma 5 has no clean IS NOT NULL filter for Json? fields; filter in JS.
|
||||
// The result is cached so this only runs once per cache period.
|
||||
if (analysisOnly) {
|
||||
statuses = statuses.filter((s) => s.analysis_summary !== null);
|
||||
}
|
||||
|
||||
cache.set(cacheKey, statuses);
|
||||
res.json(statuses);
|
||||
} catch (err) { next(err); }
|
||||
|
||||
Reference in New Issue
Block a user