type EquipmentKeywordCondition = Record const buildOwnEquipmentKeywordConditions = (keyword: string): EquipmentKeywordCondition[] => [ { equipment_name: { contains: keyword } }, { equipment_code: { contains: keyword } }, { equipment_model: { contains: keyword } }, { department: { is: { name: { contains: keyword } } } }, { storageLocation: { is: { name: { contains: keyword } } } }, { borrow_records: { some: { status: '已借出', OR: [ { person_nickname: { contains: keyword } }, { person_name: { contains: keyword } }, { person: { is: { nickname: { contains: keyword } } } }, { person: { is: { real_name: { contains: keyword } } } }, { person: { is: { job_number: { contains: keyword } } } } ] } } } ] export const buildEquipmentKeywordSearchConditions = ( keyword: string, descendantDepth = 0 ): EquipmentKeywordCondition[] => { const ownConditions = buildOwnEquipmentKeywordConditions(keyword) if (descendantDepth <= 0) { return ownConditions } return [ ...ownConditions, { children: { some: { OR: buildEquipmentKeywordSearchConditions(keyword, descendantDepth - 1) } } } ] }