Files
TurboHR/backend/scripts/check-beijing-social.ts
T
selfrelease 1d9890e607 fix: 创建年度标准时同effectiveFrom已存在则更新而非报错
问题:创建年度标准时如果该账户已有同 effectiveFrom 的标准,
会触发 P2002 唯一约束冲突,返回400"数据已存在"。

修复:先查是否已存在同 effectiveFrom 的标准,存在则更新,
不存在才创建新标准。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-08-16 15:48:21 +08:00

11 lines
740 B
TypeScript

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
const accounts = await prisma.socialAccount.findMany({ where: { type: 'SOCIAL', city: '北京' }, select: { id: true, name: true } })
for (const a of accounts) {
const std = await prisma.socialYearStandard.findFirst({ where: { accountId: a.id, isCurrent: true }, select: { medicalOrgExtra: true, medicalEmpExtra: true, extraInsurances: true, effectiveFrom: true } })
console.log(a.name + ' | effective=' + std?.effectiveFrom + ' | medicalOrgExtra=' + std?.medicalOrgExtra + ' | medicalEmpExtra=' + std?.medicalEmpExtra + ' | extraInsurances=' + JSON.stringify(std?.extraInsurances))
}
}
main().then(() => process.exit(0))