- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14) - T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9) - T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4) - T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8) - T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15) - T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8) - T7 前后端测试与 lint 门禁清零 - T8 应付卡片按关联订单日(口径 A) - T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
509 lines
20 KiB
TypeScript
509 lines
20 KiB
TypeScript
/**
|
||
* 主系统竞价:**我方只报价、不定标**——页面用到的读/写业务逻辑都在这里。
|
||
*
|
||
* 三件事:
|
||
* ① `listBidInvitations` 读**本地镜像**(页面首屏,不调外部,不会被主系统抖动拖住);
|
||
* ② `syncBidInvitations` 拉对方 `GET /api/supplier/bids` 兜底补台账(对方 webhook 只重试 2 次);
|
||
* ③ `refreshBidInvitation` / `submitBidQuotes` 单轮对齐 + 提交报价(唯一写主系统的地方)。
|
||
*
|
||
* 纪律:
|
||
* · 提交前的本地校验只为**少发一次注定失败的请求**,最终裁决权在主系统:
|
||
* 对方返回的 `bid_not_open` / `quote_deadline_passed` / `supplier_category_mismatch` 一律照实映射;
|
||
* · 提交失败**不改本地报价**(避免"以为报上了");只有对方返回成功视图才整轮 upsert;
|
||
* · 我方错误码与对方错误码**同形**(`error` 字段),前端只认一套。
|
||
*
|
||
* 设计文档:docs/design/20261017-主系统竞价待报价与报价提交.md
|
||
*/
|
||
import {
|
||
applyBidDetail,
|
||
findInvitationByRound,
|
||
getBidInvitationDetail,
|
||
listInvitationRows,
|
||
markInvitationCancelled,
|
||
markInvitationSyncError,
|
||
toBidInvitationDto,
|
||
upsertInvitationHeaders,
|
||
type BidInvitationDetailDto,
|
||
} from './mainSystemBidInbox';
|
||
import {
|
||
getMainSupplierBidDetail,
|
||
listMainSupplierBids,
|
||
submitMainSupplierBidQuotes,
|
||
type MainBidFailure,
|
||
type MainSupplierBidDetail,
|
||
} from './mainSystem/api/bids';
|
||
import { listSupplierCodesForBranch } from './mainSystemBranchApi';
|
||
|
||
/** 界面文案的**唯一**映射表(对方错误码 → 中文提示;我方错误码同表) */
|
||
export const BID_ERROR_COPY: Record<string, string> = {
|
||
// ── 对方错误码(契约 §2.3)──
|
||
bid_not_open: '本轮已结束报价,无法提交',
|
||
quote_deadline_passed: '已超过报价截止时间,本轮已出局',
|
||
supplier_category_mismatch: '该商品不在你的经营品类内,无法报价',
|
||
bid_disabled: '对方未开启竞价功能',
|
||
not_found: '竞价单不存在或已被取消',
|
||
forbidden: '无权查看本轮竞价',
|
||
unauthorized: '对方登录凭据已失效,请稍后重试',
|
||
main_system_error: '对方系统暂不可用,请稍后重试',
|
||
request_failed: '提交报价失败,请稍后重试',
|
||
// ── 我方错误码 ──
|
||
bid_invitation_not_found: '本地没有这轮竞价的记录,请先点「同步」',
|
||
bid_invitation_deleted: '该竞价邀约已被删除,无法再报价(管理员可在「显示已删除」里恢复)',
|
||
quotes_required: '请至少填写一条报价',
|
||
invalid_unit_price: '报价必须是大于 0 且最多 4 位小数的数字',
|
||
sku_not_in_round: '该商品不在本轮竞价的商品清单里,请先刷新',
|
||
main_system_unavailable: '对方系统暂不可用,请稍后重试',
|
||
invalid_main_system_response: '对方返回的数据无法识别(缺少轮次/明细),本次未落库,请稍后重试',
|
||
main_system_not_configured: '主系统对接未配置,无法提交报价',
|
||
branch_required: '当前账号未绑定分公司',
|
||
};
|
||
|
||
export function bidErrorCopy(code: string, fallback?: string | null): string {
|
||
const key = String(code || '').trim();
|
||
if (key && BID_ERROR_COPY[key]) return BID_ERROR_COPY[key];
|
||
const text = String(fallback || '').trim();
|
||
return text || BID_ERROR_COPY.request_failed;
|
||
}
|
||
|
||
export type BidFailure = {
|
||
kind: 'rejected' | 'unavailable' | 'not_configured';
|
||
status: number;
|
||
code: string;
|
||
message: string;
|
||
};
|
||
|
||
export type BidListOutcome = {
|
||
rows: ReturnType<typeof toBidInvitationDto>[];
|
||
summary: {
|
||
pending: number;
|
||
quoted: number;
|
||
expired: number;
|
||
closed: number;
|
||
won: number;
|
||
lost: number;
|
||
cancelled: number;
|
||
};
|
||
};
|
||
|
||
export type BidSyncOutcome = {
|
||
synced: number;
|
||
skipped: number;
|
||
unavailable: number;
|
||
/** 对方竞价开关是否开启(false ⇒ 对方没开竞价,我方清单只会是空的/旧的) */
|
||
enabled: boolean;
|
||
/** 该分公司有没有可出站的供应商编码(未绑定接入编码 ⇒ 一个请求都不会发) */
|
||
bound: boolean;
|
||
};
|
||
|
||
export type BidDetailOutcome = { kind: 'ok'; detail: BidInvitationDetailDto } | BidFailure;
|
||
|
||
/**
|
||
* 轮次 ID 形态校验(对方是 UUID,我方按"字母数字-下划线"放行并限长)。
|
||
*
|
||
* 为什么要它(红队 #6):`%00` 之类的控制字符会一路进到 Postgres 参数里报 500 并把原始错误回显给前端;
|
||
* 在入口挡掉比在下游 try/catch 更干净。非法形态 = 客户端问题(400),不是对方不可用。
|
||
*/
|
||
export function isValidBidRoundId(value: unknown): boolean {
|
||
const text = String(value || '').trim();
|
||
return /^[0-9A-Za-z_-]{1,64}$/.test(text);
|
||
}
|
||
|
||
/** 我方错误码 → 失败对象(HTTP 状态码在这里定,路由层照抄) */
|
||
function localFailure(input: {
|
||
code: string;
|
||
status: number;
|
||
kind?: BidFailure['kind'];
|
||
message?: string;
|
||
}): BidFailure {
|
||
return {
|
||
kind: input.kind || 'rejected',
|
||
status: input.status,
|
||
code: input.code,
|
||
message: input.message || bidErrorCopy(input.code),
|
||
};
|
||
}
|
||
|
||
/** 对方失败 → 我方失败(HTTP 状态码照对方;对方不可用统一 502) */
|
||
function fromMainFailure(failure: MainBidFailure): BidFailure {
|
||
if (failure.kind === 'not_configured') {
|
||
return localFailure({ code: 'main_system_not_configured', status: 503, kind: 'not_configured' });
|
||
}
|
||
if (failure.kind === 'unavailable') {
|
||
/**
|
||
* 默认把"对方不可用"折叠成 `main_system_unavailable`;
|
||
* 但**我方自己判定出来的码**(如 `invalid_main_system_response`)要原样透出 ——
|
||
* 它表达的是"响应不可识别、本次未落库",界面上与"对方挂了"是可区分的两件事(tester F1)。
|
||
*/
|
||
const ownCode =
|
||
failure.code === 'invalid_main_system_response' || failure.code === 'unauthorized'
|
||
? failure.code
|
||
: 'main_system_unavailable';
|
||
return localFailure({
|
||
code: ownCode,
|
||
status: 502,
|
||
kind: 'unavailable',
|
||
message: bidErrorCopy(failure.code, failure.reason),
|
||
});
|
||
}
|
||
/**
|
||
* 对方的 4xx 语义拒绝:状态码照抄(400/403/404),文案按错误码映射。
|
||
*
|
||
* ⚠️ `supplier_category_mismatch` 例外:**必须把对方的 `error_description` 原样透出**
|
||
* —— 对方文案里带商品编码("商品 SKU123 不在你的经营品类内…"),而前端要靠这句话里的
|
||
* sku 把**那一行**标红。若这里换成固定文案,界面就只能整单报错、无法定位是哪一行。
|
||
*/
|
||
const message =
|
||
failure.code === 'supplier_category_mismatch' && String(failure.reason || '').trim()
|
||
? String(failure.reason).trim()
|
||
: bidErrorCopy(failure.code, failure.reason);
|
||
return localFailure({
|
||
code: failure.code,
|
||
status: failure.status >= 400 && failure.status < 500 ? failure.status : 400,
|
||
message,
|
||
});
|
||
}
|
||
|
||
function emptySummary() {
|
||
return { pending: 0, quoted: 0, expired: 0, closed: 0, won: 0, lost: 0, cancelled: 0 };
|
||
}
|
||
|
||
/* ── ① 读本地镜像 ─────────────────────────────────────────────────────────── */
|
||
|
||
export async function listBidInvitations(input: {
|
||
branchCode: string;
|
||
status?: 'all' | 'pending' | 'history' | null;
|
||
/** true = 连已软删的行一起返回(页面「显示已删除」开关) */
|
||
includeDeleted?: boolean;
|
||
limit?: number;
|
||
}): Promise<BidListOutcome> {
|
||
const { rows, counts } = await listInvitationRows(input);
|
||
const summary = emptySummary();
|
||
for (const [key, value] of Object.entries(counts)) {
|
||
if (key in summary) (summary as Record<string, number>)[key] = Number(value) || 0;
|
||
}
|
||
summary.closed = summary.won + summary.lost + summary.cancelled;
|
||
return { rows: rows.map((row) => toBidInvitationDto(row)), summary };
|
||
}
|
||
|
||
/* ── ② 拉取兜底 ───────────────────────────────────────────────────────────── */
|
||
|
||
/**
|
||
* 主系统只重试 2 次推送 ⇒ 这条拉取是**唯一的兜底通道**。
|
||
*
|
||
* 逐个生效绑定(一个分公司可能绑多个 supplier_code)拉列表,只 upsert 邀约头:
|
||
* 对方列表接口不发明细,明细在"打开某一轮"时由 `refreshBidInvitation` 补齐。
|
||
*/
|
||
export async function syncBidInvitations(branchCode: string): Promise<BidSyncOutcome> {
|
||
const code = String(branchCode || '').trim();
|
||
const supplierCodes = code ? await listSupplierCodesForBranch(code) : [];
|
||
if (!supplierCodes.length) {
|
||
return { synced: 0, skipped: 0, unavailable: 0, enabled: false, bound: false };
|
||
}
|
||
let synced = 0;
|
||
// `skipped` 结构性恒 0(列表行必带 roundId ⇒ INSERT 必成功);保留字段是为了响应形状稳定
|
||
const skipped = 0;
|
||
let unavailable = 0;
|
||
let enabled = false;
|
||
for (const supplierCode of supplierCodes) {
|
||
const outcome = await listMainSupplierBids(supplierCode);
|
||
if (outcome.kind !== 'ok') {
|
||
unavailable += 1;
|
||
continue;
|
||
}
|
||
if (outcome.enabled) enabled = true;
|
||
const result = await upsertInvitationHeaders({
|
||
branchCode: code,
|
||
supplierCode,
|
||
rows: outcome.rows.map((row) => ({
|
||
roundId: row.roundId,
|
||
roundCode: row.roundCode,
|
||
roundTitle: row.roundTitle,
|
||
orderCode: row.orderCode,
|
||
respondDeadline: row.respondDeadline,
|
||
itemCount: row.itemCount,
|
||
roundStatus: row.roundStatus,
|
||
invitationStatus: row.invitationStatus,
|
||
})),
|
||
});
|
||
synced += result.upserted;
|
||
}
|
||
return { synced, skipped, unavailable, enabled, bound: true };
|
||
}
|
||
|
||
/** 对方详情(camelCase)→ 落库入参(snake_case):**唯一**的字段映射点,避免两处写法漂移 */
|
||
function toDetailInput(detail: MainSupplierBidDetail) {
|
||
return {
|
||
round: {
|
||
id: detail.round.roundId,
|
||
round_code: detail.round.roundCode,
|
||
title: detail.round.title,
|
||
order_code: detail.round.orderCode,
|
||
status: detail.round.status,
|
||
respond_deadline: detail.round.respondDeadline,
|
||
},
|
||
invitation: {
|
||
status: detail.invitation.status,
|
||
respond_deadline: detail.invitation.respondDeadline,
|
||
},
|
||
items: detail.items.map((item) => ({
|
||
sku_code: item.skuCode,
|
||
sku_name: item.skuName,
|
||
unit: item.unit,
|
||
})),
|
||
myQuotes: detail.myQuotes.map((quote) => ({
|
||
sku_code: quote.skuCode,
|
||
unit_price: quote.unitPrice,
|
||
remark: quote.remark,
|
||
created_at: quote.createdAt,
|
||
updated_at: quote.updatedAt,
|
||
})),
|
||
myAwards: detail.myAwards.map((award) => ({
|
||
sku_code: award.skuCode,
|
||
unit_price: award.unitPrice,
|
||
})),
|
||
};
|
||
}
|
||
|
||
/* ── ③ 单轮对齐 / 提交 ────────────────────────────────────────────────────── */
|
||
|
||
/** 定位这轮属于哪个 supplier_code:优先用台账(webhook 落的),没有就先同步一次再找 */
|
||
async function resolveInvitation(input: {
|
||
branchCode: string;
|
||
roundId: string;
|
||
supplierCode?: string | null;
|
||
syncIfMissing: boolean;
|
||
}): Promise<{ ok: true; supplierCode: string } | { ok: false; failure: BidFailure }> {
|
||
const roundId = String(input.roundId || '').trim();
|
||
const branchCode = String(input.branchCode || '').trim();
|
||
const supplierCode = String(input.supplierCode || '').trim();
|
||
if (!branchCode) {
|
||
return { ok: false, failure: localFailure({ code: 'branch_required', status: 400 }) };
|
||
}
|
||
if (!roundId) {
|
||
return { ok: false, failure: localFailure({ code: 'round_id_required', status: 400, message: '缺少竞价轮次 ID' }) };
|
||
}
|
||
if (!isValidBidRoundId(roundId)) {
|
||
return { ok: false, failure: localFailure({ code: 'invalid_round_id', status: 400, message: '竞价轮次 ID 非法' }) };
|
||
}
|
||
|
||
const pick = async () =>
|
||
findInvitationByRound({ branchCode, roundId, supplierCode: supplierCode || null });
|
||
let found = await pick();
|
||
if (found.kind === 'missing' && input.syncIfMissing) {
|
||
await syncBidInvitations(branchCode);
|
||
found = await pick();
|
||
}
|
||
if (found.kind === 'ambiguous') {
|
||
/**
|
||
* 同一轮有两个绑定编码都被邀请 ⇒ 不能替用户选哪一家。
|
||
* 让前端带上 `supplier`(清单每行都带 `supplierCode`)再来一次,避免"以另一家身份报价"。
|
||
*/
|
||
return {
|
||
ok: false,
|
||
failure: localFailure({
|
||
code: 'bid_invitation_ambiguous',
|
||
status: 409,
|
||
message: '该竞价单有多条供应商邀约,请从清单里点具体那一条',
|
||
}),
|
||
};
|
||
}
|
||
/**
|
||
* **已软删的邀约不得报价/刷新**(2026-10-19 BIZ-11):管理员「删除待报价」是本地隐藏、
|
||
* 可恢复的台账操作;若这里放行,旧详情页仍能把报价推到主系统。
|
||
* 显式 409(而不是 404)—— 用户点的是"明明在清单里存在过的这轮",需要看到"已删除",
|
||
* 而不是"本地没有记录,请先同步"这种误导文案。**零出站**:不刷新、不提交。
|
||
*/
|
||
if (found.kind === 'deleted') {
|
||
return { ok: false, failure: localFailure({ code: 'bid_invitation_deleted', status: 409 }) };
|
||
}
|
||
if (found.kind !== 'found') {
|
||
return { ok: false, failure: localFailure({ code: 'bid_invitation_not_found', status: 404 }) };
|
||
}
|
||
return { ok: true, supplierCode: String(found.row.supplier_code) };
|
||
}
|
||
|
||
/**
|
||
* 打开某一轮:以对方为准整轮对齐(明细 / 我的报价 / 我的中标)。
|
||
*
|
||
* 对方说这轮不存在或无权查看(404/403)⇒ 我方台账**停用该行**并留 sync_error,
|
||
* 让列表页不再把一轮"对方已经没有了"的竞价挂在待办里。
|
||
*/
|
||
export async function refreshBidInvitation(input: {
|
||
branchCode: string;
|
||
roundId: string;
|
||
/** 多绑定时用来定位具体那一条邀约(清单每行都带 `supplierCode`) */
|
||
supplierCode?: string | null;
|
||
}): Promise<BidDetailOutcome> {
|
||
const resolved = await resolveInvitation({ ...input, syncIfMissing: true });
|
||
if (!resolved.ok) return resolved.failure;
|
||
|
||
const outcome = await getMainSupplierBidDetail(resolved.supplierCode, input.roundId);
|
||
if (outcome.kind !== 'ok') {
|
||
const failure = fromMainFailure(outcome);
|
||
if (outcome.kind === 'rejected' && (failure.code === 'not_found' || failure.code === 'forbidden')) {
|
||
await markInvitationCancelled({
|
||
branchCode: input.branchCode,
|
||
roundId: input.roundId,
|
||
supplierCode: resolved.supplierCode,
|
||
reason: `${failure.code}: ${failure.message}`,
|
||
});
|
||
} else {
|
||
await markInvitationSyncError({
|
||
branchCode: input.branchCode,
|
||
roundId: input.roundId,
|
||
supplierCode: resolved.supplierCode,
|
||
reason: `${failure.code}: ${failure.message}`,
|
||
});
|
||
}
|
||
return failure;
|
||
}
|
||
|
||
await applyBidDetail({
|
||
branchCode: input.branchCode,
|
||
supplierCode: resolved.supplierCode,
|
||
roundId: input.roundId,
|
||
detail: toDetailInput(outcome.detail),
|
||
payload: outcome.detail,
|
||
});
|
||
|
||
const detail = await getBidInvitationDetail(input);
|
||
if (!detail) return localFailure({ code: 'bid_invitation_not_found', status: 404 });
|
||
return { kind: 'ok', detail };
|
||
}
|
||
|
||
/**
|
||
* 单价合法性:**数字**、> 0、最多 4 位小数、且不超过对方 `numeric(12,4)` 的上限。
|
||
*
|
||
* 三条都是踩过的坑:
|
||
* · `Number(true) === 1`、`Number([1.5]) === 1.5` ⇒ 只接受 `number` 或**纯数字字符串**;
|
||
* · 浮点 `*10000` 判定会把合法值 `12345678.1234` 误判成 5 位小数 ⇒ 用**字符串**小数位判定;
|
||
* · 超过 `99999999.9999` 的价对方存不下(回 502,用户看不出为什么)⇒ 入口直接 400。
|
||
*/
|
||
export function isValidBidUnitPrice(value: unknown): boolean {
|
||
if (typeof value !== 'number' && typeof value !== 'string') return false;
|
||
const text = typeof value === 'number' ? String(value) : String(value).trim();
|
||
if (!/^(?:\d+)(?:\.\d{1,4})?$/.test(text)) return false;
|
||
const num = Number(text);
|
||
if (!Number.isFinite(num) || num <= 0) return false;
|
||
return num <= 99_999_999.9999;
|
||
}
|
||
|
||
/**
|
||
* 提交报价(**唯一写主系统的地方**)。
|
||
*
|
||
* 顺序:本地校验(快、少发一次注定失败的请求)→ 对方提交 → 成功才用返回视图整轮 upsert。
|
||
* 失败一律**不动本地报价**:宁可让用户再点一次,也不能让他以为报上了。
|
||
*/
|
||
export async function submitBidQuotes(input: {
|
||
branchCode: string;
|
||
roundId: string;
|
||
/** 多绑定时用来定位具体那一条邀约(清单每行都带 `supplierCode`) */
|
||
supplierCode?: string | null;
|
||
quotes: Array<{ skuCode: string; unitPrice: number; remark?: string | null }>;
|
||
}): Promise<BidDetailOutcome> {
|
||
/**
|
||
* ⚠️ 这里**不要**先 `Number()`:`Number(true) === 1`、`Number([1.5]) === 1.5`
|
||
* ⇒ 布尔/数组会被"洗白"成合法价。先保留原值过 `isValidBidUnitPrice`,
|
||
* 通过后再转数字(红队 #3)。
|
||
*/
|
||
const quotes = Array.isArray(input.quotes)
|
||
? input.quotes
|
||
.map((quote) => ({
|
||
skuCode: String(quote?.skuCode || '').trim(),
|
||
rawUnitPrice: quote?.unitPrice as unknown,
|
||
remark: quote?.remark === undefined || quote?.remark === null ? null : String(quote.remark),
|
||
}))
|
||
.filter((quote) => Boolean(quote.skuCode))
|
||
: [];
|
||
if (!quotes.length) {
|
||
return localFailure({ code: 'quotes_required', status: 400 });
|
||
}
|
||
for (const quote of quotes) {
|
||
if (!isValidBidUnitPrice(quote.rawUnitPrice)) {
|
||
return localFailure({
|
||
code: 'invalid_unit_price',
|
||
status: 400,
|
||
message: `${quote.skuCode}:${bidErrorCopy('invalid_unit_price')}`,
|
||
});
|
||
}
|
||
}
|
||
const normalizedQuotes = quotes.map((quote) => ({
|
||
skuCode: quote.skuCode,
|
||
unitPrice: Number(quote.rawUnitPrice),
|
||
remark: quote.remark,
|
||
}));
|
||
|
||
const resolved = await resolveInvitation({ ...input, syncIfMissing: true });
|
||
if (!resolved.ok) return resolved.failure;
|
||
|
||
// 明细未拉过(只有 webhook 头)时先对齐一次:否则无法校验"这个 SKU 在不在本轮"
|
||
let detail = await getBidInvitationDetail(input);
|
||
if (!detail || !detail.items.length) {
|
||
const refreshed = await refreshBidInvitation(input);
|
||
if (refreshed.kind !== 'ok') return refreshed;
|
||
detail = refreshed.detail;
|
||
}
|
||
if (detail.deadlinePassed) {
|
||
return localFailure({ code: 'quote_deadline_passed', status: 409 });
|
||
}
|
||
if (detail.invitation.roundStatus !== 'open' || detail.invitation.localStatus === 'cancelled') {
|
||
return localFailure({ code: 'bid_not_open', status: 409 });
|
||
}
|
||
const knownSkus = new Set(detail.items.map((item) => item.skuCode));
|
||
const unknown = normalizedQuotes.find((quote) => !knownSkus.has(quote.skuCode));
|
||
if (unknown) {
|
||
return localFailure({
|
||
code: 'sku_not_in_round',
|
||
status: 400,
|
||
message: `${unknown.skuCode}:${bidErrorCopy('sku_not_in_round')}`,
|
||
});
|
||
}
|
||
|
||
const outcome = await submitMainSupplierBidQuotes({
|
||
supplierCode: resolved.supplierCode,
|
||
roundId: input.roundId,
|
||
quotes: normalizedQuotes,
|
||
});
|
||
if (outcome.kind !== 'ok') {
|
||
const failure = fromMainFailure(outcome);
|
||
if (outcome.kind === 'rejected' && (failure.code === 'bid_not_open' || failure.code === 'quote_deadline_passed')) {
|
||
// 对方说已关闭/已截止:我方台账立刻以对方为准对齐一次(失败不影响返回的错误)
|
||
await refreshBidInvitation(input).catch(() => undefined);
|
||
} else if (
|
||
outcome.kind === 'rejected' &&
|
||
(failure.code === 'not_found' || failure.code === 'forbidden')
|
||
) {
|
||
/**
|
||
* 对方说"这轮不存在 / 无权查看" ⇒ 与刷新路径同口径:**停用该行**(软删留痕)。
|
||
* 若只写 sync_error,这轮会永远挂在「待报价」里点不动,用户会当成系统坏了。
|
||
*/
|
||
await markInvitationCancelled({
|
||
branchCode: input.branchCode,
|
||
roundId: input.roundId,
|
||
supplierCode: resolved.supplierCode,
|
||
reason: `${failure.code}: ${failure.message}`,
|
||
});
|
||
} else {
|
||
await markInvitationSyncError({
|
||
branchCode: input.branchCode,
|
||
roundId: input.roundId,
|
||
supplierCode: resolved.supplierCode,
|
||
reason: `${failure.code}: ${failure.message}`,
|
||
});
|
||
}
|
||
return failure;
|
||
}
|
||
|
||
await applyBidDetail({
|
||
branchCode: input.branchCode,
|
||
supplierCode: resolved.supplierCode,
|
||
roundId: input.roundId,
|
||
detail: toDetailInput(outcome.detail),
|
||
payload: outcome.detail,
|
||
});
|
||
|
||
const after = await getBidInvitationDetail(input);
|
||
if (!after) return localFailure({ code: 'bid_invitation_not_found', status: 404 });
|
||
return { kind: 'ok', detail: after };
|
||
}
|