-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prog: added new endpoints for handling role and permissions
- Loading branch information
1 parent
cc81759
commit b773e22
Showing
6 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
lib/ts/recipe/dashboard/api/userroles/permissions/getPermissionsForRole
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,23 @@ | ||
import { getPermissionsForRole as getPermissions } from "../../../../userroles"; | ||
|
||
import { APIInterface, APIOptions } from "../../../types"; | ||
|
||
import STError from "../../../../../error"; | ||
|
||
const getPermissionsForRole = async ( _: APIInterface, ___: string, options: APIOptions, __: any)=>{ | ||
const role = options.req.getKeyValueFromQuery("role") | ||
|
||
if (role === undefined) { | ||
throw new STError({ | ||
message: "Required parameter 'role' is missing or has an invalid type", | ||
type: STError.BAD_INPUT_ERROR, | ||
}); | ||
} | ||
|
||
const response = await getPermissions(role); | ||
|
||
if(response.status === "OK"){ | ||
response.permissions | ||
} | ||
return [] | ||
} |
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,29 @@ | ||
import { APIInterface, APIOptions } from "../../../types"; | ||
|
||
import { createNewRoleOrAddPermissions } from "../../../../userroles"; | ||
import STError from "../../../../../error"; | ||
|
||
const createRole = async (_: APIInterface, __: string, options: APIOptions, ___: any) => { | ||
const requestBody = await options.req.getJSONBody(); | ||
const permissions = requestBody.permissions; | ||
const role = requestBody.role; | ||
|
||
if (permissions === undefined) { | ||
throw new STError({ | ||
message: "Required parameter 'permissions' is missing or has an invalid type", | ||
type: STError.BAD_INPUT_ERROR, | ||
}); | ||
} | ||
|
||
if (role === undefined) { | ||
throw new STError({ | ||
message: "Required parameter 'role' is missing or has an invalid type", | ||
type: STError.BAD_INPUT_ERROR, | ||
}); | ||
} | ||
|
||
const response = await createNewRoleOrAddPermissions(role, permissions); | ||
return response; | ||
}; | ||
|
||
export default createRole; |
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,21 @@ | ||
import { deleteRole as roleDelete } from "../../../../userroles"; | ||
|
||
import { APIInterface, APIOptions } from "../../../types"; | ||
|
||
import STError from "../../../../../error"; | ||
|
||
const deleteRole = async (_: APIInterface, ___: string, options: APIOptions, __: any) => { | ||
const role = options.req.getKeyValueFromQuery("userId"); | ||
|
||
if (role === undefined) { | ||
throw new STError({ | ||
message: "Required parameter 'role' is missing or has an invalid type", | ||
type: STError.BAD_INPUT_ERROR, | ||
}); | ||
} | ||
|
||
const response = await roleDelete(role); | ||
return response; | ||
}; | ||
|
||
export default deleteRole; |
File renamed without changes.
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