feat(consignment): 寄售仓库增加入库时间筛选
This commit is contained in:
@@ -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)
|
||||
})
|
||||
@@ -294,6 +294,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
|
||||
|
||||
@@ -309,6 +311,8 @@ export async function fetchAdminConsignmentInventories(query: JsonObject = {}) {
|
||||
diamondLevel,
|
||||
allowMatching,
|
||||
keyword,
|
||||
dateFrom,
|
||||
dateTo,
|
||||
page,
|
||||
pageSize,
|
||||
})
|
||||
@@ -319,6 +323,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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user