Added a api endpoint for sending email notifications to users with their assigned assets

This commit is contained in:
lukasfehling 2022-11-15 18:17:51 +01:00
parent 6dc0846f38
commit d9a9bd1c0d
2 changed files with 39 additions and 0 deletions

View file

@ -15,6 +15,7 @@ use App\Models\Asset;
use App\Models\Company;
use App\Models\License;
use App\Models\User;
use App\Notifications\CurrentInventory;
use Auth;
use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
@ -490,6 +491,37 @@ class UsersController extends Controller
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
}
/**
* Notify a specific user via email with all of his assigned assets.
*
* @author [Lukas Fehling] [<lukas.fehling@adabay.rocks>]
* @since [v6.0.13]
* @param Request $request
* @param $id
* @return string JSON
*/
public function emailAssetList(Request $request, $id)
{
$user = User::findOrFail($id);
if (empty($user->email)) {
return response()->json(
[
'status' => 'error',
'message' => 'This user has no email set.',
'payload' => null,
], 404);
}
$user->notify((new CurrentInventory($user)));
return response()->json(
[
'status' => 'success',
'message' => 'The user was notified about his current inventory.',
'payload' => null,
], 200);
}
/**
* Return JSON containing a list of consumables assigned to a user.

View file

@ -976,6 +976,13 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
]
)->name('api.users.assetlist');
Route::post('{user}/email',
[
Api\UsersController::class,
'emailAssetList'
]
)->name('api.users.email_assets');
Route::get('{user}/accessories',
[
Api\UsersController::class,