npm package: @mqict/adonis-controller
Description: MQ-Controller is a set of base Controller for MQ's Team server. MQ-Controller runs on **Adonisjs 4**,
Latest version: 1.0.0

# Welcome to MQ-Controller!
MQ-Controller is a set of base Controller for MQ's Team server.
MQ-Controller runs on **Adonisjs 4**,

# Install
npm install @mqict/adonis-controller

in Controller file: use use('@mqict/adonis-controller') as BaseController.
```javascript
	const Controller =  use('@mqict/adonis-controller')
    class  ApiController  extends  Controller {
    	.....
    }
```	

in start/routes.js:
```javascript
const Route = use('Route')
const { ioc } = use('@adonisjs/fold') //<---- add
const pluralize = use('pluralize') //<---- add
....
Route.post('/:controller/getdata',  ({view ,request, response,params}) => {
	const controller = pluralize.singular(params.controller)
	const url = `App/Controllers/Http/Api/${controller}Controller.getData`
	const controllerInstance = ioc.makeFunc(url)
	return controllerInstance.method.apply(controllerInstance.instance,[{view,request,response}])
})
Route.post('/:controller/getschema',  ({view ,request, response,params}) => {
	const controller = pluralize.singular(params.controller)
	const url = `App/Controllers/Http/Api/${controller}Controller.getSchema`
	const controllerInstance = ioc.makeFunc(url)
	return controllerInstance.method.apply(controllerInstance.instance,[{view,request,response}])
})


```

# Using
```javascript
{{host}}/api/students/getdata (POST method)

BODY:
{
	"fields": {
		"firstname": 1,
		"lastname": 1,
		"basicClass": {
			"_id": 1,
			"name": 1,
			"students": {
				"_id": 1,
				"firstname": 1,
				"lastname": 1,
				"$limit": 1
			},
			"occupation": {
				"_id": 1,
				"name": 1,
				"institute": {
					"_id": 1,
					"name": 1
				}
			}
		}
	},
	"conditions": {
		"firstname": "đức"
	},
	"page": 0,
	"pageSize": 20,
	"sorted": [
		{"id": "firstname", "desc": true}
	]
}
```	
output:
```javascript
{
    "total": 2,
    "perPage": 20,
    "lastPage": 1,
    "page": 1,
    "data": [
        {
            "_id": "5b8f2e822d904647341c5838",
            "firstname": "Đỗ Đức",
            "lastname": "Thu",
            "basicClass": {
                "_id": "5b8e61a0269e861e1c150b86",
                "name": "co so nghanh 2 k9",
                "students": [
                    {
                        "_id": "5b8e4f172d904647341c582a",
                        "firstname": "Đinh Đức",
                        "lastname": "Thuận"
                    }
                ],
                "occupation": {
                    "_id": "5b7675b712e8540b92191b68",
                    "name": "Nghề thiết kế đồ họa",
                    "institute": {
                        "_id": "5b767592a8cc5c0b8a643623",
                        "name": "Khoa Công Nghệ Thông Tin"
                    }
                }
            }
        },
        {
            "_id": "5b8e4f172d904647341c582a",
            "firstname": "Đinh Đức",
            "lastname": "Thuận",
            "basicClass": {
                "_id": "5b8e47650ae80929d4da6ffc",
                "name": "Cơ sở nghành K9",
                "students": [
                    {
                        "_id": "5b8e4f172d904647341c5823",
                        "firstname": "Nguyễn Chí",
                        "lastname": "Tài"
                    }
                ],
                "occupation": {
                    "institute": {}
                }
            }
        }
    ]
}
```

###get schema:
```javascript
{{host}}/api/students/getschema (GET method)
```
output
```javascript
{
    "_id": "objectid",
    "code": "string",
    "firstname": "string",
    "lastname": "string",
    "birthday": "string",
    "identified_number": "string",
    "gender": "string",
    "place_of_birth": "string",
    "hometown": "string",
    "address": "string",
    "phone": "string",
    "area": "string",
    "ethnic": "string",
    "relationships": "array",
    "courseId": "objectid",
    "status": "number",
    "created_at": "moment",
    "updated_at": "moment",
    "basicClassId": "objectid",
    "specifiedClassId": "object",
    "fees": "array",
    "course": "function",
    "basicClass": "function",
    "specifiedClass": "function"
}
```
NgocHip