Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 68f1d70

Browse files
Ken HasenbankKen Hasenbank
Ken Hasenbank
authored and
Ken Hasenbank
committed
log non existing tasks
1 parent 9a0b188 commit 68f1d70

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

api/src/models/Course.ts

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ courseSchema.statics.importJSON = async function (course: ICourse, admin: IUser)
137137
// 1. Duplicate -> 'name (copy)', 2. Duplicate -> 'name (copy 2)', 3. Duplicate -> 'name (copy 3)', ...
138138
course.name = origName + ((i > 0) ? ' (copy' + ((i > 1) ? ' ' + i : '') + ')' : '');
139139
isCourseDuplicated = (await Course.findOne({name: course.name})) !== null;
140-
console.log(course.name + ' -> ' + ((isCourseDuplicated) ? 'Duplicate' : 'OK'));
141140
i++;
142141
} while (isCourseDuplicated);
143142
const savedCourse = await new Course(course).save();

api/src/models/units/TaskUnit.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {ITaskModel, Task} from '../Task';
55
import {ITask} from '../../../../shared/models/task/ITask';
66
import {InternalServerError} from 'routing-controllers';
77
import {ILectureModel, Lecture} from '../Lecture';
8+
import * as winston from 'winston';
89

910
interface ITaskUnitModel extends ITaskUnit, mongoose.Document {
1011
exportJSON: () => Promise<ITaskUnit>;
@@ -49,8 +50,13 @@ taskUnitSchema.methods.exportJSON = async function() {
4950

5051
for (const taskId of tasks) {
5152
const task: ITaskModel = await Task.findById(taskId);
52-
const taskExport = await task.exportJSON();
53-
obj.tasks.push(taskExport);
53+
54+
if (task) {
55+
const taskExport = await task.exportJSON();
56+
obj.tasks.push(taskExport);
57+
} else {
58+
winston.log('warn', 'task(' + taskId + ') was referenced by unit(' + this._id + ') but does not exist anymore');
59+
}
5460
}
5561

5662
return obj;

0 commit comments

Comments
 (0)