feat: initial github integration with importing projects (#421)
* feat: initial github integration with importing projects * fix: remove unused args * chore: remove duplicate col --------- Co-authored-by: Henry <henry_ball@hotmail.co.uk>
This commit is contained in:
@@ -46,6 +46,35 @@ export const getProvidersForUser = async (db: dbClient, userId: string) => {
|
||||
return integration;
|
||||
};
|
||||
|
||||
export const createOrUpdateProvider = async (
|
||||
db: dbClient,
|
||||
data: {
|
||||
userId: string;
|
||||
provider: string;
|
||||
accessToken: string;
|
||||
refreshToken?: string | null;
|
||||
expiresAt: Date;
|
||||
},
|
||||
) => {
|
||||
await db
|
||||
.insert(integrations)
|
||||
.values({
|
||||
provider: data.provider,
|
||||
userId: data.userId,
|
||||
accessToken: data.accessToken,
|
||||
refreshToken: data.refreshToken ?? null,
|
||||
expiresAt: data.expiresAt,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [integrations.userId, integrations.provider],
|
||||
set: {
|
||||
accessToken: data.accessToken,
|
||||
refreshToken: data.refreshToken ?? null,
|
||||
expiresAt: data.expiresAt,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteProviderForUser = async (
|
||||
db: dbClient,
|
||||
userId: string,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { labels } from "./labels";
|
||||
import { lists } from "./lists";
|
||||
import { users } from "./users";
|
||||
|
||||
export const importSourceEnum = pgEnum("source", ["trello"]);
|
||||
export const importSourceEnum = pgEnum("source", ["trello", "github"]);
|
||||
export const importStatusEnum = pgEnum("status", [
|
||||
"started",
|
||||
"success",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { relations } from "drizzle-orm";
|
||||
import {
|
||||
pgTable,
|
||||
primaryKey,
|
||||
text,
|
||||
timestamp,
|
||||
uuid,
|
||||
varchar,
|
||||
@@ -16,7 +17,7 @@ export const integrations = pgTable(
|
||||
userId: uuid("userId")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
accessToken: varchar("accessToken", { length: 255 }).notNull(),
|
||||
accessToken: text("accessToken").notNull(),
|
||||
refreshToken: varchar("refreshToken", { length: 255 }),
|
||||
expiresAt: timestamp("expiresAt").notNull(),
|
||||
createdAt: timestamp("createdAt")
|
||||
|
||||
Reference in New Issue
Block a user