finki-main
main
|
Last change
on this file since 33517cc was 62b2964, checked in by Klimentina Efremova <klimentina08642@…>, 2 weeks ago |
|
Project Handcraft Marketplace
|
-
Property mode
set to
100644
|
|
File size:
834 bytes
|
| Line | |
|---|
| 1 | CREATE OR REPLACE FUNCTION validate_employee_authorization()
|
|---|
| 2 | RETURNS TRIGGER
|
|---|
| 3 | LANGUAGE plpgsql
|
|---|
| 4 | AS $$
|
|---|
| 5 | DECLARE v_authorisation TEXT;
|
|---|
| 6 | BEGIN
|
|---|
| 7 | -- Get the employee's authorization
|
|---|
| 8 | SELECT authorisation
|
|---|
| 9 | INTO v_authorisation
|
|---|
| 10 | FROM personal
|
|---|
| 11 | WHERE id = NEW.id;
|
|---|
| 12 | -- Check whether the employee exists
|
|---|
| 13 | IF v_authorisation IS NULL THEN
|
|---|
| 14 | RAISE EXCEPTION 'Employee % does not have valid authorization.', NEW.id;
|
|---|
| 15 | END IF;
|
|---|
| 16 | -- Check whether the authorization matches
|
|---|
| 17 | IF NEW.authorisation IS DISTINCT FROM v_authorisation THEN
|
|---|
| 18 | RAISE EXCEPTION 'Employee % is not authorized to make this product change.', NEW.id;
|
|---|
| 19 | END IF;
|
|---|
| 20 | RETURN NEW;
|
|---|
| 21 | END;
|
|---|
| 22 | $$;
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | CREATE TRIGGER trg_validate_employee_authorization
|
|---|
| 26 | BEFORE INSERT OR UPDATE
|
|---|
| 27 | ON makes_change
|
|---|
| 28 | FOR EACH ROW
|
|---|
| 29 | EXECUTE FUNCTION validate_employee_authorization(); |
|---|
Note:
See
TracBrowser
for help on using the repository browser.