Seeking assistance with TypeScript syntax as a beginner.
I'm struggling to refactor this code in order to retrieve the full list of serviceBranches. Currently, there is filtering and mapping resulting in only one serviceBranch being returned from our API. I have attempted removing filters without success. Can someone guide me on how to fetch all serviceBranches by eliminating the correct filters?
Thank you in advance.
public async personNews(serviceBranch?: string[]): Promise<INews> {
const fetchResult: IPersonNewsFetchResultEntry[] = await this._get('api/person/news/', newsSchema, true) as IPersonNewsFetchResultEntry[];
const serviceBranches: string[] = (serviceBranch !== undefined ? serviceBranch : fetchResult.filter((entry: IPersonNewsFetchResultEntry, index: number, array: IPersonNewsFetchResultEntry[]): boolean => {
return entry.niveauID === NewsLevel.ServiceBranch && array.findIndex((value: IPersonNewsFetchResultEntry): boolean => {
return entry.unitID === value.unitID;
}) === index;
}).map((entry: IPersonNewsFetchResultEntry): string => {
return entry.unitID;
}));