add update fields

This commit is contained in:
philipp lang 2021-06-21 23:50:09 +02:00
parent e9cda2f67d
commit 1b2f68d0b2
13 changed files with 81 additions and 44 deletions

View File

@ -16,8 +16,8 @@ class UserResource extends JsonResource
public function toArray($request)
{
return [
'name' => $this->name,
'email' => $this->email,
'name' => $this->getFirstname(),
'email' => null,
'avatar' => [
'src' => Storage::url('avatar.png')
]

View File

@ -2,7 +2,6 @@
namespace App\Initialize;
use App\User;
use App\Member;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
@ -10,6 +9,7 @@ use Aweos\Agnoster\Progress\HasProgress;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Zoomyboy\LaravelNami\NamiUser;
class InitializeJob implements ShouldQueue
{
@ -28,7 +28,7 @@ class InitializeJob implements ShouldQueue
InitializeMembers::class,
];
public function __construct(User $user)
public function __construct(NamiUser $user)
{
$this->user = $user;
}
@ -40,7 +40,7 @@ class InitializeJob implements ShouldQueue
*/
public function handle()
{
$api = $this->user->getNamiApi();
$api = $this->user->api();
$bar = $this->createProgressBar('Initialisiere');
foreach (static::$initializers as $initializer) {

View File

@ -53,6 +53,7 @@ class InitializeMembers {
'country_id' => Country::where('nami_id', $member->country_id)->firstOrFail()->id,
'fee_id' => optional(Fee::firstWhere('nami_id', $member->fee_id ?: -1))->id,
'nationality_id' => Nationality::where('nami_id', $member->nationality_id)->firstOrFail()->id,
'version' => $member->version,
]);
});
});

View File

@ -14,7 +14,6 @@ class InitializeNationalities {
public function handle() {
$this->bar->task('Synchronisiere Nationalitäten', function() {
$this->api->group(auth()->user()->getNamiGroupId())->fees();
$this->api->nationalities()->each(function($nationality) {
\App\Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]);
});

View File

@ -16,7 +16,7 @@ class Member extends Model
use Notifiable;
use HasFactory;
public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id'];
public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'fee_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version'];
public $dates = ['joined_at', 'birthday'];
@ -44,6 +44,10 @@ class Member extends Model
return $this->firstname.' '.$this->lastname;
}
public function getHasNamiAttribute() {
return $this->nami_id !== null;
}
//---------------------------------- Relations ----------------------------------
public function country()
{
@ -106,7 +110,7 @@ class Member extends Model
});
static::updated(function($model) {
UpdateJob::dispatch($model);
UpdateJob::dispatch($model, auth()->user());
});
}
}

View File

@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Zoomyboy\LaravelNami\Nami;
use App\Confession;
class UpdateJob implements ShouldQueue
{
@ -15,10 +16,12 @@ class UpdateJob implements ShouldQueue
public $memberId;
public $member;
public $user;
public function __construct(Member $member)
public function __construct(Member $member, $user)
{
$this->memberId = $member->id;
$this->user = $user;
}
/**
@ -30,7 +33,11 @@ class UpdateJob implements ShouldQueue
{
$this->member = Member::find($this->memberId);
Nami::putMember([
if (!$this->member->hasNami) {
return false;
}
$response = Nami::login($this->user->mglnr)->putMember([
'firstname' => $this->member->firstname,
'lastname' => $this->member->lastname,
'nickname' => $this->member->nickname,
@ -49,14 +56,18 @@ class UpdateJob implements ShouldQueue
'fax' => $this->member->fax,
'email' => $this->member->email,
'email_parents' => $this->member->email_parents,
'gender_id' => optional($this->member)->nami_id,
'confession_id' => optional($this->member->confession)->nami_id,
'gender_id' => optional($this->member->gender)->nami_id,
'confession_id' => $this->member->confession ? $this->member->confession->nami_id : Confession::firstWhere('is_null', true)->id,
'region_id' => optional($this->member->region)->nami_id,
'country_id' => $this->member->country->nami_id,
'fee_id' => optional($this->member->fee)->nami_id,
'nationality_id' => $this->member->nationality->nami_id,
'id' => $this->member->nami_id,
'group_id' => $this->member->group->nami_id,
'version' => $this->member->version,
]);
Member::withoutEvents(function() use ($response) {
$this->member->update(['version' => $response['version']]);
});
}
}

View File

@ -7,11 +7,13 @@
"laravel"
],
"repositories": [
{ "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} }
{ "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} },
{ "type": "path", "url": "./packages/agnoster-installer", "options": {"symlink": true} }
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"aweos/agnoster-installer": "1.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^7.0.1",

46
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "939238f463369e99565304bd5d3e68de",
"content-hash": "d960b31f70a251387c83d7ab9803fb0e",
"packages": [
{
"name": "asm89/stack-cors",
@ -62,6 +62,35 @@
},
"time": "2019-12-24T22:41:47+00:00"
},
{
"name": "aweos/agnoster-installer",
"version": "1.0.0",
"dist": {
"type": "path",
"url": "./packages/agnoster-installer",
"reference": "e33794cdf0a68d161ce22856650c288700cdbd7c"
},
"bin": [
"bin/agnoster"
],
"type": "library",
"autoload": {
"psr-4": {
"Aweos\\Agnoster\\": "src/"
}
},
"authors": [
{
"name": "philipp lang",
"email": "philipp@aweos.de"
}
],
"description": "Agnoster Backend package for UI scaffolding",
"transport-options": {
"symlink": true,
"relative": true
}
},
{
"name": "brick/math",
"version": "0.9.2",
@ -1432,16 +1461,16 @@
},
{
"name": "league/commonmark",
"version": "1.6.2",
"version": "1.6.4",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "7d70d2f19c84bcc16275ea47edabee24747352eb"
"reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/7d70d2f19c84bcc16275ea47edabee24747352eb",
"reference": "7d70d2f19c84bcc16275ea47edabee24747352eb",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c3c8b7217c52572fb42aaf84211abccf75a151b2",
"reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2",
"shasum": ""
},
"require": {
@ -1459,7 +1488,7 @@
"github/gfm": "0.29.0",
"michelf/php-markdown": "~1.4",
"mikehaertl/php-shellcommand": "^1.4",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^0.12.90",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.2",
"scrutinizer/ocular": "^1.5",
"symfony/finder": "^4.2"
@ -1529,7 +1558,7 @@
"type": "tidelift"
}
],
"time": "2021-05-12T11:39:41+00:00"
"time": "2021-06-19T20:08:14+00:00"
},
{
"name": "league/flysystem",
@ -5769,7 +5798,7 @@
"dist": {
"type": "path",
"url": "./packages/laravel-nami",
"reference": "4a89f167f825dc7e58aaf7b426657531163d82cf"
"reference": "009a9b1678b4736d3b45144cf410a5a5c9a27bed"
},
"require": {
"guzzlehttp/guzzle": "^6.3.1|^7.0"
@ -8226,6 +8255,7 @@
"type": "github"
}
],
"abandoned": true,
"time": "2020-09-28T06:45:17+00:00"
},
{

View File

@ -31,7 +31,7 @@ return [
|
*/
'lifetime' => env('SESSION_LIFETIME', 120),
'lifetime' => env('SESSION_LIFETIME', 120000),
'expire_on_close' => false,

View File

@ -51,6 +51,7 @@ class CreateMembersTable extends Migration
$table->foreignId('fee_id')->constrained();
$table->text('letter_address')->nullable();
$table->foreignId('bill_kind_id')->nullable()->constrained();
$table->unsignedInteger('version')->default(1);
$table->timestamps();
});

