Commit e56a34cb authored by Bruno Meyer's avatar Bruno Meyer 😢

Add Model and Bloco models & admin Role

parent e6e81943
# Models Descriptions
## Sala
- Públic: `False`
- Attributes
* localizacao : **geopoint** `Required`
* capacidade : **number** `Required`, default=`0`
* tipo : *string* `Required`, default=`"normal"`
* restrita : **boolean** `Required`, default=`false`
- ACLs
* All permissions not specified is `DENY`
- Relations
* Belongs to : **Bloco**
## Bloco
- Públic: `True`
- Attributes
* localizacao : **geopoint** `Required`
* tamanho : **number** `Required`, default=`0`
- ACLs
* All permissions not specified is `DENY`
* **$authenticated** ROLE have all READ operations
* **admin** ROLE have all EXECUTE, READ and WRITE operations
- Relations
* Has many : **Sala** `nestRemoting`, `disableInclude`
\ No newline at end of file
'use strict';
module.exports = function(Bloco) {
};
{
"name": "Bloco",
"plural": "blocos",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"localizacao": {
"type": "geopoint",
"required": true
},
"tamanho": {
"type": "number",
"required": true,
"default": 0
}
},
"validations": [],
"relations": {
"salas": {
"type": "hasMany",
"model": "Sala",
"foreignKey": "",
"options": {
"nestRemoting": true,
"disableInclude": true
}
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
},
{
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"accessType": "READ"
},
{
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property":"*"
}
],
"methods": {}
}
'use strict';
module.exports = function(Sala) {
};
{
"name": "Sala",
"plural": "salas",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"localizacao": {
"type": "geopoint",
"required": true
},
"capacidade": {
"type": "number",
"required": true,
"default": 0
},
"tipo": {
"type": "string",
"required": true,
"default": "normal"
},
"restrita": {
"type": "boolean",
"required": true,
"default": false
}
},
"validations": [],
"relations": {
"bloco": {
"type": "belongsTo",
"model": "Bloco",
"foreignKey": ""
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY",
"property": "*"
}
],
"methods": {}
}
module.exports = function(app) {
var User = app.models.User;
var Bloco = app.models.Bloco;
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
// TODO: Create conditions and check the dev mode to seed data for testing purposes
// Test Data
Bloco.create([
{"localizacao": {"lat": 0,"lng": 0},"tamanho": 0}
],function(err,users){
console.log("Created a block");
});
User.create([
{username: 'admin', email: 'admin@admin.com', password: '123mudar'}
], function(err, users) {
if (err) throw err;
console.log('Created users:', users);
// Roles definitions
// Define the Roles only after create initial users
// This code needs occour in that order because the Roles
// assignments will need initial users
Role.create({
name: 'admin'
}, function(err, role) {
if (err) throw err;
console.log('Created role:', role);
role.principals.create({
principalType: RoleMapping.USER,
principalId: users[0].id
}, function(err, principal) {
if (err) throw err;
console.log('Assign admin Role to initial User:', users[0].email);
});
});
});
};
\ No newline at end of file
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"User": {
"dataSource": "db"
},
"AccessToken": {
"dataSource": "db",
"public": false
},
"ACL": {
"dataSource": "db",
"public": false
},
"RoleMapping": {
"dataSource": "db",
"public": false,
"options": {
"strictObjectIDCoercion": true
}
},
"Role": {
"dataSource": "db",
"public": false
},
"Sala": {
"dataSource": "db",
"public": true
},
"Bloco": {
"dataSource": "db",
"public": true
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment