UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

76 lines 3.81 kB
import Controller from '../controller.js'; import { NONE } from '../../types/permissions.js'; import { serializeDates } from '../../types/serialize-dates.js'; import { parseISO } from 'date-fns'; import { createRequestSchema } from '../../openapi/util/create-request-schema.js'; import { createResponseSchema } from '../../openapi/util/create-response-schema.js'; import BadDataError from '../../error/bad-data-error.js'; import { feedbackResponseSchema, getStandardResponses, } from '../../openapi/index.js'; class UserFeedbackController extends Controller { constructor(config, { userFeedbackService, openApiService, }) { super(config); this.userFeedbackService = userFeedbackService; this.openApiService = openApiService; this.route({ method: 'post', path: '', handler: this.createFeedback, permission: NONE, middleware: [ openApiService.validPath({ tags: ['Admin UI'], operationId: 'createFeedback', summary: 'Send Unleash feedback', description: 'Sends feedback gathered from the Unleash UI to the Unleash server. Must be called with a token with an identifiable user (either from being sent from the UI or from using a [PAT](https://docs.getunleash.io/concepts/api-tokens-and-client-keys#personal-access-tokens)).', requestBody: createRequestSchema('feedbackCreateSchema'), responses: { 200: createResponseSchema('feedbackResponseSchema'), ...getStandardResponses(400, 401, 415), }, }), ], }); this.route({ method: 'put', path: '/:id', handler: this.updateFeedback, permission: NONE, middleware: [ openApiService.validPath({ tags: ['Admin UI'], operationId: 'updateFeedback', summary: 'Update Unleash feedback', description: 'Updates the feedback with the provided ID. Only provided fields are updated. Fields left out are left untouched. Must be called with a token with an identifiable user (either from being sent from the UI or from using a [PAT](https://docs.getunleash.io/concepts/api-tokens-and-client-keys#personal-access-tokens)).', requestBody: createRequestSchema('feedbackUpdateSchema'), responses: { 200: createResponseSchema('feedbackResponseSchema'), ...getStandardResponses(400, 401, 415), }, }), ], }); } async createFeedback(req, res) { if (!req.body.feedbackId) { throw new BadDataError('Missing feedbackId'); } const updated = await this.userFeedbackService.updateFeedback({ feedbackId: req.body.feedbackId, userId: req.user.id, given: new Date(), neverShow: req.body.neverShow || false, }); this.openApiService.respondWithValidation(200, res, feedbackResponseSchema.$id, serializeDates(updated)); } async updateFeedback(req, res) { const updated = await this.userFeedbackService.updateFeedback({ feedbackId: req.params.id, userId: req.user.id, neverShow: req.body.neverShow || false, given: (req.body.given && parseISO(req.body.given)) || new Date(), }); this.openApiService.respondWithValidation(200, res, feedbackResponseSchema.$id, serializeDates(updated)); } } export default UserFeedbackController; //# sourceMappingURL=user-feedback.js.map