Skip to content

Commit

Permalink
fix return state
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva committed Jan 11, 2023
1 parent 4c2066c commit cd7e82a
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions packages/core/src/services/ubi/community/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CommunityListService {
status?: 'valid' | 'pending';
review?: 'pending' | 'claimed' | 'declined' | 'accepted' | 'accepted';
ambassadorAddress?: string;
state?: string | string[]
state?: string | string[];
}): Promise<{ count: number; rows: CommunityAttributes[] }> {
let extendedWhere: WhereOptions<CommunityAttributes> = {};
const orderOption: OrderItem[] = [];
Expand Down Expand Up @@ -440,7 +440,7 @@ export class CommunityListService {
// remove empty elements
communitiesId = communitiesId.filter(Number);

let states: ({
const states: ({
communityId: number;
claims: number;
claimed: string;
Expand All @@ -452,31 +452,38 @@ export class CommunityListService {
} | null)[] = [];
// TODO: validate query.state
// if (query.state) {
const queryState = query.state;
const batch = config.cronJobBatchSize;
for (let i = 0; ; i = i + batch) {
const communities = communitiesId.slice(i, i + batch)
const promises = communities.map(async (id) => {
let baseState: any = {},
ubiState: any = {};
// if (queryState === 'base' || queryState.indexOf('base') !== -1) {
baseState = await this.communityDetailsService.getBaseState(id!)
// }
if (!!queryState && (queryState === 'ubi' || queryState.indexOf('ubi') !== -1)) {
ubiState = await this.communityDetailsService.getUbiState(id!)
}

return {
...baseState,
...ubiState
} as any;
});
const result = await Promise.all(promises);
states.push(...result);
if (i + batch > communitiesId.length) {
break;
const queryState = query.state;
const batch = config.cronJobBatchSize;
for (let i = 0; ; i = i + batch) {
const communities = communitiesId.slice(i, i + batch);
const promises = communities.map(async (id) => {
let baseState: any = {},
ubiState: any = {};
// if (queryState === 'base' || queryState.indexOf('base') !== -1) {
baseState = await this.communityDetailsService.getBaseState(
id!
);
// }
if (
!!queryState &&
(queryState === 'ubi' || queryState.indexOf('ubi') !== -1)
) {
ubiState = await this.communityDetailsService.getUbiState(
id!
);
}

return {
...baseState,
...ubiState,
} as any;
});
const result = await Promise.all(promises);
states.push(...result);
if (i + batch > communitiesId.length) {
break;
}
}
// }

//formate response
Expand All @@ -491,14 +498,14 @@ export class CommunityListService {
};

// if (query.state) {
const state = states.find(
(el) => el?.communityId === community.id!
);
const state = states.find(
(el) => el?.communityId === community.id!
);

community = {
...community,
state,
};
community = {
...community,
state,
};
// }
communities.push(community);
});
Expand Down

0 comments on commit cd7e82a

Please sign in to comment.