Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Aug 27, 2023
1 parent 5d55922 commit 0b7e297
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 52 deletions.
7 changes: 3 additions & 4 deletions src/api/auth/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Controller, Get, Post, Res, UseGuards } from '@nestjs/common';
import { Response } from 'express';
import { Controller, Get, Post, UseGuards } from '@nestjs/common';
import { ROUTES } from '../../utils/constants';
import { AuthUser } from '../../utils/decorators';
import { User } from "@prisma/client";
Expand All @@ -16,8 +15,8 @@ export class AuthController {

@Get('redirect')
@UseGuards(DiscordAuthGuard)
redirect(@AuthUser() user: User) {
return user;
redirect() {
return "Authenticated"
}

@Get('check')
Expand Down
1 change: 1 addition & 0 deletions src/api/auth/utils/DiscordStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DiscordStrategy extends PassportStrategy(Strategy) {
userId: profile.id,
username: profile.username,
discriminator: profile.discriminator,
avatar: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`,
accessToken,
refreshToken,
});
Expand Down
15 changes: 3 additions & 12 deletions src/api/discord/controllers/discord.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@ export class DiscordController {
return data.filter((channel) => channel.type === 0);
}

@Get('guilds/:guildId/bans')
async getGuildBans(@Param('guildId') guildId: string) {
const { data } = await this.discordService.getGuildBans(guildId);
return data;
@Get('user/:userId')
getUserDetails(@Param('userId') userId: string) {
return this.discordService.getUserDetails(userId);
}

@Delete('guilds/:guildId/bans/:userId')
async deleteGuildBan(
@Param('guildId') guildId: string,
@Param('userId') userId: string,
) {
const { data } = await this.discordService.deleteGuildBan(guildId, userId);
return data;
}
}
5 changes: 1 addition & 4 deletions src/api/discord/interfaces/discord-http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AxiosResponse } from 'axios';
import {
GuildBanType,
PartialGuild,
PartialGuildChannel,
} from '../../utils/types';
Expand All @@ -11,7 +10,5 @@ export interface IDiscordHttpService {
fetchGuildChannels(
guildId: string,
): Promise<AxiosResponse<PartialGuildChannel[]>>;
fetchGuildBans(guildId: string): Promise<AxiosResponse<GuildBanType[]>>;
deleteGuildBan(guildId: string, userId: string): Promise<AxiosResponse>;

fetchUserDetails(accessToken: string): Promise<AxiosResponse<any>>;
}
5 changes: 2 additions & 3 deletions src/api/discord/interfaces/discord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosResponse } from 'axios';
import { GuildBanType, PartialGuildChannel } from '../../utils/types';
import { PartialGuildChannel } from '../../utils/types';

export interface IDiscordService {
getBotGuilds();
Expand All @@ -8,6 +8,5 @@ export interface IDiscordService {
getGuildChannels(
guildId: string,
): Promise<AxiosResponse<PartialGuildChannel[]>>;
getGuildBans(guildId: string): Promise<AxiosResponse<GuildBanType[]>>;
deleteGuildBan(guildId: string, userId: string): Promise<AxiosResponse>;
getUserDetails(accessToken: string): Promise<AxiosResponse<any>>;
}
23 changes: 0 additions & 23 deletions src/api/discord/services/discord-http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
import { IDiscordHttpService } from '../interfaces/discord-http';
import axios, { AxiosResponse } from 'axios';
import {
GuildBanType,
PartialGuild,
PartialGuildChannel,
} from '../../utils/types';
Expand Down Expand Up @@ -37,28 +36,6 @@ export class DiscordHttpService implements IDiscordHttpService {
},
);
}

fetchGuildBans(guildId: string) {
return axios.get<GuildBanType[]>(
`${DISCORD_BASE_URL}/guilds/${guildId}/bans`,
{
headers: {
Authorization: `Bot ${config.token}`,
},
},
);
}

deleteGuildBan(guildId: string, userId: string): Promise<AxiosResponse> {
return axios.delete(
`${DISCORD_BASE_URL}/guilds/${guildId}/bans/${userId}`,
{
headers: {
Authorization: `Bot ${config.token}`,
},
},
);
}
fetchUserDetails(accessToken: string) {
return axios.get(`${DISCORD_BASE_URL}/users/@me`, {
headers: {
Expand Down
8 changes: 2 additions & 6 deletions src/api/discord/services/discord.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ export class DiscordService implements IDiscordService {
return this.discordHttpService.fetchGuildChannels(guildId);
}

getGuildBans(guildId: string) {
return this.discordHttpService.fetchGuildBans(guildId);
}

deleteGuildBan(guildId: string, userId: string): Promise<AxiosResponse> {
return this.discordHttpService.deleteGuildBan(guildId, userId);
getUserDetails(accessToken: string) {
return this.discordHttpService.fetchUserDetails(accessToken);
}
}
1 change: 1 addition & 0 deletions src/api/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type UserDetails = {
accessToken: string;
refreshToken: string;
username: string;
avatar: string;
discriminator: string;
};

Expand Down

0 comments on commit 0b7e297

Please sign in to comment.