public function postAddMail(Request $request)
{
$this->validate($request, ['userId' => 'required', 'address' => 'required|email']);
$userId = $request->get('userId');
$address = $request->get('address');
if ($this->handler->emails()->findByAddress($address)) {
throw new MailAlreadyExistsException();
}
$user = $this->handler->users()->find($userId);
XeDB::beginTransaction();
try {
$email = $this->handler->emails()->create($user, $request->only('address', 'userId'));
} catch (Exception $e) {
XeDB::rollBack();
throw $e;
}
XeDB::commit();
return XePresenter::makeApi(['mail' => $email]);
}