Skip to content

Commit

Permalink
fix(assignments-service): Don't remove token from solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Nov 8, 2023
1 parent 08980af commit 0849112
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
11 changes: 6 additions & 5 deletions services/apps/assignments/src/classroom/classroom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ 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: {
filter: {
assignment: assignment._id,
['author.' + key]: value,
},
update: {$setOnInsert: solution},
update: {
$setOnInsert: {
...importSolution,
token: generateToken(),
},
},
upsert: true,
},
};
Expand Down
10 changes: 5 additions & 5 deletions services/apps/assignments/src/solution/solution.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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: ' +
Expand All @@ -81,7 +81,7 @@ export class SolutionController {
@Param('assignment') assignment: string,
@Query('q') search?: string,
@Query('author.github') github?: string,
): Promise<ReadSolutionDto[]> {
): Promise<Solution[]> {
const query: FilterQuery<Solution> = {assignment};
github && (query['author.github'] = github);
if (search) {
Expand Down Expand Up @@ -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<ReadSolutionDto[]> {
): Promise<Solution[]> {
return this.solutionService.findAll({createdBy: user.sub});
}

Expand Down
13 changes: 1 addition & 12 deletions services/apps/assignments/src/solution/solution.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {AsObjectId} from "@mean-stream/nestx";
import {IsOptional} from "class-validator";

const excluded = [
'_id',
'token',
'assignment',
'createdBy',
Expand All @@ -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;
*/
}
5 changes: 4 additions & 1 deletion services/apps/assignments/src/solution/solution.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
IsUUID,
ValidateNested,
} from 'class-validator';
import {Document} from 'mongoose';
import {Document, Types} from 'mongoose';

export class Consent {
@Prop()
Expand Down Expand Up @@ -79,6 +79,9 @@ export class AuthorInfo {

@Schema()
export class Solution {
@ApiProperty()
_id: Types.ObjectId;

@Prop()
@ApiProperty()
token: string;
Expand Down
5 changes: 2 additions & 3 deletions services/apps/assignments/src/solution/solution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -27,10 +27,9 @@ export class SolutionService {
return created;
}

async findAll(where: FilterQuery<Solution> = {}): Promise<ReadSolutionDto[]> {
async findAll(where: FilterQuery<Solution> = {}): Promise<Solution[]> {
return this.model
.find(where)
.select(['-token'])
.sort('author.name author.github timestamp')
.collation({locale: 'en', caseFirst: 'off'})
.exec();
Expand Down

0 comments on commit 0849112

Please sign in to comment.