feat: add ABN existence check in createPayer function

This commit is contained in:
Astrian Zheng 2025-01-12 16:18:26 +11:00
parent 92a6b4275c
commit 2f57da4fa4
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -14,12 +14,15 @@ console.log = Debug('invoiceIssuer:func/createPayer.ts')
*/
export default async (prisma: PrismaClient, name: string, address: string[], email: string, abn?: string) => {
// 验证 ABN 是否已存在
const existingPayer = await prisma.payer.findFirst({
where: {
payer_abn: abn
}
})
if (existingPayer) throw new HttpError(ErrorDescEnum.item_exists, 400, ['abn'])
if (abn) {
console.log('Checking if ABN exists:', abn)
const existingPayer = await prisma.payer.findFirst({
where: {
payer_abn: abn
}
})
if (existingPayer) throw new HttpError(ErrorDescEnum.item_exists, 400, ['abn'])
}
// 创建新的付款人
const payer = await prisma.payer.create({