View UserOperation_contact_setting_change: initial implementation
This commit is contained in:
		
							parent
							
								
									72f2b5aebd
								
							
						
					
					
						commit
						eeb5689212
					
				
					 1 changed files with 63 additions and 0 deletions
				
			
		|  | @ -272,3 +272,66 @@ SELECT CASE | |||
| 
 | ||||
| END; | ||||
| -- -------------- END VIEW: UserOperation_donor_update --------------------- | ||||
| 
 | ||||
| -- -------------- VIEW: UserOperation_contact_setting_change --------------------- | ||||
| 
 | ||||
| DROP VIEW IF EXISTS SettingsLookup_contact_settings; | ||||
| CREATE VIEW SettingsLookup_contact_settings AS | ||||
|    SELECT request_configuration.description as setting_requested, request_type.type as contact_setting | ||||
|    FROM request_configuration, request_type | ||||
|    WHERE request_type.type = "contact-setting" | ||||
|      AND request_configuration.request_type_id = request_type.id | ||||
|      ORDER BY request_type.type, request_configuration.description; | ||||
| 
 | ||||
| DROP VIEW IF EXISTS UserOperation_contact_setting_change; | ||||
| 
 | ||||
| CREATE VIEW UserOperation_contact_setting_change AS | ||||
|    SELECT dd.ledger_entity_id as donor_name, rt.type as contact_setting, rc.description as setting_requested, | ||||
|           rr.date_requested as request_date, rr.notes as note, dd.id as donor_id, rr.id as request_id | ||||
|    FROM donor dd | ||||
|    LEFT JOIN request rr ON dd.id = rr.donor_id AND rr.request_type_id = 12 | ||||
|    LEFT JOIN request_configuration rc ON rc.id = rr.request_configuration_id | ||||
|    LEFT JOIN request_type rt ON rt.id = rr.request_type_id | ||||
|    ORDER BY dd.ledger_entity_id, rr.date_requested; | ||||
| 
 | ||||
| DROP TRIGGER  IF EXISTS contact_setting_config_change_updater; | ||||
| CREATE TRIGGER contact_setting_config_change_updater | ||||
| INSTEAD OF UPDATE OF setting_requested on UserOperation_contact_setting_change | ||||
| BEGIN | ||||
| 
 | ||||
| DELETE FROM _temp_request_configuration_change; | ||||
| 
 | ||||
| INSERT INTO  _temp_request_configuration_change(new_description) VALUES(NEW.setting_requested); | ||||
| 
 | ||||
| update _temp_request_configuration_change set new_request_configuration_id = (select rc.id | ||||
|                             from request_configuration rc, request_type rt | ||||
| 							where rc.description = NEW.setting_requested | ||||
| 							and rt.id = rc.request_type_id | ||||
| 							and rt.type = OLD.contact_setting) | ||||
| 						WHERE new_description = NEW.setting_requested; | ||||
| UPDATE _temp_request_configuration_change set old_request_configuration_id = | ||||
|                             (SELECT rc.id | ||||
|                             FROM request_configuration rc, request_type rt | ||||
| 							where rc.description = OLD.setting_requested | ||||
| 							and rt.id = rc.request_type_id | ||||
| 							and rt.type = OLD.contact_setting) | ||||
| 					WHERE new_description = NEW.setting_requested | ||||
|                                           AND new_request_configuration_id IS NOT NULL; | ||||
| 
 | ||||
| SELECT CASE | ||||
|   WHEN ( (SELECT new_request_configuration_id from _temp_request_configuration_change) IS NULL ) | ||||
|   THEN RAISE(FAIL, "Invalid contact setting; see SettingsLookup_contact_settings view for options!") | ||||
|   END; | ||||
| 
 | ||||
| UPDATE request | ||||
|     set request_configuration_id = | ||||
|             (select new_request_configuration_id from _temp_request_configuration_change), | ||||
|         date_requested = date("now") | ||||
| 	where id = OLD.request_id | ||||
| 	  and request_configuration_id = | ||||
|                 (select old_request_configuration_id from _temp_request_configuration_change); | ||||
| 
 | ||||
| DELETE FROM _temp_request_configuration_change; | ||||
| 
 | ||||
| END; | ||||
| -- -------------- VIEW: UserOperation_contact_setting_change --------------------- | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn