diff --git a/services/apps/assignments/src/classroom/classroom.service.ts b/services/apps/assignments/src/classroom/classroom.service.ts index a93d70c4b..14acc402c 100644 --- a/services/apps/assignments/src/classroom/classroom.service.ts +++ b/services/apps/assignments/src/classroom/classroom.service.ts @@ -64,10 +64,6 @@ export class ClassroomService { private async upsertSolutions(assignment: AssignmentDocument, importSolutions: ImportSolution[]) { const result = await this.solutionService.bulkWrite(importSolutions.map(importSolution => { - const solution: Solution = { - ...importSolution, - token: generateToken(), - }; const [key, value] = Object.entries(importSolution.author).find(([, value]) => value)!; return { updateOne: { @@ -75,7 +71,12 @@ export class ClassroomService { assignment: assignment._id, ['author.' + key]: value, }, - update: {$setOnInsert: solution}, + update: { + $setOnInsert: { + ...importSolution, + token: generateToken(), + }, + }, upsert: true, }, }; diff --git a/services/apps/assignments/src/solution/solution.controller.ts b/services/apps/assignments/src/solution/solution.controller.ts index 5c93cb8b2..6ed0f3447 100644 --- a/services/apps/assignments/src/solution/solution.controller.ts +++ b/services/apps/assignments/src/solution/solution.controller.ts @@ -20,7 +20,7 @@ import {AssigneeService} from '../assignee/assignee.service'; import {AssignmentAuth} from '../assignment/assignment-auth.decorator'; import {EvaluationService} from '../evaluation/evaluation.service'; import {SolutionAuth} from './solution-auth.decorator'; -import {BatchUpdateSolutionDto, CreateSolutionDto, ReadSolutionDto, UpdateSolutionDto} from './solution.dto'; +import {BatchUpdateSolutionDto, CreateSolutionDto, UpdateSolutionDto} from './solution.dto'; import {Solution} from './solution.schema'; import {SolutionService} from './solution.service'; import {FilesInterceptor} from "@nestjs/platform-express"; @@ -68,7 +68,7 @@ export class SolutionController { @Get('assignments/:assignment/solutions') @AssignmentAuth({forbiddenResponse: forbiddenAssignmentResponse}) - @ApiOkResponse({type: [ReadSolutionDto]}) + @ApiOkResponse({type: [Solution]}) @ApiQuery({ name: 'q', description: 'Search query: ' + @@ -81,7 +81,7 @@ export class SolutionController { @Param('assignment') assignment: string, @Query('q') search?: string, @Query('author.github') github?: string, - ): Promise { + ): Promise { const query: FilterQuery = {assignment}; github && (query['author.github'] = github); if (search) { @@ -144,10 +144,10 @@ export class SolutionController { @Get('solutions') @ApiOperation({summary: 'List your own solutions'}) @Auth() - @ApiOkResponse({type: [ReadSolutionDto]}) + @ApiOkResponse({type: [Solution]}) async findOwn( @AuthUser() user: UserToken, - ): Promise { + ): Promise { return this.solutionService.findAll({createdBy: user.sub}); } diff --git a/services/apps/assignments/src/solution/solution.dto.ts b/services/apps/assignments/src/solution/solution.dto.ts index 9c492fa57..e99eac415 100644 --- a/services/apps/assignments/src/solution/solution.dto.ts +++ b/services/apps/assignments/src/solution/solution.dto.ts @@ -5,6 +5,7 @@ import {AsObjectId} from "@mean-stream/nestx"; import {IsOptional} from "class-validator"; const excluded = [ + '_id', 'token', 'assignment', 'createdBy', @@ -30,15 +31,3 @@ export class BatchUpdateSolutionDto extends UpdateSolutionDto { @ApiPropertyOptional() _id?: Types.ObjectId; } - -export class ReadSolutionDto extends OmitType(Solution, [ - 'token', -]) { - _id: Types.ObjectId; - /* - @Prop() - @ApiProperty() - @IsString() - assignee: string; - */ -} diff --git a/services/apps/assignments/src/solution/solution.schema.ts b/services/apps/assignments/src/solution/solution.schema.ts index 898caafca..2cc4bdac1 100644 --- a/services/apps/assignments/src/solution/solution.schema.ts +++ b/services/apps/assignments/src/solution/solution.schema.ts @@ -13,7 +13,7 @@ import { IsUUID, ValidateNested, } from 'class-validator'; -import {Document} from 'mongoose'; +import {Document, Types} from 'mongoose'; export class Consent { @Prop() @@ -79,6 +79,9 @@ export class AuthorInfo { @Schema() export class Solution { + @ApiProperty() + _id: Types.ObjectId; + @Prop() @ApiProperty() token: string; diff --git a/services/apps/assignments/src/solution/solution.service.ts b/services/apps/assignments/src/solution/solution.service.ts index 3e355e80e..19c941e86 100644 --- a/services/apps/assignments/src/solution/solution.service.ts +++ b/services/apps/assignments/src/solution/solution.service.ts @@ -4,7 +4,7 @@ import {Injectable} from '@nestjs/common'; import {InjectModel} from '@nestjs/mongoose'; import {FilterQuery, Model, UpdateQuery} from 'mongoose'; import {generateToken} from '../utils'; -import {BatchUpdateSolutionDto, CreateSolutionDto, ReadSolutionDto, UpdateSolutionDto} from './solution.dto'; +import {BatchUpdateSolutionDto, CreateSolutionDto, UpdateSolutionDto} from './solution.dto'; import {Solution, SolutionDocument} from './solution.schema'; @Injectable() @@ -27,10 +27,9 @@ export class SolutionService { return created; } - async findAll(where: FilterQuery = {}): Promise { + async findAll(where: FilterQuery = {}): Promise { return this.model .find(where) - .select(['-token']) .sort('author.name author.github timestamp') .collation({locale: 'en', caseFirst: 'off'}) .exec();