mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
7ba8cd05eb
* fix: do not require Content-Type for requests without body * fix: require Content-Type for feature update requests
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { Response } from 'express';
|
|
import Controller from '../controller';
|
|
import { Logger } from '../../logger';
|
|
import { IUnleashConfig } from '../../types/option';
|
|
import { IUnleashServices } from '../../types/services';
|
|
import UserSplashService from '../../services/user-splash-service';
|
|
import { IAuthRequest } from '../unleash-types';
|
|
import { NONE } from '../../types/permissions';
|
|
import { OpenApiService } from '../../services/openapi-service';
|
|
import { createResponseSchema } from '../../openapi';
|
|
import { splashSchema, SplashSchema } from '../../openapi/spec/splash-schema';
|
|
|
|
class UserSplashController extends Controller {
|
|
private logger: Logger;
|
|
|
|
private userSplashService: UserSplashService;
|
|
|
|
private openApiService: OpenApiService;
|
|
|
|
constructor(
|
|
config: IUnleashConfig,
|
|
{
|
|
userSplashService,
|
|
openApiService,
|
|
}: Pick<IUnleashServices, 'userSplashService' | 'openApiService'>,
|
|
) {
|
|
super(config);
|
|
this.logger = config.getLogger('splash-controller.ts');
|
|
this.userSplashService = userSplashService;
|
|
this.openApiService = openApiService;
|
|
|
|
this.route({
|
|
method: 'post',
|
|
path: '/:id',
|
|
acceptAnyContentType: true,
|
|
handler: this.updateSplashSettings,
|
|
permission: NONE,
|
|
middleware: [
|
|
openApiService.validPath({
|
|
tags: ['admin'],
|
|
operationId: 'updateSplashSettings',
|
|
responses: { 200: createResponseSchema('splashSchema') },
|
|
}),
|
|
],
|
|
});
|
|
}
|
|
|
|
private async updateSplashSettings(
|
|
req: IAuthRequest<{ id: string }>,
|
|
res: Response<SplashSchema>,
|
|
): Promise<void> {
|
|
const { user } = req;
|
|
const { id } = req.params;
|
|
|
|
const splash = {
|
|
splashId: id,
|
|
userId: user.id,
|
|
seen: true,
|
|
};
|
|
|
|
this.openApiService.respondWithValidation(
|
|
200,
|
|
res,
|
|
splashSchema.$id,
|
|
await this.userSplashService.updateSplash(splash),
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = UserSplashController;
|
|
export default UserSplashController;
|