View File

@ -71,22 +71,13 @@
<f-select :options="billKinds" id="bill_kind_id" v-model="inner.bill_kind_id" label="Rechnung versenden über"></f-select>
</div>
</div>
<div class="grid grid-cols-2 gap-3 p-4" v-if="menuTitle == 'Sonstiges'">
<div>
<f-text id="other_country" v-model="inner.other_country" label="Andere Staatsangehörigkeit"></f-text>
</div>
<div>
<f-switch id="has_nami" v-model="inner.has_nami" label="In Nami eintragen"></f-switch>
</div>
<div>
<f-text type="date" id="joined_at" v-model="inner.joined_at" label="Eintrittsdatum"></f-text>
</div>
<div>
<f-select :options="confessions" id="confession_id" v-model="inner.confession_id" label="Konfession"></f-select>
</div>
<div>
<f-textarea rows="4" id="letter_address" v-model="inner.letter_address" label="Brief-Adresse"></f-textarea>
</div>
<div class="grid grid-cols-4 gap-3 p-4" v-if="menuTitle == 'Sonstiges'">
<f-text class="col-span-2" id="other_country" v-model="inner.other_country" label="Andere Staatsangehörigkeit"></f-text>
<f-switch id="has_nami" v-model="inner.has_nami" label="In Nami eintragen"></f-switch>
<f-switch id="send_newspaper" v-model="inner.send_newspaper" label="Mittendrin"></f-switch>
<f-text class="col-span-2" type="date" id="joined_at" v-model="inner.joined_at" label="Eintrittsdatum"></f-text>
<f-select class="col-span-2" :options="confessions" id="confession_id" v-model="inner.confession_id" label="Konfession"></f-select>
<f-textarea class="col-span-2" rows="4" id="letter_address" v-model="inner.letter_address" label="Brief-Adresse"></f-textarea>
</div>
</div>
</form>

View File

@ -28,9 +28,9 @@ class LoginTest extends TestCase
$key = session()->get('auth_key');
$cache = Cache::get("namiauth-{$key}");
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
$this->assertEquals(123, auth()->user()->mglnr);
$this->assertEquals('Max', auth()->user()->firstname);
$this->assertEquals('Muster', auth()->user()->lastname);
$this->assertEquals(123, auth()->user()->getMglnr());
$this->assertEquals('Max', auth()->user()->getFirstname());
$this->assertEquals('Muster', auth()->user()->getLastname());
$this->assertTrue(auth()->check());
}

View File

@ -24,11 +24,9 @@ abstract class TestCase extends BaseTestCase
]);
$this->fakeNamiPassword(999, 'secret', [12399]);
$api = Nami::login(999, 'secret');
$this->be(new NamiUser([
'cookie' => $api->cookie->toArray(),
$this->be(NamiUser::fromPayload([
'credentials' => [
'mglnr' => 999,
'password' => 'secret'