Add paged orders API and infinite scroll, short order numbers, and align the guest invite card with the logged-in hero shell. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
/**
|
|
* Move all MOCK-ORD-* orders to a target customer mobile.
|
|
* Run: npx tsx scripts/reassign-mock-orders.ts
|
|
*/
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
const prisma = new PrismaClient()
|
|
const TARGET_MOBILE = process.env.MOCK_ORDERS_MOBILE?.trim() || '09382507041'
|
|
const TAG = 'MOCK-ORD'
|
|
|
|
async function main() {
|
|
const customer = await prisma.customer.findUnique({
|
|
where: { mobile: TARGET_MOBILE },
|
|
select: { id: true, mobile: true, fullName: true },
|
|
})
|
|
if (!customer) {
|
|
throw new Error(`Customer not found for mobile=${TARGET_MOBILE}`)
|
|
}
|
|
|
|
const before = await prisma.order.count({ where: { orderNumber: { startsWith: TAG } } })
|
|
const result = await prisma.order.updateMany({
|
|
where: { orderNumber: { startsWith: TAG } },
|
|
data: { customerId: customer.id },
|
|
})
|
|
|
|
const byStatus = await prisma.order.groupBy({
|
|
by: ['status'],
|
|
_count: { _all: true },
|
|
where: { orderNumber: { startsWith: TAG }, customerId: customer.id },
|
|
})
|
|
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
target: { mobile: customer.mobile, fullName: customer.fullName },
|
|
matched: before,
|
|
updated: result.count,
|
|
byStatus: Object.fromEntries(byStatus.map((c) => [c.status, c._count._all])),
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
)
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|