diff --git a/backend/packages/Upgrade/src/api/controllers/ExperimentUserController.ts b/backend/packages/Upgrade/src/api/controllers/ExperimentUserController.ts deleted file mode 100644 index 962cf804c9..0000000000 --- a/backend/packages/Upgrade/src/api/controllers/ExperimentUserController.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { JsonController, Req, Get, Post, Put, Body, Authorized, Params } from 'routing-controllers'; -import { ExperimentUserService } from '../services/ExperimentUserService'; -import { ExperimentUser } from '../models/ExperimentUser'; -import { AppRequest } from '../../types'; -import { - ExperimentUserArrayValidator, - ExperimentUserValidator, - IdValidator, -} from './validators/ExperimentUserValidator'; -import { InsertResult } from 'typeorm'; -import { ExperimentClientController } from './ExperimentClientController.v5'; - -// TODO delete this from experiment system -/** - * @swagger - * definitions: - * ExperimentUser: - * required: - * - id - * properties: - * id: - * type: string - * group: - * type: object - * workingGroup: - * type: object - */ - -/** - * @swagger - * tags: - * - name: Experiment Users - * description: CRUD operations related to users - */ - -@Authorized() -@JsonController('/experimentusers') -export class UserController { - constructor( - public userService: ExperimentUserService, - public experimentClientController: ExperimentClientController - ) {} - - /** - * @swagger - * /experimentusers: - * get: - * description: Get all the users - * tags: - * - Experiment Users - * responses: - * '200': - * description: Successful - * '401': - * description: AuthorizationRequiredError - */ - @Get() - public find(@Req() request: AppRequest): Promise { - return this.userService.find(request.logger); - } - - /** - * @swagger - * /experimentusers/{id}: - * get: - * description: Get user by id - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * description: user Id - * tags: - * - Experiment Users - * produces: - * - application/json - * responses: - * '200': - * description: Get user By Id - * '400': - * description: BadRequestError - InvalidParameterValue - * '401': - * description: AuthorizationRequiredError - * '404': - * description: Experiment User not defined - */ - @Get('/:id') - public async one( - @Params({ validate: true }) { id }: IdValidator, - @Req() request: AppRequest - ): Promise { - await this.experimentClientController.checkIfUserExist(id, request.logger); - return this.userService.findOne(id, request.logger); - } - - /** - * @swagger - * /experimentusers: - * post: - * description: Create New ExperimentUser - * consumes: - * - application/json - * parameters: - * - in: body - * name: user - * required: true - * schema: - * type: object - * $ref: '#/definitions/ExperimentUser' - * description: ExperimentUser Structure - * tags: - * - Experiment Users - * produces: - * - application/json - * responses: - * '200': - * description: New ExperimentUser is created - * '400': - * description: BadRequestError - InvalidParameterValue - * '401': - * description: AuthorizationRequiredError - */ - @Post() - public create( - @Body({ validate: true }) - users: ExperimentUserArrayValidator, - @Req() request: AppRequest - ): Promise { - return this.userService.create(users.users, request.logger); - } - - /** - * @swagger - * /experimentusers/{id}: - * put: - * description: Update ExperimentUser - * consumes: - * - application/json - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * description: ExperimentUser ID - * - in: body - * name: user - * required: true - * schema: - * type: object - * $ref: '#/definitions/ExperimentUser' - * description: ExperimentUser Structure - * tags: - * - Experiment Users - * produces: - * - application/json - * responses: - * '200': - * description: ExperimentUser is updated - * '400': - * description: BadRequestError - InvalidParameterValue - * '401': - * description: AuthorizationRequiredError - * '404': - * description: Experiment User not defined - */ - @Put('/:id') - public async update( - @Params({ validate: true }) { id }: IdValidator, - @Body({ validate: true }) user: ExperimentUserValidator, - @Req() request: AppRequest - ): Promise { - await this.experimentClientController.checkIfUserExist(id, request.logger); - return this.userService.update(id, user, request.logger); - } -} diff --git a/backend/packages/Upgrade/src/api/services/ExperimentUserService.ts b/backend/packages/Upgrade/src/api/services/ExperimentUserService.ts index 43ae8be601..7cf7b00595 100644 --- a/backend/packages/Upgrade/src/api/services/ExperimentUserService.ts +++ b/backend/packages/Upgrade/src/api/services/ExperimentUserService.ts @@ -233,12 +233,6 @@ export class ExperimentUserService { return this.userRepository.save(newDocument); } - public update(id: string, user: Partial, logger: UpgradeLogger): Promise { - logger.info({ message: `Update a user ${user.toString()}` }); - user.id = id; - return this.userRepository.save(user); - } - // TODO should we check for workingGroup as a subset over here? public async updateGroupMembership( userId: string, diff --git a/backend/packages/Upgrade/test/unit/controllers/ExperimentUserController.test.ts b/backend/packages/Upgrade/test/unit/controllers/ExperimentUserController.test.ts deleted file mode 100644 index 90b3a61bb8..0000000000 --- a/backend/packages/Upgrade/test/unit/controllers/ExperimentUserController.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import app from '../../utils/expressApp'; -import request from 'supertest'; -import { configureLogger } from '../../utils/logger'; -import { useContainer as routingUseContainer } from 'routing-controllers'; -import { Container } from 'typedi'; -import { ExperimentUserService } from '../../../src/api/services/ExperimentUserService'; -import ExperimentUserServiceMock from './mocks/ExperimentUserServiceMock'; - -import { useContainer as classValidatorUseContainer } from 'class-validator'; -import { v4 as uuid } from 'uuid'; -import { ExperimentClientController } from '../../../src/api/controllers/ExperimentClientController.v5'; -import ExperimentClientControllerMock from './mocks/ExperimentClientControllerMock'; - -describe('Experiment User Controller Testing', () => { - beforeAll(() => { - configureLogger(); - routingUseContainer(Container); - classValidatorUseContainer(Container); - - Container.set(ExperimentUserService, new ExperimentUserServiceMock()); - Container.set(ExperimentClientController, new ExperimentClientControllerMock()); - - }); - - afterAll(() => { - Container.reset(); - }); - - test('Get request for /api/experimentusers', () => { - return request(app) - .get('/api/experimentusers') - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200); - }); - - test('Get request for /api/experimentusers/id', () => { - return request(app) - .get('/api/experimentusers/' + uuid()) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200); - }); - - test('Post request for /api/experimentusers/', () => { - return request(app) - .post('/api/experimentusers/') - .send({ - users: [ - { - id: 'u21', - group: { - school: ['testschool'], - class: ['testclass'], - instructor: ['testteacher'], - }, - workingGroup: { - school: 'testschool', - class: 'testclass', - instructor: 'testteacher', - }, - }, - ], - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200); - }); - - test('Put request for /api/experimentusers/id', () => { - return request(app) - .put('/api/experimentusers/u21') - .send({ - id: 'u21', - group: { - school: ['testschool'], - class: ['testclass'], - instructor: ['testteacher'], - }, - workingGroup: { - school: 'testschool', - class: 'testclass', - instructor: 'testteacher', - }, - }) - .set('Accept', 'application/json') - .expect('Content-Type', /json/) - .expect(200); - }); -});