-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Description
A bulk update on the staff_tenant_link table is required per the figma designs. See issue /issues/439 for more details.
Create a staff_tenant resource with the following url /staff-tenants that will accept a PATCH request with following payload structure:
{
staff: [<int:staff_id>, ...],
tenants: [<int:tenant_id>, ...]
}
The patch action will:
- remove all rows in the staff_tenant_link table that exists for each given tenant id if any exist.
- For each tenant id: Create a staff_tenant relationship for each provided staff id.
The above commands should all be performed within a single transaction (ex: call db.commit once) so that if there is an issue on commit it can be easily rolled back, and an appropriate error message sent to the frontend.
Possible validations to include:
- Verify the provided staff id's are indeed Staff members.
- Verify the provided tenant id's exist.
We probably wont be able to use any of the convenient methods defined in the BaseModel. May need to directly communicate with the db.session to add/remove objects from the session and the call db.session.commit() to commit all bulk changes in a single transaction.
See sqlalchemy docs:
- https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session.begin
- https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session.add_all
- https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session.bulk_save_objects
Acceptance Criteria
Please list the requirements the implementation of this feature should meet.
- Create schema and schema test file for validations
- Create integration tests for new route
- Create new route
- Create patch action
- Update README
- Complete request in a single transaction