feat: improve application access and money precision

This commit is contained in:
hectorzhao
2026-07-16 17:54:05 +08:00
parent 9d5c507007
commit faa716b8d0
49 changed files with 1699 additions and 489 deletions
+7 -2
View File
@@ -3,6 +3,7 @@ import { Queue } from 'bullmq';
import IORedis from 'ioredis';
import { Prisma } from '@prisma/client';
import { randomUUID } from 'crypto';
import { assertMoneyUnits, moneyToNumber } from '../common/money';
import { PrismaService } from '../prisma/prisma.service';
export interface CreateChannelDto {
@@ -230,6 +231,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
}
async createChannel(data: CreateChannelDto) {
assertMoneyUnits(data.unitPrice ?? 0, '通道单价');
const missingFields = ['code', 'name', 'gatewayHost', 'gatewayPort', 'account', 'passwordCipher', 'srcId'].filter((field) => {
const value = data[field as keyof CreateChannelDto];
return value === undefined || value === null || value === '';
@@ -275,6 +277,9 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
if (!channel) {
throw new NotFoundException('Channel not found');
}
if (data.unitPrice !== undefined) {
assertMoneyUnits(data.unitPrice, '通道单价');
}
const gatewayPort = data.gatewayPort === undefined ? undefined : Number(data.gatewayPort);
if (gatewayPort !== undefined && (!Number.isInteger(gatewayPort) || gatewayPort <= 0 || gatewayPort > 65535)) {
throw new BadRequestException('gatewayPort must be an integer between 1 and 65535');
@@ -323,7 +328,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
enterpriseCode: channel.enterpriseCode,
account: channel.account,
srcId: channel.srcId,
unitPrice: channel.unitPrice,
unitPrice: moneyToNumber(channel.unitPrice),
},
after: data,
} as Prisma.InputJsonValue,
@@ -502,7 +507,7 @@ export class ChannelsService implements OnModuleInit, OnModuleDestroy {
submitId,
submitStatus: 'queued',
costUnitPrice: channel.unitPrice,
costAmountCents: channel.unitPrice * messageRecord.billingUnits,
costAmountCents: moneyToNumber(channel.unitPrice) * messageRecord.billingUnits,
},
});
const command = buildChannelTestSubmitCommand({