add user to project by email

This commit is contained in:
Kavalar 2024-02-06 17:37:02 +03:00
parent 1a8b415062
commit 3a6725947b
2 changed files with 66 additions and 3 deletions

View File

@ -50,7 +50,7 @@ class ProjectUser extends \yii\db\ActiveRecord
public function rules()
{
return [
[['user_id', 'project_id', 'card_id'], 'required'],
[['user_id', 'project_id'], 'required'],
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
['card_id', 'unique', 'targetAttribute' => ['card_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
[['card_id', 'project_id', 'user_id', 'project_role_id', 'status'], 'integer'],

View File

@ -4,6 +4,7 @@ namespace frontend\modules\api\controllers;
use common\models\ProjectTaskCategory;
use common\models\Status;
use common\models\User;
use common\models\UseStatus;
use frontend\modules\api\models\Manager;
use frontend\modules\api\models\project\Project;
@ -538,4 +539,66 @@ class ProjectController extends ApiController
{
return ProjectStatistic::find()->where(['id' => $project_id])->one();
}
/**
*
* @OA\Post(path="/project/add-user-by-email",
* summary="Добавить пользователя в проект по почте",
* description="Метод для добавления пользователя в проект по почте",
* security={
* {"bearerAuth": {}}
* },
* tags={"TaskManager"},
*
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* required={"email", "project_id"},
* @OA\Property(
* property="email",
* type="integer",
* description="Email пользователя",
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* description="Идентификатор проекта",
* ),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="Возвращает объект",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ProjectUsers"),
* ),
* ),
* )
*
* @return ProjectUser
* @throws NotFoundHttpException
*/
public function actionAddUserByEmail(): ProjectUser
{
$request = Yii::$app->request->post();
$project = Project::findOne($request['project_id']);
if (empty($project)) {
throw new NotFoundHttpException('The project not found');
}
$user = User::findByEmail($request['email']);
if (empty($user)) {
throw new NotFoundHttpException('The user not found');
}
$model = new ProjectUser();
$model->user_id = $user->id;
$model->project_id = $project->id;
$model->save();
return $model;
}
}