POST subtask/{id}/timesheet

This commit is contained in:
StudioTem committed 2023-02-14 09:15:33 +01:00
1 parent 0d2a659049
commit ef2ab75ce4
2 files changed
+20 -8

No files matched your search

+19 -5
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -45,13 +46,15 @@ class SubTask extends Model
$item['user_id'] = $item['employee_id'];
unset($item['employee_id']);
$item['sub_task_id'] = $this->id;
$item['created_at'] = Carbon::now();
$item['updated_at'] = Carbon::now();
return $item;
}, $timesheets);
$this->timesheets()->upsert($timesheets, ['id']);
// zmazanie vykazov, ktore neboli poslane z frontendu
$this->timesheets()->whereNotIn('id', collect($timesheets)->pluck('id')->filter())->delete();
// zmazanie vykazov, ktore boli poslane z frontendu
$this->timesheets()->whereNotIn('id', collect($timesheets)->pluck('id'))->delete();
$this->timesheets()->upsert($timesheets, ['id']);
}
public function syncTimeblocks(Array $timeblocks)
@@ -62,10 +65,21 @@ class SubTask extends Model
return $item;
}, $timeblocks);
// zmazanie vykazov, ktore neboli poslane z frontendu
$this->timeblocks()->whereNotIn('id', collect($timeblocks)->pluck('id')->filter())->delete();
$this->timeblocks()->upsert($timeblocks, ['id']);
}
// zmazanie vykazov, ktore boli poslane z frontendu
$this->timeblocks()->whereNotIn('id', collect($timeblocks)->pluck('id'))->delete();
public function deleteAttachments()
{
foreach ( $this->attachments as $attachment ) {
$attachment->deleteFromS3();
}
$this->attachments()->delete();
return true;
}
}
+1 -3
View File
@@ -81,9 +81,7 @@ Route::put('/v1/subtasks/{id}', SubTaskController::class . '@update');
Route::get('/v1/subtasks/{id}', function ($id) {
return new SubTaskResource( SubTask::find($id));
});
Route::get('/v1/subtasks/{id}', function ($id) {
return new SubTaskResource( SubTask::find($id));
});
Route::post('/v1/subtasks/{id}/timesheet', SubTaskController::class . '@submitTimesheet');
Route::get('/v1/subtasks',SubTaskController::class . '@index');