# mares-app-service
슬로그업 ddd 패턴의 application layer에서 사용되는 base class

## Installation
`npm install --save mares-app-service`

## Examples

```javascript
const MaresAppService = require('mares-app-service')

class UserAppService extends MaresAppService {
	doSomething() {
		return UserAppService.sendObject(200, {
			id: 1,
			name: 'slogup'
		})
	}
}
```
## Action
### Response Object
Application layer에서는 항상 {status, body}의 형태로 응답을 넘겨주게 됩니다. 이를 정규화 하기 위한 응답 함수입니다. 반드시 return 시에는 다음과 같이 send* 함수를 이용해야 합니다.
```javascript
class UserAppService extends MaresAppService {
	doSomething() {
		return UserAppService.sendObject(200, {
			id: 1,
			name: 'slogup'
		})
	}
}
```

### Response Array
응답해야할 데이터가 배열인 경우 사용 방법입니다. 
```javascript
class UserAppService extends MaresAppService {
	doSomething() {
		const count = 1000
		return UserAppService.sendArray(200, [1,2,3], count)
	}
}
```

### Response Error
응답해야할 데이터가 에러인 경우 사용 방법입니다. 
```javascript
class UserAppService extends MaresAppService {
	async doSomething() {
        try {
            //await call
        } catch (e) {
            UserAppService.sendError(e)
        }
    }
}
```

### Response no contents
```javascript
class UserAppService extends MaresAppService {
	doSomething() {
		const count = 1000
		
		// 두개의 리턴값은 동일합니다.
		return UserAppService.sendNoContents()
		// return UserAppService.sendObject(204, {})
	}
}
```
