Skip to content

Commit

Permalink
feat: update email-related functions and models
Browse files Browse the repository at this point in the history
Refactor Email model with updated create method parameters. Adjust references to Email in index.ts for consistency. Add requireAuth decorator to SMTPConfig model.
  • Loading branch information
schettn committed Mar 2, 2024
1 parent 886e891 commit 07336b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 8 additions & 25 deletions src/repository/models/Email.ts
Original file line number Diff line number Diff line change
@@ -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>(
Expand All @@ -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,
},
});
}
Expand All @@ -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);
Expand All @@ -69,9 +55,6 @@ export class Email extends EmailRepository {
smtpConfig: {
update: data.smtpConfig,
},
oauthConfig: {
update: data.oauthConfig,
},
},
{ id }
);
Expand Down
16 changes: 9 additions & 7 deletions src/repository/models/SMTPConfig.ts
Original file line number Diff line number Diff line change
@@ -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...

}
}

0 comments on commit 07336b3

Please sign in to comment.