Skip to content

Commit 2a86c03

Browse files
committed
Using isNil
1 parent 346f0ad commit 2a86c03

10 files changed

Lines changed: 30 additions & 23 deletions

File tree

both/collections/user.collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
if (this.isGlobalAdministrator(user_id)){
6262
return Role.global_admin;
63-
} else if (_.isUndefined(res) || _.isNull(res)) {
63+
} else if (_.isUndefined(res) || _.isNil(res)) {
6464
return Role.guest;
6565
} else {
6666
return res.role;
@@ -90,7 +90,7 @@
9090
// getCourseRecordFor
9191
UsersCollection.getCourseRecordFor = function(course_id : string, user_id : string) : string {
9292
let res = this.getPrivilegeFor(course_id, user_id);
93-
if (typeof res === "undefined") {
93+
if (_.isNil(res)) {
9494
return undefined;
9595
} else {
9696
return res.course_record;

client/imports/account/auth-guard.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class AuthGuard implements CanActivate, CanActivateChild {
1212
}
1313

1414
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
15-
if(_.isNull(Meteor.userId())){
15+
if(_.isNil(Meteor.userId())){
1616
this.router.navigate(['/login'], { queryParams : { redirect_url: state.url }});
1717
return false;
1818
} else {

client/imports/admin/admin_user_list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
.afterClosed()
688688
.first()
689689
.subscribe((user) => {
690-
if(!_.isNull(user)){
690+
if(!_.isNil(user)){
691691
Meteor.call('Users.addRoleForCourse', {
692692
course_id : this.course_query._id,
693693
user_id :user._id,

client/imports/course/course_view.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
this.course_behaviorSubject
8888
.subscribe((course) => {
8989
this.zone.run(() => {
90-
if(!_.isNull(course)){
90+
if(!_.isNil(course)){
9191
this.course_model = course;
9292
}
9393
});
@@ -115,7 +115,7 @@
115115
// Get Instructors
116116
this.instructors = this.course
117117
.distinct()
118-
.filter(x => !_.isNull(x))
118+
.filter(x => !_.isNil(x))
119119
.mergeMap((course) => {
120120
Meteor.subscribe('users.instructors', course._id);
121121
return Users.observable
@@ -154,7 +154,7 @@
154154
// Get Course Record
155155
this.course_record = this.course
156156
.distinct()
157-
.filter(x => !_.isNull(x))
157+
.filter(x => !_.isNil(x))
158158
.mergeMap((course) => {
159159
Meteor.subscribe('course_records.id', course._id, Meteor.userId());
160160
var course_record = CourseRecords.findOne({ user_id : Meteor.userId(), course_id : course._id });
@@ -168,7 +168,7 @@
168168
// Get Labs
169169
this.labs = this.course
170170
.distinct()
171-
.filter(x => !_.isNull(x))
171+
.filter(x => !_.isNil(x))
172172
.mergeMap((course) => {
173173
Meteor.subscribe('labs.course', course._id);
174174
return Labs.observable.find({ course_id : course._id })
@@ -217,7 +217,7 @@
217217
private addInstructor(){
218218
var dialogRef = this.dialog.open(SelectUser, { width: '600px' });
219219
dialogRef.afterClosed().subscribe((user) => {
220-
if(!_.isNull(user)){
220+
if(!_.isNil(user)){
221221
this.addRole(user._id, Role.instructor);
222222
}
223223
})
@@ -226,7 +226,7 @@
226226
private addCourseAdmin(){
227227
var dialogRef = this.dialog.open(SelectUser, { width: '600px' });
228228
dialogRef.afterClosed().subscribe((user) => {
229-
if(!_.isNull(user)){
229+
if(!_.isNil(user)){
230230
this.addRole(user._id, Role.course_admin);
231231
}
232232
})

client/imports/lab/lab_terminal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737

3838
onResize(){
39-
if(!_.isNull(this.xterm)){
39+
if(!_.isNil(this.xterm)){
4040
this.xterm.fit();
4141
}
4242
}

client/imports/lab/lab_view.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
new Promise((resolve, reject) => {
7272
Meteor.subscribe('labs.course',course_id, () => {
7373
var lab = Labs.findOne({ _id : lab_id });
74-
if(_.isNull(lab)){
74+
if(_.isNil(lab)){
7575
this.router.navigate(['/error','404']);
7676
} else {
7777
resolve(lab);

server/imports/api/lab.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@
7171
}
7272

7373
export function isValidLabObject (sandbox : any) : sandbox is { Lab : typeof Lab } {
74-
if (typeof sandbox === "undefined") {
74+
if (_.isNil(sandbox)) {
7575
throw new Error("SandboxUndefined");
76-
} else if (typeof sandbox.Lab === "undefined"){
76+
} else if (!_.has(sandbox, "Lab")){
7777
throw new Error("LabUndefined");
78-
} else if (typeof sandbox.Lab.name === "undefined"){
78+
} else if (!_.has(sandbox, "Lab.name")){
7979
throw new Error("LabNameUndefined");
80-
} else if (typeof sandbox.Lab._vm === "undefined"){
80+
} else if (!_.has(sandbox, "Lab._vm")){
8181
throw new Error("VMUndefined");
82-
} else if (typeof sandbox.Lab._tasks === "undefined") {
82+
} else if (!_.has(sandbox, "Lab._tasks")) {
8383
throw new Error("TaskUndefined");
8484
} else if (_.every(sandbox.Lab._vm, isValidTaskObject)){
8585
throw new Error("InvalidTask");

server/imports/runtime/container.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
let prepare_containers : Promise<Dockerode.Container>;
5656

5757
// Create Container
58-
if (typeof id === "undefined") {
58+
if (_.isNil(id)) {
5959

6060
// Pull Image
6161
prepare_containers = Container.docker.pull(this.config.image, {})
@@ -83,11 +83,18 @@
8383
return container.start();
8484
})
8585

86-
} else if (typeof id === "string"){
86+
} else if (typeof id === "string") {
8787
// Get Container
8888
prepare_containers = new Promise((resolve, reject) => {
89-
resolve(Container.docker.getContainer(id));
89+
if (_.isNil(Container.docker.getContainer(id))){
90+
reject(new Meteor.Error("Could not find Docker Container."));
91+
} else {
92+
resolve(Container.docker.getContainer(id));
93+
}
9094
});
95+
96+
} else {
97+
throw new Meteor.Error("Invalid id argument");
9198
}
9299

93100
this._ready = prepare_containers

server/imports/runtime/lab_runtime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { VMConfig, VMResolveConfig, VMConfigCustom } from '../api/vmconfig';
1919
import { Lab, isValidLabObject } from '../api/lab'
20-
import { InitObject, SetupObject, VerifyObject } from '../api/environment';
20+
import { InitObject, SetupObject, VerifyObject } from '../api/environment';
2121

2222
/*
2323
LabSandbox
@@ -165,7 +165,7 @@
165165

166166
let lab_model = Labs.findOne({ _id : lab_id });
167167

168-
if (typeof lab_model === "undefined"){
168+
if (_.isNil(lab_model)){
169169
reject(new Error("Lab Not Found"));
170170

171171
} else {

server/methods/lab.methods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
function labsCourse(course_id){
1313

1414
let course = Courses.findOne(course_id);
15-
if (_.isNull(course) || _.isUndefined(course)){
15+
if (_.isNil(course) || _.isUndefined(course)){
1616
throw new Meteor.Error("Course not Found");
1717
}
1818

0 commit comments

Comments
 (0)