1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/services/client-metrics/projection.ts
checketts 2f013bacbf
chore: Convert client metrics controller to typescript (#831)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-06-24 19:22:12 +02:00

34 lines
850 B
TypeScript

import { IYesNoCount } from './models';
export class Projection {
store: Record<string, IYesNoCount> = {};
getProjection(): Record<string, IYesNoCount> {
return this.store;
}
add(name: string, countObj: IYesNoCount): void {
if (this.store[name]) {
this.store[name].yes += countObj.yes;
this.store[name].no += countObj.no;
} else {
this.store[name] = {
yes: countObj.yes,
no: countObj.no,
};
}
}
substract(name: string, countObj: IYesNoCount): void {
if (this.store[name]) {
this.store[name].yes -= countObj.yes;
this.store[name].no -= countObj.no;
} else {
this.store[name] = {
yes: 0,
no: 0,
};
}
}
}