1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/routes/admin-api/user-splash.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

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;
2021-11-09 20:55:23 +01:00
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',
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;
2021-11-09 20:55:23 +01:00
export default UserSplashController;