diff --git a/src/api/channel/serviceChannel.ts b/src/api/channel/serviceChannel.ts index 3898be8..5a32178 100644 --- a/src/api/channel/serviceChannel.ts +++ b/src/api/channel/serviceChannel.ts @@ -95,6 +95,9 @@ export type ServiceChannelUpdatePayload = { preScript: string isActive: number remoteAreaId?: number | null + blacklistAreaId?: number | null + weightRuleId?: number | null + weightRoundingId?: number | null } export function buildServiceChannelUpdatePayload( @@ -112,6 +115,9 @@ export function buildServiceChannelUpdatePayload( | 'preScript' | 'isActive' | 'remoteAreaId' + | 'blacklistAreaId' + | 'weightRuleId' + | 'weightRoundingId' > > & { groupId?: number } ): ServiceChannelUpdatePayload { @@ -132,13 +138,17 @@ export function buildServiceChannelUpdatePayload( : isEnableStatusEnabled(activeRaw) ? ENABLE_STATUS.enabled : ENABLE_STATUS.disabled - const resolveRemoteAreaId = (): number | null => { - if (patch.remoteAreaId !== undefined) { - if (patch.remoteAreaId == null || patch.remoteAreaId === ('' as any)) return null - const n = Number(patch.remoteAreaId) + const resolveOptionalPositiveId = ( + patchVal: unknown, + detailCamel: string, + detailPascal: string + ): number | null => { + if (patchVal !== undefined) { + if (patchVal == null || patchVal === '') return null + const n = Number(patchVal) return Number.isFinite(n) && n > 0 ? n : null } - const raw = detail.remoteAreaId ?? detail.RemoteAreaId + const raw = detail[detailCamel] ?? detail[detailPascal] if (raw == null || raw === '') return null const n = Number(raw) return Number.isFinite(n) && n > 0 ? n : null @@ -157,7 +167,26 @@ export function buildServiceChannelUpdatePayload( description: str(patch.description ?? detail.description ?? detail.Description), preScript: str(patch.preScript ?? detail.preScript ?? detail.PreScript), isActive, - remoteAreaId: resolveRemoteAreaId(), + remoteAreaId: resolveOptionalPositiveId( + patch.remoteAreaId, + 'remoteAreaId', + 'RemoteAreaId' + ), + blacklistAreaId: resolveOptionalPositiveId( + patch.blacklistAreaId, + 'blacklistAreaId', + 'BlacklistAreaId' + ), + weightRuleId: resolveOptionalPositiveId( + patch.weightRuleId, + 'weightRuleId', + 'WeightRuleId' + ), + weightRoundingId: resolveOptionalPositiveId( + patch.weightRoundingId, + 'weightRoundingId', + 'WeightRoundingId' + ), } }