Files

28 lines
788 B
TypeScript
Raw Permalink Normal View History

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const counts = await prisma.order.groupBy({
by: ['status'],
_count: { _all: true },
where: { orderNumber: { startsWith: 'MOCK-ORD' } },
})
const total = counts.reduce((s, c) => s + c._count._all, 0)
const sample = await prisma.order.findFirst({
where: { orderNumber: { startsWith: 'MOCK-ORD' } },
select: {
orderNumber: true,
status: true,
customer: { select: { mobile: true, fullName: true } },
},
})
console.log(JSON.stringify({ total, byStatus: Object.fromEntries(counts.map((c) => [c.status, c._count._all])), sample }, null, 2))
await prisma.$disconnect()
}
main().catch((e) => {
console.error(e)
process.exit(1)
})