demand.ts 907 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. export interface DemandBelongItem {
  2. id: number
  3. name: string | null
  4. category_id: number
  5. reason: string | null
  6. }
  7. export interface DemandBelongResponse {
  8. items: DemandBelongItem[]
  9. }
  10. export interface DemandVideoItem {
  11. vid: string
  12. title: string | null
  13. inspiration_points_json: string | null
  14. purpose_points_json: string | null
  15. key_points_json: string | null
  16. }
  17. export interface DemandVideosResponse {
  18. demand_belong_id: number
  19. name: string | null
  20. category_id: number
  21. videos: DemandVideoItem[]
  22. }
  23. /** category_id → demands belonging to that category */
  24. export type DemandsByCategory = Record<number, DemandBelongItem[]>
  25. export function groupDemandsByCategory(items: DemandBelongItem[]): DemandsByCategory {
  26. const map: DemandsByCategory = {}
  27. for (const item of items) {
  28. const key = item.category_id
  29. if (!map[key]) map[key] = []
  30. map[key].push(item)
  31. }
  32. return map
  33. }