Skip to content

Commit

Permalink
feat: add endpoint for discord users linked wallet (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
amateima authored Feb 16, 2023
1 parent f85af65 commit 73935c2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modules/user/entry-points/http/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Controller, Get, Post, Patch, Body, Req, UseGuards } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
import { utils } from "ethers";

import { JwtAuthGuard } from "../../../auth/entry-points/http/jwt.guard";
import { UserService } from "../../services/user.service";
import { UserWalletService } from "../../services/user-wallet.service";
import { UsersWalletsBody } from "./dto";
import { Role, Roles, RolesGuard } from "../../../auth/entry-points/http/roles";

@Controller("users")
export class UserController {
Expand Down Expand Up @@ -66,4 +67,13 @@ export class UserController {

return { walletAddress: updatedUserWallet.walletAddress };
}

@Get("etl/discord-wallets")
@ApiTags("scraper")
@Roles(Role.Admin)
@UseGuards(JwtAuthGuard, RolesGuard)
@ApiBearerAuth()
public async getEtlDiscordUsersWallet() {
return this.userWalletService.getEtlDiscordUsersWallet();
}
}
12 changes: 12 additions & 0 deletions src/modules/user/services/user-wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,16 @@ export class UserWalletService {

return user;
}

public async getEtlDiscordUsersWallet() {
const query = this.userWalletRepository
.createQueryBuilder("uw")
.leftJoinAndSelect("uw.user", "u")
.select(["uw.walletAddress", "u.discordId"]);
const userWallets = await query.getMany();
return userWallets.map((uw) => ({
address: uw.walletAddress,
discordId: uw.user.discordId,
}));
}
}
16 changes: 16 additions & 0 deletions test/user.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ describe("PATCH /users/me/wallets", () => {
});
});

describe("GET users/etl/discord-wallet", () => {
it("should get discord users wallet", async () => {
await userWalletFixture.insertUserWallet({ userId: existingUser.id, walletAddress: "0x" });
const adminJwt = app.get(JwtService).sign({ roles: ["admin"] });
const response = await request(app.getHttpServer())
.get("/users/etl/discord-wallets")
.set("Authorization", `Bearer ${adminJwt}`);
expect(response.status).toBe(200);
expect(response.body.length).toBeGreaterThan(0);
});

afterEach(async () => {
await userWalletFixture.deleteAllUserWallets();
});
});

async function createWalletForExistingUser() {
await request(app.getHttpServer())
.post("/users/me/wallets")
Expand Down

0 comments on commit 73935c2

Please sign in to comment.