1+ import { observable } from 'mobx' ;
2+ import { HTTPClient } from 'koajax' ;
3+ import { StrapiListModel , Base } from 'mobx-strapi' ;
4+
5+ // Define the organization data structure similar to China NGO database
6+ export interface Organization extends Base {
7+ name : string ;
8+ description ?: string ;
9+ type ?: string ;
10+ city ?: string ;
11+ province ?: string ;
12+ tags ?: string [ ] ;
13+ website ?: string ;
14+ logo ?: {
15+ data ?: {
16+ attributes : {
17+ url : string ;
18+ } ;
19+ } ;
20+ } ;
21+ year ?: number ;
22+ }
23+
24+ export interface OrganizationStatistic {
25+ year : Array < { label : string ; count : number } > ;
26+ city : Array < { label : string ; count : number } > ;
27+ type : Array < { label : string ; count : number } > ;
28+ tag : Array < { label : string ; count : number } > ;
29+ }
30+
31+ // Strapi client configuration
32+ const strapiClient = new HTTPClient ( {
33+ baseURI : 'https://china-ngo-db.onrender.com/api/' ,
34+ responseType : 'json' ,
35+ } ) ;
36+
37+ export class OrganizationModel extends StrapiListModel < Organization > {
38+ baseURI = '/organizations' ;
39+
40+ constructor ( ) {
41+ super ( ) ;
42+ this . client = strapiClient ;
43+ }
44+
45+ @observable
46+ accessor tagMap : Record < string , Organization [ ] > = { } ;
47+
48+ async groupAllByTags ( ) : Promise < Record < string , Organization [ ] > > {
49+ try {
50+ const allData = await this . getAll ( ) ;
51+ const tagMap : Record < string , Organization [ ] > = { } ;
52+
53+ for ( const org of allData ) {
54+ const tags = org . tags || [ ] ;
55+ for ( const tag of tags ) {
56+ if ( ! tagMap [ tag ] ) {
57+ tagMap [ tag ] = [ ] ;
58+ }
59+ tagMap [ tag ] . push ( org ) ;
60+ }
61+ }
62+
63+ this . tagMap = tagMap ;
64+ return tagMap ;
65+ } catch ( error ) {
66+ console . error ( 'Failed to fetch organizations:' , error ) ;
67+ return { } ;
68+ }
69+ }
70+ }
71+
72+ export class OrganizationStatisticModel {
73+ private client : HTTPClient < any > ;
74+ private collection : string ;
75+
76+ constructor ( baseId : string , collectionId : string ) {
77+ this . client = new HTTPClient ( {
78+ baseURI : 'https://china-ngo-db.onrender.com/api/' ,
79+ responseType : 'json' ,
80+ } ) ;
81+ this . collection = collectionId ;
82+ }
83+
84+ async countAll ( ) : Promise < Array < { label : string ; count : number } > > {
85+ try {
86+ // This would need to be adapted based on the actual Strapi API structure
87+ const response = await this . client . get ( `${ this . collection } ` ) ;
88+ return response . body ?. data || [ ] ;
89+ } catch ( error ) {
90+ console . error ( `Failed to fetch statistics for ${ this . collection } :` , error ) ;
91+ return [ ] ;
92+ }
93+ }
94+ }
95+
96+ // Mock constants for now - these would be configured based on the actual Strapi setup
97+ export const COMMUNITY_BASE_ID = 'community' ;
98+ export const OSC_YEAR_STATISTIC_TABLE_ID = 'organization-year-stats' ;
99+ export const OSC_CITY_STATISTIC_TABLE_ID = 'organization-city-stats' ;
100+ export const OSC_TYPE_STATISTIC_TABLE_ID = 'organization-type-stats' ;
101+ export const OSC_TAG_STATISTIC_TABLE_ID = 'organization-tag-stats' ;
0 commit comments