Projecto ref: loopback
- platform: Bluemix
- Nodejs + loopback
- data: Cloudant
loopback:datasource: cloudante (cloudantCraftDB)database: handcraft
loopback:model Handcraft Base class: PersistedModel
| Property name | Property type | Required | Default |
|---|---|---|---|
| name | string | yes | |
| segment | string | yes | |
| feedstock | string | yes | |
| category | string | yes | |
| label | string | " " | |
| price | number | no | |
| description | string | yes | |
| timestamp | mixins | yes |
{
"name": "Handcraft",
"base": "PersistedModel",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"mixins": {
"TimeStamp": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"segment": {
"type": "string"
},
"feedstock": {
"type": "string"
},
"category": {
"type": "string"
},
"label": {
"type": "string"
},
"price": {
"type": "number"
},
"description": {
"type": "string"
}
},
"validations": [],
"relations": {
"comments": {
"type": "hasMany",
"model": "Comment",
"foreignKey": ""
},
"customers": {
"type": "hasMany",
"model": "Customer",
"foreignKey": ""
},
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {}
}
loopback:model Comment Base class: PersistedModel
| Property name | Property type | Required | Default |
|---|---|---|---|
| rating | number | yes | |
| description | string | yes | |
| timestamp | mixins | yes |
{
"name": "Comment",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"mixins": {
"TimeStamp": true
},
"properties": {
"rating": {
"type": "number",
"required": true
},
"comment": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"handcraft": {
"type": "belongsTo",
"model": "Handcraft",
"foreignKey": ""
},
"customer": {
"type": "belongsTo",
"model": "Customer",
"foreignKey": "publisherId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {}
}
loopback:model Customer Base class: User
| Property name | Property type | Required | Default |
|---|---|---|---|
| timestamp | mixins | yes |
"name": "Customer",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"mixins": {
"TimeStamp": true
},
"properties": {},
"validations": [],
"relations": {
"comments": {
"type": "hasMany",
"model": "Comment",
"foreignKey": "publisherId"
}
},
"acls": [],
"methods": {}
}
loopback:model Favorite Base class: PersistedModel
| Property name | Property type | Required | Default |
|---|---|---|---|
| timestamp | mixins | yes |
{
"name": "Favorite",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"description": {
"type": "string"
}
},
"mixins": {
"TimeStamp": true
},
"validations": [],
"relations": {
"handcrafts": {
"type": "hasMany",
"model": "Handcraft",
"foreignKey": ""
},
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {}
}
- A handcraft has many comments.
- A handcraft belong to a customers.
- A comment belongs to a handcraft.
- A comment belongs to a customer.
- A customer has many comments.
- A favorite has many handcrafts.
- A favorite belongs to a Customer
- Anyone can read comment, but you must be logged in to create, edit, or delete them.
- Anyone can register as a user; then log in and log out.
- Logged-in users can create new comments, and edit or delete their own comemnts. however they cannot modify the handcraft for a comment.
- Logged-in users can create new Handcrat, and edit or delete their own Handcraft.
- Logged-in users can create new Favorite, and edit or delete their own Favorite; however the user owning the object.
Create AngularJS client - Generate lb-services.js
add:
server/middleware.json>> "files": { > "loopback#static": { > "params": "$!../client" > } > }, >
add:
client/index.html
add:client/handcraft.html
add:client/comment-form.html
add:client/list-all.html
add:client/success.html