unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
29 lines • 1.33 kB
JavaScript
import NotFoundError from '../error/notfound-error.js';
import { FeatureTypeUpdatedEvent } from '../types/index.js';
export default class FeatureTypeService {
constructor({ featureTypeStore }, { getLogger }, eventService) {
this.featureTypeStore = featureTypeStore;
this.logger = getLogger('services/feature-type-service.ts');
this.eventService = eventService;
}
async getAll() {
return this.featureTypeStore.getAll();
}
async updateLifetime(id, newLifetimeDays, auditUser) {
// because our OpenAPI library does type coercion, any `null` values you
// pass in get converted to `0`.
const translatedLifetime = newLifetimeDays === 0 ? null : newLifetimeDays;
const featureType = await this.featureTypeStore.get(id);
const result = await this.featureTypeStore.updateLifetime(id, translatedLifetime);
if (!featureType || !result) {
throw new NotFoundError(`The feature type you tried to update ("${id}") does not exist.`);
}
await this.eventService.storeEvent(new FeatureTypeUpdatedEvent({
auditUser,
data: { ...featureType, lifetimeDays: translatedLifetime },
preData: featureType,
}));
return result;
}
}
//# sourceMappingURL=feature-type-service.js.map