Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Bulk Api user actions #57

Merged

Conversation

zashton
Copy link
Contributor

@zashton zashton commented Oct 31, 2021

Token authenticated endpoints for

  • Bulk Create Users
  • Bulk Update Users
  • Bulk Delete Users
  • Bulk Restore deleted Users

- Bulk Create Users
- Bulk Update Users
- Bulk Delete Users
- Bulk Restore deleted Users
Copy link
Member

@crabsinger crabsinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zashton nice, looks good. asked a few questions and left a few comments.

'users.*.address' => ['required', 'string', 'size:42', 'distinct',
// validate id is unique within circle
Rule::unique('users')->where(function ($query) use ($circle_id) {
return $query->where('circle_id', $circle_id)->whereNull('deleted_at');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Laravel have support for default scopes or some way that we can more easily verify " deleted_at is NULL" all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app/Http/Requests/BulkUserCreateRequest.php Show resolved Hide resolved
Rule::unique('users')->where(function ($query) use ($circle_id) {
return $query->where('circle_id', $circle_id)->whereNull('deleted_at');
})],
'users.*.name' => ['required', 'string', 'max:255'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if easy to do, but ideally I'd think all these validation rules are defined in exactly one spot not across multiple places (https://github.com/coordinape/coordinape-backend/blob/main/app/Http/Requests/UserRequest.php#L40) but may not be easy to do especially as this is wrapped within the "users" context here vs not in the UserRequest file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk maybe i can make a constant for every rule. but might result in a lot of constants created

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, this is fine then.

Rule::unique('users')->where(function ($query) use ($circle_id, $user_id) {
return $query->where('circle_id', $circle_id)->whereNotIn('id', $user_id)->whereNull('deleted_at');
})],
'users.*.name' => ['nullable', 'string', 'max:255'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticing this is nullable during Update, but required during Create. Am I understanding that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to required, but should never trigger since if not provided will be refilled with existing data

$users = $request->get('users');
$address_array = $request->get('address_array');
$circle_id = $request->route('circle_id');
return DB::transaction(function () use ($users, $address_array, $circle_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will the error messages look like returned from the DB transaction blocks? If there's a validation error will we pass that to the FE or will it be hidden behind another transaction error log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation is performed before this code block in RequestForm,
message: e.g {value} is required etc , if you need it changed then provide a list of error messages i'll update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge for now and can update later.

@zashton zashton requested a review from crabsinger November 11, 2021 15:50
$users = $request->get('users');
$address_array = $request->get('address_array');
$circle_id = $request->route('circle_id');
return DB::transaction(function () use ($users, $address_array, $circle_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge for now and can update later.

@levity levity merged commit 9a8ca77 into staging Nov 12, 2021
@levity levity deleted the feature/dev-343-bulk-createupdate-user-list-api-endpoint branch November 12, 2021 18:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants