diff --git a/package.json b/package.json index 2bbec421..a2c86988 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@o-platform/api-server", - "version": "1.0.5", + "version": "1.0.5-1", "description": "", "main": "dist/index.js", "prepublish": "tsc", diff --git a/src/api-db-migrations/20230907111300__fix_DisableProfileAndShopProc.sql b/src/api-db-migrations/20230907111300__fix_DisableProfileAndShopProc.sql new file mode 100644 index 00000000..d1487661 --- /dev/null +++ b/src/api-db-migrations/20230907111300__fix_DisableProfileAndShopProc.sql @@ -0,0 +1,115 @@ +-- migrate:up +CREATE OR REPLACE PROCEDURE sp_DisableProfileAndShop(address varchar(100)) +LANGUAGE plpgsql +AS $$ +BEGIN + -- Remove Session + DELETE FROM "Session" + WHERE "Session"."profileId" IN( + SELECT + "id" + FROM + "Profile" + WHERE + "circlesAddress" = address); + -- Copy circlesAddress to disabledCirclesAddress + UPDATE + "Profile" + SET + "disabledCirclesAddress" = "circlesAddress" + WHERE + "circlesAddress" = address; + -- Copy circlesSafeOwner to disabledCirclesSafeOwner + UPDATE + "Profile" + SET + "disabledCirclesSafeOwner" = "circlesSafeOwner" + WHERE + "circlesAddress" = address; + -- Set disabled status + UPDATE + "Profile" + SET + "status" = 'disabled' + WHERE + "circlesAddress" = address; + -- Disable the Shop for the Person Entry + UPDATE + "Profile" + SET + "shopEnabled" = FALSE + WHERE + "circlesAddress" = address; + -- Remove circlesSafeOwner + UPDATE + "Profile" + SET + "circlesSafeOwner" = NULL + WHERE + "circlesAddress" = address; + -- Remove CirclesAddress + UPDATE + "Profile" + SET + "circlesAddress" = NULL + WHERE + "circlesAddress" = address; + -- Disable the Shop for the Orga Entry + UPDATE + "Profile" + SET + "shopEnabled" = FALSE + WHERE + id IN( + SELECT + "createdByProfileId" + FROM + "Membership" + WHERE + "memberAddress" = address + AND "isAdmin" = TRUE); + -- copy circlesAddress for the Orga Entry + UPDATE + "Profile" + SET + "disabledCirclesAddress" = "circlesAddress" + WHERE + id IN( + SELECT + "memberAtId" + FROM + "Membership" + WHERE + "memberAddress" = address + AND "isAdmin" = TRUE); + -- Remove circlesAddress for Orga Entry + UPDATE + "Profile" + SET + "circlesAddress" = NULL + WHERE + id IN( + SELECT + "memberAtId" + FROM + "Membership" + WHERE + "memberAddress" = address + AND "isAdmin" = TRUE); + -- set status for Orga Entry to disabled + UPDATE + "Profile" + SET + "status" = 'disabled' + WHERE + id IN( + SELECT + "memberAtId" + FROM + "Membership" + WHERE + "memberAddress" = address + AND "isAdmin" = TRUE); +END +$$ +-- migrate:down