Skip to content

Commit

Permalink
Merge pull request gitroomhq#407 from gitroomhq/feat/refresh-v
Browse files Browse the repository at this point in the history
Refresh changes
  • Loading branch information
nevo-david authored Oct 29, 2024
2 parents b09cd71 + c3e7377 commit 526b761
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
16 changes: 7 additions & 9 deletions apps/backend/src/api/routes/integrations.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Query,
UseFilters,
Body, Controller, Delete, Get, Param, Post, Query, UseFilters
} from '@nestjs/common';
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
import { ConnectIntegrationDto } from '@gitroom/nestjs-libraries/dtos/integrations/connect.integration.dto';
Expand All @@ -29,6 +22,7 @@ import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/po
import { IntegrationTimeDto } from '@gitroom/nestjs-libraries/dtos/integrations/integration.time.dto';
import { AuthService } from '@gitroom/helpers/auth/auth.service';
import { AuthTokenDetails } from '@gitroom/nestjs-libraries/integrations/social/social.integrations.interface';
import { NotEnoughScopes } from '@gitroom/nestjs-libraries/integrations/social.abstract';

@ApiTags('Integrations')
@Controller('/integrations')
Expand Down Expand Up @@ -354,7 +348,11 @@ export class IntegrationsController {
});

if (!id) {
throw new Error('Invalid api key');
throw new NotEnoughScopes('Invalid API key');
}

if (refresh && id !== refresh) {
throw new NotEnoughScopes('Please refresh the channel that needs to be refreshed');
}

return this._integrationService.createOrUpdateIntegration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default async function Page({
});

if (data.status === HttpStatusCode.NotAcceptable) {
return redirect(`/launches?scope=missing`);
const { msg } = await data.json();
return redirect(`/launches?msg=${msg}`);
}

if (
Expand All @@ -50,8 +51,8 @@ export default async function Page({
const { inBetweenSteps, id } = await data.json();

if (inBetweenSteps && !searchParams.refresh) {
return redirect(`/launches?added=${provider}&continue=${id}`);
return redirect(`/launches?msg=Channel Refreshed&added=${provider}&continue=${id}`);
}

return redirect(`/launches?added=${provider}`);
return redirect(`/launches?added=${provider}&msg=Channel Added`);
}
4 changes: 2 additions & 2 deletions apps/frontend/src/components/launches/launches.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export const LaunchesComponent = () => {
if (typeof window === 'undefined') {
return;
}
if (search.get('scope') === 'missing') {
toast.show('You have to approve all the channel permissions', 'warning');
if (search.get('msg')) {
toast.show(search.get('msg')!, 'warning');
}
if (search.get('added')) {
fireEvents('channel_added');
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/components/launches/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useCallback, useState } from 'react';
import { FC, MouseEventHandler, useCallback, useState } from 'react';
import { useClickOutside } from '@mantine/hooks';
import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
import { deleteDialog } from '@gitroom/react/helpers/delete.dialog';
Expand Down Expand Up @@ -36,7 +36,8 @@ export const Menu: FC<{
setShow(false);
});

const changeShow = useCallback(() => {
const changeShow: MouseEventHandler<HTMLDivElement> = useCallback((e) => {
e.stopPropagation();
setShow(!show);
}, [show]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export class NotEnoughScopesFilter implements ExceptionFilter {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();

response.status(HttpStatusCode.NotAcceptable).json({ invalid: true });
response.status(HttpStatusCode.NotAcceptable).json({ msg: exception.message });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export class BadBody {
) {}
}

export class NotEnoughScopes {}
export class NotEnoughScopes {
constructor(public message = 'Not enough scopes') {}
}

export abstract class SocialAbstract {
async fetch(url: string, options: RequestInit = {}, identifier = '') {
Expand Down

0 comments on commit 526b761

Please sign in to comment.