Merge branch 'main' into dev_match

This commit is contained in:
2026-11-06 10:14:43 +08:00
63 changed files with 7027 additions and 954 deletions
@@ -0,0 +1,12 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { normalizeInventoryDate } from './consignment-admin-service.js'
test('寄售仓库入库日期筛选只接受合法的 YYYY-MM-DD', () => {
assert.equal(normalizeInventoryDate('2026-11-05'), '2026-11-05')
assert.equal(normalizeInventoryDate(' 2026-11-05 '), '2026-11-05')
assert.equal(normalizeInventoryDate('2026-02-31'), undefined)
assert.equal(normalizeInventoryDate('2026/11/05'), undefined)
assert.equal(normalizeInventoryDate(''), undefined)
})
@@ -391,6 +391,8 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) {
const allowMatching =
query.allowMatching !== undefined ? String(query.allowMatching) === 'true' : undefined
const keyword = query.keyword ? String(query.keyword).trim() : undefined
const dateFrom = normalizeInventoryDate(query.dateFrom)
const dateTo = normalizeInventoryDate(query.dateTo)
const page = query.page ? Number(query.page) : 1
const pageSize = query.pageSize ? Number(query.pageSize) : 20
@@ -406,6 +408,8 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) {
diamondLevel,
allowMatching,
keyword,
dateFrom,
dateTo,
page,
pageSize,
})
@@ -416,6 +420,20 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) {
}
}
/**
* 寄售仓库的“通过审核入库时间”按自然日筛选。
* 只接受 YYYY-MM-DD,并通过 UTC roundtrip 拦截 2026-02-31 这类会被 Date 溢出的日期。
*/
export function normalizeInventoryDate(rawValue: unknown) {
const normalized = String(rawValue || '').trim()
if (!/^\d{4}-\d{2}-\d{2}$/.test(normalized)) return undefined
const parsed = new Date(`${normalized}T00:00:00.000Z`)
return Number.isNaN(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== normalized
? undefined
: normalized
}
export async function fetchAdminConsignmentStats() {
return getConsignmentInventoryStats()
}