31 lines
855 B
TypeScript
31 lines
855 B
TypeScript
|
import { APIDecoder, APIResponse } from '@ucap-webmessenger/api';
|
||
|
|
||
|
export interface MailCountResponse {
|
||
|
systemName: string;
|
||
|
count: number;
|
||
|
}
|
||
|
|
||
|
export const decodeMailCount: APIDecoder<MailCountResponse> = (res: any) => {
|
||
|
const domParser = new DOMParser();
|
||
|
const dom: Document = domParser.parseFromString(res, 'text/xml');
|
||
|
|
||
|
let systemName = '';
|
||
|
const systemNameDom: HTMLCollection = dom.getElementsByTagName('COUNT');
|
||
|
if (!!systemNameDom && systemNameDom.length > 0) {
|
||
|
systemName = systemNameDom[0].textContent;
|
||
|
}
|
||
|
|
||
|
let count = 0;
|
||
|
const countDom: HTMLCollection = dom.getElementsByTagName('COUNT');
|
||
|
if (!!countDom && countDom.length > 0) {
|
||
|
count =
|
||
|
countDom[0].textContent.trim().length > 0
|
||
|
? Number(countDom[0].textContent.trim())
|
||
|
: 0;
|
||
|
}
|
||
|
return {
|
||
|
systemName,
|
||
|
count
|
||
|
} as MailCountResponse;
|
||
|
};
|