Last active
July 26, 2022 15:55
-
-
Save mpokryva/66a52e8a6a25848d0312fee5af17d10a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** ---- Without RLS ---- ** | |
1. Check if user is a member of the org | |
a. If so, execute the update query | |
b. Else, return a 404 | |
*/ | |
Org update(userId, orgId, updatePayload) { | |
if (dao.isOrgMember(userId, orgId)) { | |
return dao.updateOrg(updatePayload); | |
} else { | |
throw new NotFoundException(); | |
} | |
} | |
/* -- DAO layer -- */ | |
boolean isOrgMember(userId, orgId) { | |
return query("EXISTS(SELECT 1 ...)"); | |
} | |
Org updateOrg(updatePayload) { | |
return query("UPDATE orgs SET ... RETURNING *"); | |
} | |
/* | |
** ----- With RLS ---- ** | |
1. Execute the update query | |
a. If the org was returned from the db, return the org in the response | |
b. Else, return a 404 | |
*/ | |
Org update(userId, orgId, updatePayload) { | |
Optional<Org> maybeOrg = dao.updateOrg(updatePayload); | |
if (maybeOrg.isPresent()) { | |
return maybeOrg.get(); | |
} else { | |
throw new NotFoundException(); | |
} | |
} | |
/* -- DAO layer -- */ | |
Optional<Org> updateOrg(updatePayload) { | |
return query("UPDATE orgs SET ... RETURNING *"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment