Merge remote-tracking branch 'origin/email-imap'
This commit is contained in:
@@ -20,7 +20,14 @@ export {
|
||||
|
||||
export { readServerSettings, writeServerSettings, readConfigValue, writeConfigValue } from './queries/server-config';
|
||||
|
||||
export { getUserSettings, setUserSettings, getUserState, patchUserState, getDockPaths, setDockPaths } from './queries/user-data';
|
||||
export {
|
||||
getUserSettings,
|
||||
setUserSettings,
|
||||
getUserState,
|
||||
patchUserState,
|
||||
getDockPaths,
|
||||
setDockPaths,
|
||||
} from './queries/user-data';
|
||||
|
||||
export {
|
||||
getServerIntegrations,
|
||||
@@ -35,5 +42,15 @@ export {
|
||||
findUserByIntegrationConfig,
|
||||
} from './queries/integrations';
|
||||
|
||||
export {
|
||||
getEmailAccounts,
|
||||
getEmailAccount,
|
||||
createEmailAccount,
|
||||
deleteEmailAccount,
|
||||
updateEmailAccountStatus,
|
||||
updateEmailAccountSyncMeta,
|
||||
getAllSyncedAccounts,
|
||||
} from './queries/email-accounts';
|
||||
|
||||
export { db } from './db';
|
||||
export * as schema from './schema';
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { db } from '../db';
|
||||
import { emailAccounts } from '../schema';
|
||||
import type { EmailAccountInsert, EmailAccountSelect } from '../types';
|
||||
|
||||
export async function getEmailAccounts(userId: number): Promise<EmailAccountSelect[]> {
|
||||
return db.select().from(emailAccounts).where(eq(emailAccounts.userId, userId));
|
||||
}
|
||||
|
||||
export async function getEmailAccount(id: number): Promise<EmailAccountSelect | undefined> {
|
||||
const [row] = await db.select().from(emailAccounts).where(eq(emailAccounts.id, id));
|
||||
return row;
|
||||
}
|
||||
|
||||
export async function createEmailAccount(params: EmailAccountInsert): Promise<EmailAccountSelect> {
|
||||
const [row] = await db.insert(emailAccounts).values(params).returning();
|
||||
return row!;
|
||||
}
|
||||
|
||||
export async function deleteEmailAccount(id: number, userId: number): Promise<boolean> {
|
||||
const [row] = await db
|
||||
.delete(emailAccounts)
|
||||
.where(and(eq(emailAccounts.id, id), eq(emailAccounts.userId, userId)))
|
||||
.returning({ id: emailAccounts.id });
|
||||
return !!row;
|
||||
}
|
||||
|
||||
export async function updateEmailAccountStatus(id: number, status: string): Promise<void> {
|
||||
await db.update(emailAccounts).set({ status }).where(eq(emailAccounts.id, id));
|
||||
}
|
||||
|
||||
export async function updateEmailAccountSyncMeta(id: number, syncMeta: Record<string, unknown>): Promise<void> {
|
||||
await db.update(emailAccounts).set({ syncMeta }).where(eq(emailAccounts.id, id));
|
||||
}
|
||||
|
||||
export async function getAllSyncedAccounts(): Promise<EmailAccountSelect[]> {
|
||||
return db
|
||||
.select()
|
||||
.from(emailAccounts)
|
||||
.where(and(eq(emailAccounts.status, 'synced'), eq(emailAccounts.enabled, true)));
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { pgTable, serial, integer, text, boolean, timestamp, jsonb, unique } from 'drizzle-orm/pg-core';
|
||||
import { users } from './auth';
|
||||
|
||||
export const emailAccounts = pgTable(
|
||||
'email_accounts',
|
||||
{
|
||||
id: serial('id').primaryKey(),
|
||||
userId: integer('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: 'cascade' }),
|
||||
provider: text('provider').notNull(),
|
||||
email: text('email').notNull(),
|
||||
displayName: text('display_name'),
|
||||
imapHost: text('imap_host').notNull(),
|
||||
imapPort: integer('imap_port').notNull(),
|
||||
imapSecure: boolean('imap_secure').notNull().default(true),
|
||||
authType: text('auth_type').notNull(),
|
||||
credentials: jsonb('credentials').notNull().default({}),
|
||||
enabled: boolean('enabled').notNull().default(true),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
status: text('status').notNull().default('connected'),
|
||||
syncMeta: jsonb('sync_meta').notNull().default({}),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [unique('uq_email_accounts_user_email').on(table.userId, table.email)],
|
||||
);
|
||||
@@ -5,3 +5,4 @@ export * from './dashboards';
|
||||
export * from './agent-items';
|
||||
export * from './operations';
|
||||
export * from './server';
|
||||
export * from './email';
|
||||
|
||||
@@ -100,6 +100,11 @@ export type QueueJobInsert = typeof Schema.queueJobs.$inferInsert;
|
||||
export type TerminalContainerSelect = typeof Schema.terminalContainers.$inferSelect;
|
||||
export type TerminalContainerInsert = typeof Schema.terminalContainers.$inferInsert;
|
||||
|
||||
// ── Email ──
|
||||
|
||||
export type EmailAccountSelect = typeof Schema.emailAccounts.$inferSelect;
|
||||
export type EmailAccountInsert = typeof Schema.emailAccounts.$inferInsert;
|
||||
|
||||
// ── Server ──
|
||||
|
||||
export type ServerConfigSelect = typeof Schema.serverConfig.$inferSelect;
|
||||
|
||||
Reference in New Issue
Block a user