unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
106 lines • 3.72 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const controller_1 = __importDefault(require("../controller"));
const types_1 = require("../../types");
const openapi_1 = require("../../openapi");
class FavoritesController extends controller_1.default {
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: types_1.NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'addFavoriteFeature',
responses: { 200: openapi_1.emptyResponse },
}),
],
});
this.route({
method: 'delete',
path: '/:projectId/features/:featureName/favorites',
handler: this.removeFavoriteFeature,
permission: types_1.NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'removeFavoriteFeature',
responses: { 200: openapi_1.emptyResponse },
}),
],
});
this.route({
method: 'post',
path: '/:projectId/favorites',
handler: this.addFavoriteProject,
permission: types_1.NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'addFavoriteProject',
responses: { 200: openapi_1.emptyResponse },
}),
],
});
this.route({
method: 'delete',
path: '/:projectId/favorites',
handler: this.removeFavoriteProject,
permission: types_1.NONE,
middleware: [
openApiService.validPath({
tags: ['Features'],
operationId: 'removeFavoriteProject',
responses: { 200: openapi_1.emptyResponse },
}),
],
});
}
async addFavoriteFeature(req, res) {
const { featureName } = req.params;
const { user } = req;
await this.favoritesService.favoriteFeature({
feature: featureName,
user,
});
res.status(200).end();
}
async removeFavoriteFeature(req, res) {
const { featureName } = req.params;
const { user } = req;
await this.favoritesService.unfavoriteFeature({
feature: featureName,
user,
});
res.status(200).end();
}
async addFavoriteProject(req, res) {
const { projectId } = req.params;
const { user } = req;
await this.favoritesService.favoriteProject({
project: projectId,
user,
});
res.status(200).end();
}
async removeFavoriteProject(req, res) {
const { projectId } = req.params;
const { user } = req;
await this.favoritesService.unfavoriteProject({
project: projectId,
user: user,
});
res.status(200).end();
}
}
exports.default = FavoritesController;
//# sourceMappingURL=favorites.js.map