ai 'chat' is helping now
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m8s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m8s
This commit is contained in:
@@ -129,10 +129,11 @@ export async function findFlyerByChecksum(checksum: string): Promise<Flyer | und
|
||||
// prettier-ignore
|
||||
export async function createFlyerAndItems(
|
||||
flyerData: Omit<Flyer, 'flyer_id' | 'created_at' | 'store' | 'store_id'> & { store_name: string },
|
||||
items: Omit<FlyerItem, 'flyer_item_id' | 'flyer_id' | 'created_at'>[]
|
||||
items?: Omit<FlyerItem, 'flyer_item_id' | 'flyer_id' | 'created_at'>[]
|
||||
): Promise<Flyer> {
|
||||
const client = await getPool().connect();
|
||||
logger.debug('[DB createFlyerAndItems] Starting transaction to create flyer.', { flyerData: { name: flyerData.file_name, store_name: flyerData.store_name }, itemCount: items.length });
|
||||
const safeItems = items ?? [];
|
||||
logger.debug('[DB createFlyerAndItems] Starting transaction to create flyer.', { flyerData: { name: flyerData.file_name, store_name: flyerData.store_name }, itemCount: safeItems.length });
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
logger.debug('[DB createFlyerAndItems] BEGIN transaction successful.');
|
||||
@@ -167,7 +168,7 @@ export async function createFlyerAndItems(
|
||||
const newFlyer = newFlyerRes.rows[0];
|
||||
|
||||
// Prepare and insert all flyer items
|
||||
if (items.length > 0) {
|
||||
if (safeItems.length > 0) {
|
||||
const itemInsertQuery = `
|
||||
INSERT INTO public.flyer_items (
|
||||
flyer_id, item, price_display, price_in_cents, quantity,
|
||||
@@ -181,7 +182,7 @@ export async function createFlyerAndItems(
|
||||
// The query now directly calls the `suggest_master_item_for_flyer_item` function
|
||||
// on the database side, passing the item name (`item.item`) as the argument.
|
||||
// This is more efficient than making a separate DB call for each item to get the suggestion.
|
||||
for (const item of items) {
|
||||
for (const item of safeItems) {
|
||||
const itemValues = [
|
||||
newFlyer.flyer_id,
|
||||
item.item,
|
||||
|
||||
Reference in New Issue
Block a user