AI Product Description Generator
Module 22 · ai · intermediate
review.js
// The review queue: pending drafts first, with their issues.
const q = $('Review API').first().json.query ?? {};
const all = Object.values($getWorkflowStaticData('global').drafts ?? {});
const state = q.state || 'pending';
const list = all.filter((d) => state === 'all' || d.state === state)
.sort((a, b) => (a.status === b.status ? 0 : a.status === 'needs_review' ? -1 : 1));
const one = q.product_id ? all.find((d) => d.product_id === String(q.product_id)) : null;
return [{ json: q.product_id ? (one ? { found: true, ...one } : { found: false, product_id: q.product_id })
: { found: true, state, count: list.length, counts: all.reduce((m, d) => ({ ...m, [d.state]: (m[d.state] ?? 0) + 1 }), {}), drafts: list } }];