maybe a few too many fixes
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Failing after 41s

This commit is contained in:
2025-12-28 21:38:31 -08:00
parent ba67ace190
commit 2e72ee81dd
40 changed files with 850 additions and 662 deletions

View File

@@ -148,6 +148,18 @@ router.get('/corrections', async (req, res, next: NextFunction) => {
}
});
router.get('/review/flyers', async (req, res, next: NextFunction) => {
try {
req.log.debug('Fetching flyers for review via adminRepo');
const flyers = await db.adminRepo.getFlyersForReview(req.log);
req.log.info({ count: Array.isArray(flyers) ? flyers.length : 'unknown' }, 'Successfully fetched flyers for review');
res.json(flyers);
} catch (error) {
logger.error({ error }, 'Error fetching flyers for review');
next(error);
}
});
router.get('/brands', async (req, res, next: NextFunction) => {
try {
const brands = await db.flyerRepo.getAllBrands(req.log);

View File

@@ -330,6 +330,12 @@ describe('AI Routes (/api/ai)', () => {
expect(response.status).toBe(201);
expect(response.body.message).toBe('Flyer processed and saved successfully.');
expect(mockedDb.createFlyerAndItems).toHaveBeenCalledTimes(1);
// Verify that the legacy endpoint correctly sets the status to 'needs_review'
expect(vi.mocked(mockedDb.createFlyerAndItems).mock.calls[0][0]).toEqual(
expect.objectContaining({
status: 'needs_review',
}),
);
});
it('should return 400 if no flyer image is provided', async () => {
@@ -383,6 +389,12 @@ describe('AI Routes (/api/ai)', () => {
expect(response.status).toBe(201);
expect(mockedDb.createFlyerAndItems).toHaveBeenCalledTimes(1);
// Verify that the legacy endpoint correctly sets the status to 'needs_review'
expect(vi.mocked(mockedDb.createFlyerAndItems).mock.calls[0][0]).toEqual(
expect.objectContaining({
status: 'needs_review',
}),
);
// verify the items array passed to DB was an empty array
const callArgs = vi.mocked(mockedDb.createFlyerAndItems).mock.calls[0]?.[1];
expect(callArgs).toBeDefined();
@@ -412,6 +424,12 @@ describe('AI Routes (/api/ai)', () => {
expect(response.status).toBe(201);
expect(mockedDb.createFlyerAndItems).toHaveBeenCalledTimes(1);
// Verify that the legacy endpoint correctly sets the status to 'needs_review'
expect(vi.mocked(mockedDb.createFlyerAndItems).mock.calls[0][0]).toEqual(
expect.objectContaining({
status: 'needs_review',
}),
);
// verify the flyerData.store_name passed to DB was the fallback string
const flyerDataArg = vi.mocked(mockedDb.createFlyerAndItems).mock.calls[0][0];
expect(flyerDataArg.store_name).toContain('Unknown Store');

View File

@@ -13,8 +13,8 @@ import {
handleMulterError,
} from '../middleware/multer.middleware';
import { generateFlyerIcon } from '../utils/imageProcessor';
import { logger } from '../services/logger.server';
import { UserProfile, ExtractedCoreData, ExtractedFlyerItem } from '../types';
import { logger } from '../services/logger.server'; // This was a duplicate, fixed.
import { UserProfile, ExtractedCoreData, ExtractedFlyerItem, FlyerInsert } from '../types';
import { flyerQueue } from '../services/queueService.server';
import { validateRequest } from '../middleware/validation.middleware';
import { requiredString } from '../utils/zodUtils';
@@ -437,7 +437,7 @@ router.post(
const iconUrl = `/flyer-images/icons/${iconFileName}`;
// 2. Prepare flyer data for insertion
const flyerData = {
const flyerData: FlyerInsert = {
file_name: originalFileName,
image_url: `/flyer-images/${req.file.filename}`, // Store the full URL path
icon_url: iconUrl,
@@ -448,6 +448,8 @@ router.post(
valid_to: extractedData.valid_to ?? null,
store_address: extractedData.store_address ?? null,
item_count: 0, // Set default to 0; the trigger will update it.
// Set a safe default status for this legacy endpoint. The new flow uses the transformer to determine this.
status: 'needs_review',
uploaded_by: userProfile?.user.user_id, // Associate with user if logged in
};