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

feat: display permission level in /query #707

Merged
merged 9 commits into from
Sep 7, 2023
21 changes: 21 additions & 0 deletions src/adapters/supabase/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { Database } from "../types";
import { InsertPermit, Permit } from "../../../helpers";
import { BigNumber, BigNumberish } from "ethers";

interface AccessLevels {
multiplier: boolean;
price: boolean;
priority: boolean;
time: boolean;
}

/**
* @dev Creates a typescript client which will be used to interact with supabase platform
*
Expand Down Expand Up @@ -340,6 +347,20 @@ export const getAccessLevel = async (username: string, repository: string, label
return accessValues;
};

export const getAllAccessLevels = async (username: string, repository: string): Promise<null | AccessLevels> => {
const logger = getLogger();
const { supabase } = getAdapters();

const { data } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository).single();

if (!data) {
logger.info(`Access not found on the database`);
// no access
return null;
}
return { multiplier: data["multiplier_access"], time: data["time_access"], priority: data["priority_access"], price: data["price_access"] };
whilefoo marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Queries the wallet address registered previously
*
Expand Down
14 changes: 12 additions & 2 deletions src/handlers/comment/handlers/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getWalletInfo } from "../../../adapters/supabase";
import { getAllAccessLevels, getWalletInfo } from "../../../adapters/supabase";
import { getBotContext, getLogger } from "../../../bindings";
import { Payload } from "../../../types";

Expand All @@ -22,13 +22,23 @@ export const query = async (body: string) => {
const regex = /^\/query\s+@([\w-]+)\s*$/;
const matches = body.match(regex);
const user = matches?.[1];
const repo = payload.repository;

if (user) {
const data = await getAllAccessLevels(user, repo.full_name);
if (!data) {
return `Error retrieving access for @${user}`;
}
const walletInfo = await getWalletInfo(user, id?.toString());
if (!walletInfo?.address) {
return `Error retrieving multiplier and wallet address for @${user}`;
} else {
return `@${user}'s wallet address is ${walletInfo?.address} and multiplier is ${walletInfo?.multiplier}`;
return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are
| access type | access level |
| multiplier | ${data.multiplier} |
| priority | ${data.priority} |
| time | ${data.time} |
| price | ${data.price} |`;
}
} else {
logger.error("Invalid body for query command");
Expand Down
Loading