1.0.13 • Published 5 years ago
ynov v1.0.13
ynov-express
Entity JSON File
A JSON file you need to create an entity
Structure
- name : string
The name of the entity
- path : string
The root path for the entity - ref (optional) : string
In case of using "belongsTo" relationship, the name of the linked entity
- authorized (optional) : Array<string>
An array of string that represents authorized user roles to define what type of user can access to the different routes
- actions (optional) : Array<string|Action>
An array of string or Action type that defines what actions are enabled for the entity controller
The default methods are : find, findById, create, update, modify, delete
- customActions (optional) : Array<string|Action>
An array of string or Action type that contains the custom actions defined by the user schema : object
The schema of the entity propertiesbelongsTo (optional) : Array<EntityJson>
The related entities to define "belongsTo" relationships- hasMany (optional) : Array<EntityJson>
The related entities to define "hasMany" relationships
Example
{
"name": "Post",
"path": "/posts",
"actions": ["find", "findById", "create", "update", "modify", "delete"],
"schema": {
"title": "string",
"content": "string"
},
"belongsTo": [
{
"name": "author",
"ref": "User",
"path": "/authors",
"schema": {
"login": "string",
"password": "string"
}
}
]
}
Configuration File
A .yconf.ts file that exports JS object that overwrites the default configuration parameters
Structure
All the parameters are optionals.
The file should be in the root directory of the application. If the .yconf.ts file doesn't exist, the default configuration is used.
- appName : string
The name of the application
- root : string
The root directory of the application (import and use path is recommended)
By default : - entitiesDir : string
The entities directory of the application (import and use path is recommended)
By default : - port : number
The port used to request the server secret : string
A secret string for the application By default :db : object
An object that contains database informations
Example
{
appName: "My Application",
root: path.resolve(__dirname, "../../"),
entitiesDir: path.resolve(__dirname, "../Jsons"),
port: 8080,
secret: Math.random().toString(36),
db: {
get url(){
return `mongodb://${this.host}:${this.port}/${this.name}`
},
host: "localhost",
port: "27017",
name: "test"
}
}
Overwrite Youter
Example
import {Youter} from "ynov"
export class NameController extends Youter {
constructor(options){
super(options)
}
// Custom Action Example
functionName() {
return (req, res) => {
this.model.find().then(data => {
res.json('Bienvenue sur notre api')
}).catch(err => {
res.json(err)
})
}
}
// surcharge function
create() {
return (req, res) => {
this.model.find().then(data => {
res.json('Bienvenue sur notre api')
}).catch(err => {
res.json(err)
})
}
}
}
export default NameController