Skip to content

Commit 8d152a7

Browse files
authored
Change address id from members table to users table and update profile edit and update logic (#130)
* more admin nation todo items to stage 2 * downgrade sass to fix bootstrap warning * update compoer * remove unused parameter from inertia middleware * remove unused library tailwind * remove unused code and add dark mode * fix responsive size * change address_id column from members table to users table * update user register found end page for add address field * update user register back en form validation and store logic * update user register tests * fix "update user register found end page for add address field" missing save found end page * update phpunit test memory limit * add more todo item * fix nav Collapse responsive * fix missing super administrator role * move updateAddress function from AdmissionTest Controller to Address model for share to user and admin user controller * update user profile for add address * update user update profile back end form validation and update logic for add address * update user update profile tests for add address * fix register tests missing add address too long test care * add auto add required mark css and fix some labels missing "for" attribute * fix some table missing unique attribute * fix user tests same function name wrong * fix user profile when district_is null districtValue is not '' * update admin user show for add address * update admin user update back end form validation and update logic for add address * update admin update user update tests for add address * add active member and has in progress membership order must type address rule for user update and update tests * move the validation logic form user controller login and update method to form validation class and fix missing incorrect password test * fix removed field "login_ip" missing update UserLoginLog model * fix missing update usar admin index label missing "for" * add member data edit and update function to inside user edit and update, update tests * fix missing hidden show member data div when editing * fix passport format fail message missing format info * rename prior_evidence_resulis table is_pass column name to is_accepted * change qualifying_test_details.score to nullable * add is_refunded column to prior_evidence_orders table and update model * add refunded_quota column to admission_test_orders table, update model and update user model hasUnusedQuotaAdmissionTestOrder relatiom method logic * fix prior_evidence_orders.is_returned wrony type to is_refunded * add canEditPassportInformation method to user model and add tests * change user can update passport information on profile if user match requestment * update todo lists * fix coding style * fix insert prior_evidence_orders.status wrong type full refunded to full_refunded * fix CanEditPassportInformationTest create prior_evidence_orders record missing set price value * fix relationship create missing type_id data change to user factory create than attach the relationship * fix copy test cases misssing update roure data * add membershipOrder relationship method to user model * fix membership order in progress, user address should be required but missing and update tests * add more todo items * fix missing gateway_type and gateway_id * fix coding style * fix wrong type "taken_on" to "test_on"
1 parent aaba8ba commit 8d152a7

File tree

55 files changed

+3016
-1445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3016
-1445
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,10 @@ Please read laravel official documents:
6767

6868
#### stage 1 permission system, nav, custom web page and admission test
6969

70-
- change address_id from members table to users table
70+
- add can_join_admission_test column to passport_types table
7171
- change module to support submodule
7272
- add edit candidate and edit candidate result permission and update admin admission test candidate permission checking
7373
- change SEO from page to layout export props title, desc. and ogImage and change ogImage from public to storage
74-
- add admin nation index
75-
- add admin nation store
76-
- add admin nation update
77-
- add admin nation update status
7874
- update candidate store method to support select product and contact stripe
7975
- add stripe checkout web hock handle
8076
- change quota validity months to inside product and order table
@@ -93,10 +89,17 @@ Please read laravel official documents:
9389
- admin user add admission test orders list and create order button
9490
- Add assign roles function to admin user show
9591
- Admin team show page add team member list and relation role
96-
- change whatsapp from twilio to whatsapp cloud api (coming soon)
92+
- add whatsapp_templates table, add seeder and add admin whatsapp templates index
93+
- add admin whatsapp templates index edit and update
94+
- change qr code to from quickchart.io gen image link to use twilio assets
95+
- add user delete function
9796

9897
#### stage 2 third party iq test result
9998

99+
- add admin nation index
100+
- add admin nation store
101+
- add admin nation update
102+
- add admin nation update status
100103
- Add admin third party iq test accept list store
101104
- Add admin third party iq test accept list index
102105
- Add admin third party iq test accept list update name
@@ -123,7 +126,7 @@ Please read laravel official documents:
123126
- Add membership products edit
124127
- Add membership products price store
125128
- Add membership products price update
126-
- Add membership orders create
129+
- Add membership orders create (require user address)
127130
- Add membership orders index
128131
- Add membership orders show
129132
- Add membership orders update payment status
@@ -135,6 +138,8 @@ Please read laravel official documents:
135138
- add user public option on user show
136139
- Add member index
137140
- Add member show
141+
- Add upload image to profile when user is member
142+
- Add remove image to profile when user is member
138143
- Add edit forwarding email function
139144
- Add admin forwarding email changing index and approve or reject function
140145

@@ -200,6 +205,10 @@ Please read laravel official documents:
200205

201206
#### stage 8 contest (coming soon)
202207

208+
#### stage 9 CalDAV (coming soon)
209+
210+
#### stage 10 project management (coming soon)
211+
203212
#### unimportant
204213

205214
- takeout Strip Library from app folder to make a standalone composer package on standalone repo.

app/Http/Controllers/Admin/AdmissionTest/Controller.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -225,39 +225,6 @@ public function show(AdmissionTest $admissionTest)
225225
);
226226
}
227227

