feat: implement Trello integration with OAuth and user fields (#48)
* feat: implement Trello integration with OAuth and user fields * feat: migrate Trello integration to new integrations table * refactor: migrate Trello integration to use new integration system * refactor: migrate Trello integration to use new integrations table * fix: add loading check for Trello integration and update VSCode settings * feat: enhance import boards UI with dynamic integration providers and local storage config * feat: add select/unselect all buttons and loading state to board import form * feat: add Trello import env vars on README * docs: update Trello import guide to use OAuth flow instead of API keys * feat: add integrations table for OAuth token management * feat: connect trello from import modal * refactor: consolidate Trello integration endpoints into unified integration router * fix: trello import again * refactor: generalize integration authorization flow and improve error handling * refactor: update Trello API endpoints and tags for better organization * feat: add Integrations tag to OpenAPI specification * refactor: update Trello auth endpoint to use generic integration provider param * refactor: move Trello integration logic from trello.ts to import.ts router * refactor: consolidate Trello integration endpoints and fix API URL * chore: remove debug logs --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk>
This commit is contained in:
59
packages/db/src/repository/integration.repo.ts
Normal file
59
packages/db/src/repository/integration.repo.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { and, eq, gte } from "drizzle-orm";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import { integrations } from "@kan/db/schema";
|
||||
|
||||
export const isProviderAvailableForUser = async (
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
provider: string,
|
||||
) => {
|
||||
const integration = await db.query.integrations.findFirst({
|
||||
where: and(
|
||||
eq(integrations.userId, userId),
|
||||
eq(integrations.provider, provider),
|
||||
gte(integrations.expiresAt, new Date()),
|
||||
),
|
||||
});
|
||||
|
||||
return !!integration;
|
||||
};
|
||||
|
||||
export const getProviderForUser = async (
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
provider: string,
|
||||
) => {
|
||||
const integration = await db.query.integrations.findFirst({
|
||||
where: and(
|
||||
eq(integrations.userId, userId),
|
||||
eq(integrations.provider, provider),
|
||||
gte(integrations.expiresAt, new Date()),
|
||||
),
|
||||
});
|
||||
|
||||
return integration;
|
||||
};
|
||||
|
||||
export const getProvidersForUser = async (db: dbClient, userId: string) => {
|
||||
const integration = await db.query.integrations.findMany({
|
||||
where: and(
|
||||
eq(integrations.userId, userId),
|
||||
gte(integrations.expiresAt, new Date()),
|
||||
),
|
||||
});
|
||||
|
||||
return integration;
|
||||
};
|
||||
|
||||
export const deleteProviderForUser = async (
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
provider: string,
|
||||
) => {
|
||||
await db
|
||||
.delete(integrations)
|
||||
.where(
|
||||
and(eq(integrations.userId, userId), eq(integrations.provider, provider)),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user