From 24e44e1607c2b55612957236fc25367b2fdf5ec6 Mon Sep 17 00:00:00 2001 From: Yaman Qalieh Date: Thu, 18 Aug 2016 19:08:58 -0400 Subject: [PATCH] check if code exists --- hourglass/server/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 48cf460..d72b211 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -88,7 +88,11 @@ Security.permit(['insert', 'update', 'remove']).collections([schools, classes, w Meteor.methods({ 'genCode': function() { - return Math.random().toString(36).substr(2, 6); + currcode = Math.random().toString(36).substr(2, 6); + while (classes.findOne({code: currcode}) !== undefined) { + currcode = Math.random().toString(36).substr(2, 6); + } + return currcode; }, 'createSchool': function(schoolname) { if (Meteor.user() !== null &&