2021-11-09 14:13:30 +01:00
|
|
|
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';
|
2021-12-03 12:46:50 +01:00
|
|
|
import { NONE } from '../../types/permissions';
|
2022-06-10 15:11:07 +02:00
|
|
|
import { OpenApiService } from '../../services/openapi-service';
|
|
|
|
import { createResponseSchema } from '../../openapi';
|
|
|
|
import { splashSchema, SplashSchema } from '../../openapi/spec/splash-schema';
|
2021-11-09 14:13:30 +01:00
|
|
|
|
|
|
|
class UserSplashController extends Controller {
|
|
|
|
private logger: Logger;
|
2021-11-09 20:55:23 +01:00
|
|
|
|
2021-11-09 14:13:30 +01:00
|
|
|
private userSplashService: UserSplashService;
|
|
|
|
|
2022-06-10 15:11:07 +02:00
|
|
|
private openApiService: OpenApiService;
|
|
|
|
|
2021-11-09 14:13:30 +01:00
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
2022-06-10 15:11:07 +02:00
|
|
|
{
|
|
|
|
userSplashService,
|
|
|
|
openApiService,
|
|
|
|
}: Pick<IUnleashServices, 'userSplashService' | 'openApiService'>,
|
2021-11-09 14:13:30 +01:00
|
|
|
) {
|
|
|
|
super(config);
|
|
|
|
this.logger = config.getLogger('splash-controller.ts');
|
|
|
|
this.userSplashService = userSplashService;
|
2022-06-10 15:11:07 +02:00
|
|
|
this.openApiService = openApiService;
|
2021-11-09 14:13:30 +01:00
|
|
|
|
2022-06-10 15:11:07 +02:00
|
|
|
this.route({
|
|
|
|
method: 'post',
|
|
|
|
path: '/:id',
|
|
|
|
handler: this.updateSplashSettings,
|
|
|
|
permission: NONE,
|
|
|
|
middleware: [
|
|
|
|
openApiService.validPath({
|
|
|
|
tags: ['admin'],
|
|
|
|
operationId: 'updateSplashSettings',
|
|
|
|
responses: { 200: createResponseSchema('splashSchema') },
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
2021-11-09 14:13:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private async updateSplashSettings(
|
2022-06-10 15:11:07 +02:00
|
|
|
req: IAuthRequest<{ id: string }>,
|
|
|
|
res: Response<SplashSchema>,
|
2021-11-09 14:13:30 +01:00
|
|
|
): Promise<void> {
|
|
|
|
const { user } = req;
|
|
|
|
const { id } = req.params;
|
|
|
|
|
|
|
|
const splash = {
|
|
|
|
splashId: id,
|
|
|
|
userId: user.id,
|
2021-11-12 10:49:09 +01:00
|
|
|
seen: true,
|
2021-11-09 14:13:30 +01:00
|
|
|
};
|
2022-06-10 15:11:07 +02:00
|
|
|
|
|
|
|
this.openApiService.respondWithValidation(
|
|
|
|
200,
|
|
|
|
res,
|
|
|
|
splashSchema.$id,
|
|
|
|
await this.userSplashService.updateSplash(splash),
|
|
|
|
);
|
2021-11-09 14:13:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UserSplashController;
|
2021-11-09 20:55:23 +01:00
|
|
|
export default UserSplashController;
|