228-
private function updateAddress(Address $address, string $newAddress, int $newDistrictID): Address
229-
{
230-
$addressModel = $address;
231-
if (
232-
$newAddress != $address->value ||
233-
$newDistrictID != $address->district_id
234-
) {
235-
$addressModel = Address::firstWhere([
236-
'district_id' => $newDistrictID,
237-
'value' => $newAddress,
238-
]);
239-
if ($address->admissionTests()->count() == 1) {
240-
if ($addressModel) {
241-
$address->delete();
242-
} else {
243-
$address->update([
244-
'district_id' => $newDistrictID,
245-
'value' => $newAddress,
246-
]);
247-
$addressModel = $address;
248-
}
249-
}
250-
if (! $addressModel) {
251-
$addressModel = Address::create([
252-
'district_id' => $newDistrictID,
253-
'value' => $newAddress,
254-
]);
255-
}
256-
}
257-
258-
return $addressModel;
259-
}
260-
261228
private function updateLocation(Location $location, string $newLocationName): Location
262229
{
263230
$newLocation = $location;
@@ -295,7 +262,7 @@ public function update(TestRequest $request, AdmissionTest $admissionTest)
295262
'location' => $admissionTest->location->name,
296263
'address' => "{$admissionTest->address->value}, {$admissionTest->address->district->name}, {$admissionTest->address->district->area->name}",
297264
];
298-
$address = $this->updateAddress($admissionTest->address, $request->address, $request->district_id);
265+
$address = $admissionTest->address->updateAddress($request->district_id, $request->address);
299266
$location = $this->updateLocation($admissionTest->location, $request->location);
300267
$admissionTest->update([
301268
'type_id' => $request->type_id,

app/Http/Controllers/Admin/UserController.php

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use App\Http\Controllers\Controller;
66
use App\Http\Requests\Admin\User\ResetPasswordRequest;
77
use App\Http\Requests\Admin\User\UpdateRequest;
8+
use App\Models\Address;
9+
use App\Models\Area;
810
use App\Models\Gender;
911
use App\Models\PassportType;
1012
use App\Models\ResetPasswordLog;
@@ -124,16 +126,19 @@ public function index(Request $request)
124126
public function show(User $user)
125127
{
126128
$user->load([
127-
'emails.lastVerification' => function ($query) {
129+
'member', 'emails.lastVerification' => function ($query) {
128130
$query->select(['contact_id', 'verified_at', 'expired_at']);
129131
}, 'mobiles.lastVerification' => function ($query) {
130132
$query->select(['contact_id', 'verified_at', 'expired_at']);
131-
},
133+
}, 'address',
132134
]);
135+
$user->member?->makeHidden(['user_id', 'created_at', 'updated_at']);
136+
$user->member?->append('is_active');
133137
$user->emails->append('is_verified');
134138
$user->emails->makeHidden(['user_id', 'type', 'created_at', 'lastVerification']);
135139
$user->mobiles->append('is_verified');
136140
$user->mobiles->makeHidden(['user_id', 'type', 'created_at', 'lastVerification']);
141+
$user->address?->makeHidden(['id', 'created_at', 'updated_at']);
137142

138143
return Inertia::render('Admin/Users/Show')
139144
->with('user', $user)
@@ -149,6 +154,24 @@ public function show(User $user)
149154
'maxBirthday', now()
150155
->subYears(2)
151156
->format('Y-m-d')
157+
)->with(
158+
'districts', function () {
159+
$areas = Area::with([
160+
'districts' => function ($query) {
161+
$query->orderBy('display_order');
162+
},
163+
])->orderBy('display_order')
164+
->get();
165+
$districts = [];
166+
foreach ($areas as $area) {
167+
$districts[$area->name] = [];
168+
foreach ($area->districts as $district) {
169+
$districts[$area->name][$district->id] = $district->name;
170+
}
171+
}
172+
173+
return $districts;
174+
}
152175
);
153176
}
154177

@@ -166,10 +189,38 @@ public function update(UpdateRequest $request, User $user)
166189
'gender_id' => $gender->id,
167190
'birthday' => $request->birthday,
168191
];
192+
if ($user->address) {
193+
if ($request->district_id) {
194+
$return['address_id'] = $user->address->updateAddress(
195+
$request->district_id,
196+
$request->address
197+
)->id;
198+
} else {
199+
$user->address->delete();
200+
$return['address_id'] = null;
201+
}
202+
} elseif ($request->district_id) {
203+
$return['address_id'] = Address::firstOrCreate([
204+
'district_id' => $request->district_id,
205+
'value' => $request->address,
206+
])->id;
207+
}
169208
$user->update($return);
170-
unset($return['gender_id']);
209+
unset($return['address_id']);
210+
$return['district_id'] = $request->district_id;
211+
$return['address'] = $request->address;
171212
$return['gender'] = $gender->name;
172213
$return['success'] = 'The user data update success!';
214+
if ($user->member) {
215+
$user->member->update([
216+
'prefix_name' => $request->prefix_name,
217+
'nickname' => $request->nickname,
218+
'suffix_name' => $request->suffix_name,
219+
]);
220+
$return['prefix_name'] = $user->member->prefix_name;
221+
$return['nickname'] = $user->member->nickname;
222+
$return['suffix_name'] = $user->member->suffix_name;
223+
}
173224
DB::commit();
174225

175226
return $return;

0 commit comments

Comments
 (0)