generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Szuchet
committed
May 18, 2023
1 parent
aa31602
commit 7bd61e6
Showing
13 changed files
with
820 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import SQL from 'sql-template-strings' | ||
import { AccessNotFoundError, DuplicatedAccessError } from './errors' | ||
import { Permission } from './types' | ||
|
||
export const deleteAccessQuery = (listId: string, permission: Permission, grantee: string, listOwner: string) => SQL` | ||
DELETE FROM favorites.acl USING favorites.lists | ||
WHERE favorites.acl.list_id = favorites.lists.id | ||
AND favorites.acl.list_id = ${listId} | ||
AND favorites.lists.user_address = ${listOwner} | ||
AND favorites.acl.permission = ${permission} | ||
AND favorites.acl.grantee = ${grantee}` | ||
|
||
export function validateAccessExists(listId: string, permission: Permission, grantee: string, result: { rowCount: number }) { | ||
if (!result.rowCount) { | ||
throw new AccessNotFoundError(listId, permission, grantee) | ||
} | ||
} | ||
|
||
export const insertAccessQuery = (listId: string, permission: Permission, grantee: string) => | ||
SQL`INSERT INTO favorites.acl (list_id, permission, grantee) VALUES (${listId}, ${permission}, ${grantee})` | ||
|
||
export function validateDuplicatedAccess(listId: string, permission: Permission, grantee: string, error: unknown) { | ||
if (error && typeof error === 'object' && 'constraint' in error && error.constraint === 'list_id_permissions_grantee_primary_key') { | ||
throw new DuplicatedAccessError(listId, permission, grantee) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ListNotFoundError } from './errors' | ||
|
||
export function validateListExists(id: string, result: { rowCount: number }) { | ||
if (result.rowCount === 0) { | ||
throw new ListNotFoundError(id) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.