From 07336b387abab9f2075a345d6349729c33639e19 Mon Sep 17 00:00:00 2001 From: Nico Schett Date: Sat, 2 Mar 2024 05:45:15 +0100 Subject: [PATCH] feat: update email-related functions and models Refactor Email model with updated create method parameters. Adjust references to Email in index.ts for consistency. Add requireAuth decorator to SMTPConfig model. --- src/index.ts | 6 +++--- src/repository/models/Email.ts | 33 +++++++---------------------- src/repository/models/SMTPConfig.ts | 16 ++++++++------ 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/index.ts b/src/index.ts index c5f65a6..fe6b573 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,9 +26,9 @@ export const service = defineService( templateUpdate: EmailTemplate.update, templateDelete: EmailTemplate.delete, templateTransformer: EmailTemplate.setTransformer, - senderEmailCreate: Email.create, - senderEmailUpdate: Email.update, - senderEmailDelete: Email.delete, + emailCreate: Email.create, + emailUpdate: Email.update, + emailDelete: Email.delete, organizationSetSenderEmail: Organization.setSenderEmail, oauthAppCreate: OAuthApp.create, diff --git a/src/repository/models/Email.ts b/src/repository/models/Email.ts index 4cb69c5..ab27e90 100644 --- a/src/repository/models/Email.ts +++ b/src/repository/models/Email.ts @@ -1,11 +1,10 @@ import { ObjectManager } from "@netsnek/prisma-repository"; import { requireAuth } from "@cronitio/pylon"; -import { $Enums } from "@prisma/client"; -import { client } from "../client"; -import { EmailRepository } from "../.generated"; import service from "../.."; +import { EmailRepository } from "../.generated"; +import { client } from "../client"; export class Email extends EmailRepository { static objects = new ObjectManager<"Email", typeof Email>( @@ -14,31 +13,22 @@ export class Email extends EmailRepository { ); @requireAuth({}) - static async create(data: { - email: string; + static async create( + email: string, smtpConfig?: { host: string; port: number; secure: boolean; username: string; password: string; - }; - oauthConfig?: { - provider: $Enums.OAuthProvider; - accessToken: string; - accessTokenExpiresAt: string; - refreshToken: string; - }; - }) { + } + ) { const ctx = await service.getContext(this); return await ctx.user!.$emailAdd({ - email: data.email, + email: email, smtpConfig: { - create: data.smtpConfig, - }, - oauthConfig: { - create: data.oauthConfig, + create: smtpConfig, }, }); } @@ -55,10 +45,6 @@ export class Email extends EmailRepository { username?: string; password?: string; }; - oauthConfig?: { - provider?: $Enums.OAuthProvider; - accessToken?: string; - }; } ) { const ctx = await service.getContext(this); @@ -69,9 +55,6 @@ export class Email extends EmailRepository { smtpConfig: { update: data.smtpConfig, }, - oauthConfig: { - update: data.oauthConfig, - }, }, { id } ); diff --git a/src/repository/models/SMTPConfig.ts b/src/repository/models/SMTPConfig.ts index 036eca5..38d4bba 100644 --- a/src/repository/models/SMTPConfig.ts +++ b/src/repository/models/SMTPConfig.ts @@ -1,13 +1,15 @@ import { ObjectManager } from "@netsnek/prisma-repository"; -import {client} from "../client"; -import {SMTPConfigRepository} from "../.generated"; - +import { client } from "../client"; +import { SMTPConfigRepository } from "../.generated"; +import { requireAuth } from "@cronitio/pylon"; +import service from "../../"; export class SMTPConfig extends SMTPConfigRepository { - - static objects = new ObjectManager<"SMTPConfig", typeof SMTPConfig>(client.sMTPConfig,SMTPConfig); + static objects = new ObjectManager<"SMTPConfig", typeof SMTPConfig>( + client.sMTPConfig, + SMTPConfig + ); // Custom logic here... - -} \ No newline at end of file +}