Skip to content

Commit

Permalink
Rename profile to account for v3 preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Nov 23, 2024
1 parent 71fa946 commit 399f8cf
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import catchedError from "../catchedError";
import { HEY_USER_AGENT, UNLEASH_API_URL } from "../constants";

/**
* Middleware to validate if the profile is staff
* Middleware to validate if the account is staff
* @param req Incoming request
* @param res Response
* @param next Next function
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/helpers/middlewares/validateIsGardener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import catchedError from "../catchedError";
import { HEY_USER_AGENT, UNLEASH_API_URL } from "../constants";

/**
* Middleware to validate if the profile is gardener
* Middleware to validate if the account is gardener
* @param req Incoming request
* @param res Response
* @param next Next function
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/helpers/middlewares/validateIsStaff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import catchedError from "../catchedError";
import { HEY_USER_AGENT, UNLEASH_API_URL } from "../constants";

/**
* Middleware to validate if the profile is staff
* Middleware to validate if the account is staff
* @param req Incoming request
* @param res Response
* @param next Next function
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/helpers/oembed/meta/getFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const getFrame = (document: Document, url?: string): Frame | null => {
buttons.push({ action, button, postUrl: buttonPostUrl, target });
}

// Frames must be OpenFrame with accepted protocol of Lens (profile authentication) or anonymous (no authentication)
// Frames must be OpenFrame with accepted protocol of Lens (account authentication) or anonymous (no authentication)
if (!lensFramesVersion && !acceptsAnonymous) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const sendSignupNotificationToSlack = async (hash: Address) => {
},
{
short: false,
title: "Profile",
title: "Account",
value: `https://hey.xyz/u/${handle}`
}
],
text: ":tada: A new profile has been signed up to :hey:"
text: ":tada: A new account has been signed up to :hey:"
});

logger.info(
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/account/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const get = [
}))
};

logger.info(`Internal profile fetched for ${id}`);
logger.info(`Internal account fetched for ${id}`);

return res.status(200).json({ result: response, success: true });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/account/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const post = [
}

await reportPost(postId, subreasons, accessToken);
logger.info(`[Lens] Reported profile ${id}`);
logger.info(`[Lens] Reported account ${id}`);

return res.status(200).json({ result: postId, success: true });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/internal/permissions/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const postUpdateTasks = async (
enabled: boolean
) => {
await delRedis(`preference:${accountId}`);
await delRedis(`profile:${accountId}`);
await delRedis(`account:${accountId}`);

await sendSlackMessage({
channel: "#permissions",
Expand Down
14 changes: 7 additions & 7 deletions apps/api/src/routes/lists/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ export const get = [
}

try {
const cacheKey = `list:profiles:${id}`;
const cacheKey = `list:accounts:${id}`;
const cachedData = await getRedis(cacheKey);

if (cachedData) {
logger.info(`(cached) List profiles fetched for ${id}`);
logger.info(`(cached) List accounts fetched for ${id}`);
return res
.status(200)
.json({ result: JSON.parse(cachedData), success: true });
}

const listProfile = await prisma.listProfile.findMany({
const listAccounts = await prisma.listProfile.findMany({
where: { listId: id as string }
});

const accountIds = listProfile.map((item) => item.profileId);
const accountIds = listAccounts.map((account) => account.profileId);
const accountsList = accountIds.map((p) => `'${p}'`).join(",");

const profiles = await lensPg.query(
const accounts = await lensPg.query(
`
SELECT profile_id
FROM profile.record
Expand All @@ -44,9 +44,9 @@ export const get = [
`
);

const result = profiles.map((item) => item.profile_id);
const result = accounts.map((account) => account.profile_id);
await setRedis(cacheKey, JSON.stringify(result));
logger.info(`Lists profiles fetched for ${id}`);
logger.info(`Lists accounts fetched for ${id}`);

return res.status(200).json({ result, success: true });
} catch (error) {
Expand Down
20 changes: 10 additions & 10 deletions apps/api/src/routes/lists/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ export const post = [
try {
const identityToken = req.headers["x-identity-token"] as string;
const payload = parseJwt(identityToken);
const listProfilesCacheKey = `list:profiles:${listId}`;
const listAccountsCacheKey = `list:accounts:${listId}`;
const listCacheKey = `list:${listId}`;

const clearCache = async () => {
await Promise.all([
delRedis(listProfilesCacheKey),
delRedis(listAccountsCacheKey),
delRedis(listCacheKey)
]);
};

const profile = await lensPg.query(
const account = await lensPg.query(
`
SELECT EXISTS (
SELECT 1 FROM profile.record
Expand All @@ -64,13 +64,13 @@ export const post = [
[accountId]
);

const hasProfile = profile[0]?.result;
const hasAccount = account[0]?.result;

if (!hasProfile) {
if (!hasAccount) {
return notFound(res);
}

// Check if the list exists and belongs to the authenticated user and the number of profiles in the list
// Check if the list exists and belongs to the authenticated user and the number of accounts in the list
const [list, count] = await prisma.$transaction([
prisma.list.findUnique({
where: { id: listId, createdBy: payload.id }
Expand All @@ -93,20 +93,20 @@ export const post = [
}

if (add) {
const listProfile = await prisma.listProfile.create({
const listAccount = await prisma.listProfile.create({
data: { listId, profileId: accountId }
});
await clearCache();
logger.info(`Added profile ${accountId} to list ${listId}`);
logger.info(`Added account ${accountId} to list ${listId}`);

return res.status(200).json({ result: listProfile, success: true });
return res.status(200).json({ result: listAccount, success: true });
}

await prisma.listProfile.delete({
where: { profileId_listId: { profileId: accountId, listId } }
});
await clearCache();
logger.info(`Removed profile ${accountId} from list ${listId}`);
logger.info(`Removed account ${accountId} from list ${listId}`);

return res.status(200).json({ success: true });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/lists/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const get = [

return {
...rest,
totalProfiles: _count.profiles,
totalAccounts: _count.profiles,
totalPins: _count.pinnedList,
pinned: pinnedList.length > 0,
isAdded: profiles.length > 0
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/lists/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const post = [
const identityToken = req.headers["x-identity-token"] as string;
const payload = parseJwt(identityToken);
const listCacheKey = `list:${id}`;
const listProfilesCacheKey = `list:profiles:${id}`;
const listAccountsCacheKey = `list:accounts:${id}`;

const clearCache = async () => {
await Promise.all([
delRedis(listCacheKey),
delRedis(listProfilesCacheKey)
delRedis(listAccountsCacheKey)
]);
};

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/lists/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const get = [
const result = {
...rest,
profiles: profiles.map((account) => account.profileId),
totalProfiles: _count.profiles,
totalAccounts: _count.profiles,
totalPins: _count.pinnedList,
pinned: pinnedList.length > 0
};
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/lists/pinned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const get = [

return {
...rest,
totalProfiles: _count.profiles,
totalAccounts: _count.profiles,
totalPins: _count.pinnedList,
pinned: pinnedList.length > 0
};
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/profile/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const get = [
}

try {
const cacheKey = `profile:${id}`;
const cacheKey = `account:${id}`;
const cachedData = await getRedis(cacheKey);

if (cachedData) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/profile/status/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const post = [
where: { id: payload.id }
});

await delRedis(`profile:${payload.id}`);
await delRedis(`account:${payload.id}`);
logger.info(`Cleared profile status for ${payload.id}`);

return res.status(200).json({ result: profileStatus, success: true });
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/profile/status/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const post = [
where: { id: payload.id }
});

await delRedis(`profile:${payload.id}`);
logger.info(`Updated profile status for ${payload.id}`);
await delRedis(`account:${payload.id}`);
logger.info(`Updated account status for ${payload.id}`);

return res.status(200).json({ result: profileStatus, success: true });
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/lists/all.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("GET /lists/all", () => {
expect(data.result).toBeDefined();
expect(data.result.length).toBeGreaterThan(0);
expect(data.result[0].totalPins).toStrictEqual(expect.any(Number));
expect(data.result[0].totalProfiles).toStrictEqual(expect.any(Number));
expect(data.result[0].totalAccounts).toStrictEqual(expect.any(Number));
});

test("should return 200 with isAdded as true if the user is added to the list", async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/lists/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ describe("GET /lists/get", () => {
expect(data.result.description).toBe(newList.description);
expect(data.result.avatar).toBe(newList.avatar);
expect(data.result.totalPins).toStrictEqual(expect.any(Number));
expect(data.result.totalProfiles).toStrictEqual(expect.any(Number));
expect(data.result.totalAccounts).toStrictEqual(expect.any(Number));
});
});
2 changes: 1 addition & 1 deletion apps/api/tests/lists/pinned.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("GET /lists/pinned", () => {
expect(data.result).toBeDefined();
expect(data.result.length).toBeGreaterThan(0);
expect(data.result[0].totalPins).toStrictEqual(expect.any(Number));
expect(data.result[0].totalProfiles).toStrictEqual(expect.any(Number));
expect(data.result[0].totalAccounts).toStrictEqual(expect.any(Number));
expect(data.result[0].pinned).toBe(true);
});

Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/profile/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("GET /profile/get", () => {
});

test("should return 200 with status and theme", async () => {
await delRedis(`profile:${TEST_LENS_ID}`);
await delRedis(`account:${TEST_LENS_ID}`);
const { data, status } = await axios.get(`${TEST_URL}/profile/get`, {
params: { id: TEST_LENS_ID }
});
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/List/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ const Details: FC<DetailsProps> = ({ list }) => {
className="text-left outline-offset-4"
href={`/lists/${list.id}/accounts`}
>
<H4>{humanize(list.totalProfiles)}</H4>
<H4>{humanize(list.totalAccounts)}</H4>
<div className="ld-text-gray-500">
{plur("Profile", list.totalProfiles)}
{plur("Profile", list.totalAccounts)}
</div>
</Link>
<div className="text-left outline-offset-4">
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Shared/Modal/AddToList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const AddToList: FC = () => {
? {
...list,
isAdded: add,
totalProfiles: add
? list.totalProfiles + 1
: list.totalProfiles - 1
totalAccounts: add
? list.totalAccounts + 1
: list.totalAccounts - 1
}
: list
)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Shared/SingleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SingleList: FC<SingleListProps> = ({ list, linkToList = true }) => {
<div className="flex flex-col">
<div className="font-bold">{list.name}</div>
<div className="text-gray-500 text-xs">
{list.totalProfiles} {plur("Profile", list.totalProfiles)}
{list.totalAccounts} {plur("Profile", list.totalAccounts)}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/types/hey.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type List = {
name: string;
description: string | null;
avatar: string | null;
totalProfiles: number;
totalAccounts: number;
totalPins: number;
createdBy: string;
isAdded?: boolean;
Expand Down

1 comment on commit 399f8cf

@vercel
Copy link

@vercel vercel bot commented on 399f8cf Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./

web-git-main-heyxyz.vercel.app
hey.xyz
heyxyz.vercel.app
web-heyxyz.vercel.app

Please sign in to comment.