Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | module.exports = function(app) { const User = app.models.endUser; const Role = app.models.Role; const RoleMapping = app.models.RoleMapping; const logger = require('../../services/logger'); function newRole(roleName) { Role.find({where: { name: roleName}}, function(err, results) { Iif (err) throw err; Iif (results.length < 1) { Role.create({ name: roleName }, function(err, role) { if (err) throw err; logger.info(`Created role ${role}`); // Create admin. if (roleName === 'admin') { User.create({email: 'admin@codemen.fi', password: 'testi', emailVerified:'true'}, function(err, userInstance) { logger.info(`Created user: ${userInstance.email}`); role.principals.create({ principalType: RoleMapping.USER, principalId: userInstance.id }, function(err, principal) { if (err) throw err; logger.info(`Created principal: ${principal}`); }); }); } }); } }); } newRole('admin'); User.find({where: { email: 'administrator@codemen.fi'}}, function(err, result) { Iif (err) throw err; Eif (result.length < 1) { function callback(err){ throw err; } User.createUser('administrator@codemen.fi', 'testi', 'administrator', null, null, callback); } }); }; |