Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

feat: add endpoint to sync beta members to guild

yoginth.com ac64480d 8bb2c305

verified
+38
+36
apps/api/src/routes/cron/guild/syncBetaMembersToGuild.ts
··· 1 + import { PERMISSIONS } from "@hey/data/constants"; 2 + import type { Context } from "hono"; 3 + import handleApiError from "@/utils/handleApiError"; 4 + import lensPg from "@/utils/lensPg"; 5 + import syncAddressesToGuild from "@/utils/syncAddressesToGuild"; 6 + 7 + // Sync accounts that have current beta status 8 + const syncBetaMembersToGuild = async (ctx: Context) => { 9 + try { 10 + const accounts = (await lensPg.query( 11 + ` 12 + SELECT DISTINCT ksw.owned_by 13 + FROM account.known_smart_wallet ksw 14 + INNER JOIN "group"."member" AS member ON ksw.address = member.account 15 + WHERE member."group" = $1; 16 + `, 17 + [`\\x${PERMISSIONS.BETA.replace("0x", "").toLowerCase()}`] 18 + )) as Array<{ owned_by: Buffer }>; 19 + 20 + const addresses = accounts.map((account) => 21 + `0x${account.owned_by.toString("hex")}`.toLowerCase() 22 + ); 23 + 24 + const data = await syncAddressesToGuild({ 25 + addresses, 26 + requirementId: 479578, 27 + roleId: 177898 28 + }); 29 + 30 + return ctx.json(data); 31 + } catch (error) { 32 + return handleApiError(ctx, error); 33 + } 34 + }; 35 + 36 + export default syncBetaMembersToGuild;
+2
apps/api/src/routes/cron/index.ts
··· 1 1 import { Hono } from "hono"; 2 2 import secretMiddleware from "@/middlewares/secretMiddleware"; 3 + import syncBetaMembersToGuild from "./guild/syncBetaMembersToGuild"; 3 4 import syncSubscribersToGuild from "./guild/syncSubscribersToGuild"; 4 5 import totalSubscribers from "./guild/totalSubscribers"; 5 6 import removeExpiredSubscribers from "./removeExpiredSubscribers"; 6 7 7 8 const app = new Hono(); 8 9 10 + app.get("/syncBetaMembersToGuild", secretMiddleware, syncBetaMembersToGuild); 9 11 app.get("/syncSubscribersToGuild", secretMiddleware, syncSubscribersToGuild); 10 12 app.get("/totalSubscribers", totalSubscribers); 11 13 app.get(