Add scripts
This commit is contained in:
163
scripts/create-super-admin.js
Normal file
163
scripts/create-super-admin.js
Normal file
@@ -0,0 +1,163 @@
|
||||
const db = require('mantra-db-models');
|
||||
const prompt = require("prompt")
|
||||
|
||||
db.init().then(() => {
|
||||
// We could probably run the things in the seeders...
|
||||
db.Role.findAll()
|
||||
.then(roles => {
|
||||
if(roles.length == 0) {
|
||||
return db.Role.bulkCreate([
|
||||
{
|
||||
type: "user",
|
||||
description: "All users should have this role..."
|
||||
},
|
||||
{
|
||||
type: "admin",
|
||||
description: "This role takes care of the things in the club..."
|
||||
},
|
||||
{
|
||||
type: "superadmin",
|
||||
description: "The user that can do all the things on the system..."
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
return roles;
|
||||
}
|
||||
})
|
||||
.then(roles => {
|
||||
// Roles have been made and all...
|
||||
console.log()
|
||||
// Now we can create the admin account...
|
||||
var schema = {
|
||||
properties: {
|
||||
email: {
|
||||
description: 'Enter admin email', // Prompt displayed to the user. If not supplied name will be used.
|
||||
type: 'string',
|
||||
message: 'Please enter admin email',
|
||||
required: true
|
||||
},
|
||||
displayName: {
|
||||
description: 'Enter admin displayName', // Prompt displayed to the user. If not supplied name will be used.
|
||||
type: 'string',
|
||||
pattern: /^[a-zA-Z\s\-]+$/,
|
||||
message: 'Name must be only letters, spaces, or dashes',
|
||||
required: true
|
||||
},
|
||||
// phoneNumber: {
|
||||
// description: `Enter admin phonenumber (please use country calling code)`, // Prompt displayed to the user. If not supplied name will be used.
|
||||
// type: 'string',
|
||||
// pattern: /^[1-9][0-9]*$/,
|
||||
// message: 'Please enter phone number with the country code',
|
||||
// required: true
|
||||
// },
|
||||
password: {
|
||||
description: 'Enter admin password', // Prompt displayed to the user. If not supplied name will be used.
|
||||
type: 'string',
|
||||
message: 'Please enter admin password',
|
||||
hidden: true,
|
||||
replace: '*',
|
||||
required: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
prompt.get(schema, async function (err, result) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
db.User.create({
|
||||
userEmails: [
|
||||
{
|
||||
email: {
|
||||
address: result.email
|
||||
}
|
||||
}
|
||||
],
|
||||
activeEmail: result.email,
|
||||
displayName: result.displayName,
|
||||
// userPhoneNumbers: [
|
||||
// {
|
||||
// phoneNumber: {
|
||||
// number: result.phoneNumber,
|
||||
// confirmedOn: new Date()
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
passwords: [{
|
||||
password: result.password
|
||||
}],
|
||||
emailConfirmedOn: Date.now(),
|
||||
activatedOn: Date.now()
|
||||
}, {
|
||||
include: [
|
||||
{
|
||||
association: db.User.Passwords
|
||||
},
|
||||
{
|
||||
association: db.User.UserEmails,
|
||||
include: [
|
||||
{
|
||||
association: db.UserEmail.Email
|
||||
}
|
||||
]
|
||||
}
|
||||
// {
|
||||
// association: db.User.UserPhoneNumbers,
|
||||
// include: [
|
||||
// {
|
||||
// association: db.UserPhoneNumber.PhoneNumber
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
]
|
||||
})
|
||||
.then(async (user) => {
|
||||
const individualEntity = await db.IndividualEntityUser.create({
|
||||
userId: user.id,
|
||||
entityUser: {
|
||||
userId: user.id,
|
||||
type: "admin",
|
||||
entity: {
|
||||
name: result.displayName,
|
||||
type: "individual"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
include: [
|
||||
{
|
||||
association: db.IndividualEntityUser.EntityUser,
|
||||
include: [
|
||||
{
|
||||
association: db.EntityUser.Entity
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
console.log("Created: ", user.firstName);
|
||||
console.log("Created: ", individualEntity.entityUser.entity.name);
|
||||
console.log("Updated User Password: " + user.passwords[0]);
|
||||
|
||||
// Create this Users Roles...
|
||||
var userRoles = [];
|
||||
for(var i in roles) {
|
||||
var role = roles[i];
|
||||
userRoles.push({
|
||||
userId: user.id,
|
||||
roleId: role.id
|
||||
})
|
||||
};
|
||||
db.UserRole.bulkCreate(userRoles)
|
||||
.then(dbUserRoles => {
|
||||
console.log("Created User Roles: "+ JSON.stringify(dbUserRoles))
|
||||
}).catch(error => {
|
||||
console.error("User Role Error: ", error)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Hanlde error: " + error);
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
88
scripts/init-dialects.js
Normal file
88
scripts/init-dialects.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const db = require('mantra-db-models');
|
||||
const prompt = require("prompt")
|
||||
|
||||
db.init().then(() => {
|
||||
// We could probably run the things in the seeders...
|
||||
db.Language.findAll()
|
||||
.then(languages => {
|
||||
if (languages.length == 0) {
|
||||
// TODO: Create languages
|
||||
return db.Language.bulkCreate([
|
||||
{
|
||||
id: "en",
|
||||
name: "English",
|
||||
displayName: "English",
|
||||
},
|
||||
{
|
||||
id: "st",
|
||||
name: "Sesotho",
|
||||
displayName: "Sesotho",
|
||||
},
|
||||
{
|
||||
id: "zu",
|
||||
name: "Isizulu",
|
||||
displayName: "Isizulu",
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return languages
|
||||
}
|
||||
}).then(languages => {
|
||||
return db.Continent.findAll()
|
||||
}).then(continents => {
|
||||
if (continents.length == 0) {
|
||||
return db.Continent.bulkCreate([
|
||||
{
|
||||
id: "afr",
|
||||
name: "Africa"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return continents
|
||||
}
|
||||
}).then(continents => {
|
||||
return db.Country.findAll()
|
||||
}).then(countries => {
|
||||
if (countries.length == 0) {
|
||||
return db.Country.bulkCreate([
|
||||
{
|
||||
id: "int",
|
||||
name: "International"
|
||||
},
|
||||
{
|
||||
id: "zaf",
|
||||
name: "South Africa"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return countries
|
||||
}
|
||||
}).then(countries => {
|
||||
return db.Dialect.findAll()
|
||||
}).then(dialects => {
|
||||
if (dialects.length == 0) {
|
||||
// TODO: Create dialects
|
||||
return db.Dialect.bulkCreate([
|
||||
{
|
||||
name: "English",
|
||||
countryId: "int",
|
||||
languageId: "en"
|
||||
},
|
||||
{
|
||||
name: "Sesotho",
|
||||
countryId: "zaf",
|
||||
languageId: "st"
|
||||
},
|
||||
{
|
||||
name: "Zulu",
|
||||
countryId: "zaf",
|
||||
languageId: "zu"
|
||||
}
|
||||
])
|
||||
} else {
|
||||
return dialects
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("Error: ", error)
|
||||
})
|
||||
})
|
||||
20
scripts/init-license.js
Normal file
20
scripts/init-license.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const db = require('mantra-db-models');
|
||||
const prompt = require("prompt")
|
||||
|
||||
db.init().then(() => {
|
||||
// We could probably run the things in the seeders...
|
||||
db.License.findAll()
|
||||
.then(licenses => {
|
||||
if (licenses.length == 0) {
|
||||
// TODO: Create languages
|
||||
return db.License.create({
|
||||
id: "copyright",
|
||||
name: "Copyright"
|
||||
})
|
||||
} else {
|
||||
return licenses
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error("Error: ", error)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user