feat: add production task set API client and item mapping
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
49e208c241
commit
d60d4bd4b6
4 files changed
+162
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { mapWorkOrderTasksToSetItems } from './production-task-set'
|
||||
|
||||
describe('mapWorkOrderTasksToSetItems', () => {
|
||||
it('skips empty names and keeps route/description/remark', () => {
|
||||
const { items, skippedEmptyNameCount } = mapWorkOrderTasksToSetItems([
|
||||
{ taskName: '分离', routeId: 'r1', routeName: '路线A', description: 'd', remark: 'm' },
|
||||
{ taskName: ' ', routeId: 'r2' },
|
||||
{ taskName: '培养' }
|
||||
])
|
||||
assert.equal(skippedEmptyNameCount, 1)
|
||||
assert.deepEqual(items, [
|
||||
{
|
||||
taskName: '分离',
|
||||
routeId: 'r1',
|
||||
routeName: '路线A',
|
||||
description: 'd',
|
||||
remark: 'm'
|
||||
},
|
||||
{
|
||||
taskName: '培养',
|
||||
routeId: '',
|
||||
routeName: '',
|
||||
description: '',
|
||||
remark: ''
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
export type ProductionTaskSetItemPreview = {
|
||||
taskName: string
|
||||
routeId: string
|
||||
routeName: string
|
||||
description: string
|
||||
remark: string
|
||||
}
|
||||
|
||||
export function mapWorkOrderTasksToSetItems(tasks: Record<string, any>[] | undefined): {
|
||||
items: ProductionTaskSetItemPreview[]
|
||||
skippedEmptyNameCount: number
|
||||
} {
|
||||
const items: ProductionTaskSetItemPreview[] = []
|
||||
let skippedEmptyNameCount = 0
|
||||
for (const row of tasks || []) {
|
||||
const taskName = String(row.taskName || '').trim()
|
||||
if (!taskName) {
|
||||
skippedEmptyNameCount += 1
|
||||
continue
|
||||
}
|
||||
items.push({
|
||||
taskName,
|
||||
routeId: String(row.routeId || '').trim(),
|
||||
routeName: String(row.routeName || '').trim(),
|
||||
description: String(row.description || '').trim(),
|
||||
remark: String(row.remark || '').trim()
|
||||
})
|
||||
}
|
||||
return { items, skippedEmptyNameCount }
|
||||
}
|
||||
Reference in new issue
Block a user