Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Use number for ID, not string
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Aug 4, 2020
1 parent 713dc5a commit 3f3ccf1
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 218 deletions.
8 changes: 4 additions & 4 deletions src/_staart/helpers/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ const canApiKeyGroup = (apiKey: apiKeys, action: OrgScopes, target: groups) => {
* Whether a user has authorization to perform an action
*/
export const can = async (
user: string | users | ApiKeyResponse | AccessTokenResponse,
user: number | users | ApiKeyResponse | AccessTokenResponse,
action: OrgScopes | UserScopes | SudoScopes,
targetType: "user" | "group" | "membership" | "sudo",
target?: string | users | groups | memberships
target?: number | users | groups | memberships
) => {
let requestFromType: "users" | "apiKeys" | "accessTokens" = "users";

/**
* First, we figure out what the first parameter is
* If it's a string, it can only be a user ID we'll convert to user
* If it's a number, it can only be a user ID we'll convert to user
*/
if (typeof user === "object") {
if ((user as ApiKeyResponse).sub === Tokens.API_KEY) {
Expand All @@ -193,7 +193,7 @@ export const can = async (
* and `requestFromType` will tell us what type it is
* We find what the correct target is
*/
if (typeof target === "string") {
if (typeof target === "number") {
if (targetType === "membership") {
const membership = await prisma.memberships.findOne({
where: { id: parseInt(target) },
Expand Down
2 changes: 1 addition & 1 deletion src/_staart/helpers/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const setupQueue = async () => {
};

export const queueWebhook = (
groupId: string,
groupId: number,
webhook: Webhooks,
data?: any
) => {
Expand Down
10 changes: 5 additions & 5 deletions src/_staart/rest/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const register = async (
user: usersCreateInput,
locals?: Locals,
email?: string,
groupId?: string,
groupId?: number,
role?: MembershipRole,
emailVerified = false
) => {
Expand All @@ -137,7 +137,7 @@ export const register = async (
try {
domain = email.split("@")[1];
const domainDetails = await getDomainByDomainName(domain);
groupId = domainDetails.groupId.toString();
groupId = domainDetails.groupId;
} catch (error) {}
}
const userId = (
Expand All @@ -148,7 +148,7 @@ export const register = async (
memberships: {
create: {
group: {
connect: { id: parseInt(groupId) },
connect: { id: groupId },
},
role,
},
Expand Down Expand Up @@ -254,8 +254,8 @@ export const updatePassword = async (
};

export const impersonate = async (
tokenUserId: string,
impersonateUserId: string,
tokenUserId: number,
impersonateUserId: number,
locals: Locals
) => {
if (
Expand Down
Loading

0 comments on commit 3f3ccf1

Please sign in to comment.