Skip to content

Commit

Permalink
Added Youtube Channels and Videos
Browse files Browse the repository at this point in the history
  • Loading branch information
anoopkarnik committed Jul 28, 2024
1 parent 517c721 commit ef7117f
Show file tree
Hide file tree
Showing 25 changed files with 643 additions and 554 deletions.
18 changes: 9 additions & 9 deletions apps/dashboard-app/actions/connections/notion-connections.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use server'

import { createConnection, getConnectionByAccessToken, getConnectionsByUser, getConnectionsByUserAndType } from '@repo/prisma-db/repo/connection'
import { use } from 'react'
interface notionProps {
access_token: string,
notion_connected: any,
Expand All @@ -11,17 +12,16 @@ interface notionProps {
}

export const onNotionConnection = async ({access_token, workspace_id, workspace_icon, workspace_name, userId}: any) => {
if(access_token){
const notion_connected = await getConnectionByAccessToken(access_token)
if (!notion_connected){
const notion = await createConnection({type: 'Notion', userId, accessToken: access_token, workspaceName: workspace_name, workspaceIcon: workspace_icon, workspaceId: workspace_id})
return notion;
}
}
return null
}
if(!access_token) return {error: "Access Token not present in the query"}
const notion_connected = await getConnectionByAccessToken(access_token)
if(notion_connected) return {success: "Notion Connection already exists"}
const notion = await createConnection({type: 'Notion', userId, accessToken: access_token, workspaceName: workspace_name, workspaceIcon: workspace_icon, workspaceId: workspace_id})
if(!notion) return {error: "Notion Connection not created successfully"}
return notion
}

export const getNotionConnection = async (userId: string) => {
if(!userId) return {error: "User Id not present in the query"}
const connection = await getConnectionsByUserAndType(userId, 'Notion')
return connection
}
18 changes: 9 additions & 9 deletions apps/dashboard-app/actions/connections/openai-connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { createConnection, getConnectionByAPIKey, getConnectionsByUserAndType }


export const onOpenAIConnection = async ({apiKey,userId}:any) => {
if(apiKey){
const openai_connected = await getConnectionByAPIKey(apiKey)
if (!openai_connected){
const openai = await createConnection({apiKey,type:'OpenAI', userId})
return openai;
}
}

}
if(!apiKey) return {error: "API Key not present in the query"}
const openai_connected = await getConnectionByAPIKey(apiKey)
if (openai_connected) return {success: "OpenAI Connection already exists"}
const openai = await createConnection({apiKey,type:'OpenAI', userId})
if(!openai) return {error: "OpenAI Connection not created successfully"}
return openai;

}

export const getOpenAIConnection = async (userId: string) => {
if(!userId) return {error: "User Id not present in the query"}
const connection = await getConnectionsByUserAndType(userId, 'OpenAI')
return connection
}
16 changes: 11 additions & 5 deletions apps/dashboard-app/actions/connections/user-connections.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use server'
import { getConnectionByUser} from '@repo/prisma-db/repo/user'

import { updateConnection,deleteConnection, deleteNotionDb } from '@repo/prisma-db/repo/connection'
import { updateConnection,deleteConnection, deleteNotionDb, getConnectionById } from '@repo/prisma-db/repo/connection'
export const getUserInfo = async (userId: string) => {
const user_info:any = await getConnectionByUser(userId);
return user_info;
Expand All @@ -13,9 +13,15 @@ export const updateConnectionById = async (id: string, name: string) => {
}

export const deleteConnectionById = async (id: string) => {
const conn = await deleteConnection(id);
if (conn.type === 'Notion') {
await deleteNotionDb(id);
try{
const conn = await getConnectionById(id);
if (conn?.type === 'Notion') {
await deleteNotionDb(id);
}
await deleteConnection(id);
return {success: "Connection deleted successfully"}
}
catch (error) {
return {error: "Connection not deleted successfully"}
}
return conn;
}
Loading

0 comments on commit ef7117f

Please sign in to comment.