unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
120 lines • 4.49 kB
JavaScript
import Controller from '../controller.js';
import { NONE } from '../../types/index.js';
import { emptyResponse, getStandardResponses } from '../../openapi/index.js';
export default class FavoritesController extends Controller {
constructor(config, { favoritesService, openApiService, }) {
super(config);
this.logger = config.getLogger('/routes/favorites-controller');
this.favoritesService = favoritesService;
this.openApiService = openApiService;
this.route({
method: 'post',
path: '/:projectId/features/:featureName/favorites',
handler: this.addFavoriteFeature,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'addFavoriteFeature',
summary: 'Add feature to favorites',
description: 'This endpoint marks the feature in the url as favorite',
responses: {
200: emptyResponse,
...getStandardResponses(401, 404),
},
}),
],
});
this.route({
method: 'delete',
path: '/:projectId/features/:featureName/favorites',
handler: this.removeFavoriteFeature,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'removeFavoriteFeature',
summary: 'Remove feature from favorites',
description: 'This endpoint removes the feature in the url from favorites',
responses: {
200: emptyResponse,
...getStandardResponses(401, 404),
},
}),
],
});
this.route({
method: 'post',
path: '/:projectId/favorites',
handler: this.addFavoriteProject,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Add project to favorites',
description: 'This endpoint marks the project in the url as favorite',
operationId: 'addFavoriteProject',
responses: {
200: emptyResponse,
...getStandardResponses(401, 404),
},
}),
],
});
this.route({
method: 'delete',
path: '/:projectId/favorites',
handler: this.removeFavoriteProject,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Remove project from favorites',
description: 'This endpoint removes the project in the url from favorites',
operationId: 'removeFavoriteProject',
responses: {
200: emptyResponse,
...getStandardResponses(401, 404),
},
}),
],
});
}
async addFavoriteFeature(req, res) {
const { featureName } = req.params;
const { user } = req;
await this.favoritesService.favoriteFeature({
feature: featureName,
user,
}, req.audit);
res.status(200).end();
}
async removeFavoriteFeature(req, res) {
const { featureName } = req.params;
const { user } = req;
await this.favoritesService.unfavoriteFeature({
feature: featureName,
user,
}, req.audit);
res.status(200).end();
}
async addFavoriteProject(req, res) {
const { projectId } = req.params;
const { user } = req;
await this.favoritesService.favoriteProject({
project: projectId,
user,
}, req.audit);
res.status(200).end();
}
async removeFavoriteProject(req, res) {
const { projectId } = req.params;
const { user } = req;
await this.favoritesService.unfavoriteProject({
project: projectId,
user: user,
}, req.audit);
res.status(200).end();
}
}
//# sourceMappingURL=favorites.js.map