2022-10-06 08:33:46 +02:00
|
|
|
import { CredentialsType, SmtpCredentialsData } from 'models'
|
|
|
|
import { PrismaClient } from 'db'
|
|
|
|
import { encrypt } from 'utils/api'
|
2022-11-02 19:45:46 +01:00
|
|
|
import { proWorkspaceId } from 'utils/playwright/databaseSetup'
|
2022-10-06 08:33:46 +02:00
|
|
|
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
|
|
|
|
export const createSmtpCredentials = (
|
|
|
|
id: string,
|
|
|
|
smtpData: SmtpCredentialsData
|
|
|
|
) => {
|
|
|
|
const { encryptedData, iv } = encrypt(smtpData)
|
|
|
|
return prisma.credentials.create({
|
|
|
|
data: {
|
|
|
|
id,
|
|
|
|
data: encryptedData,
|
|
|
|
iv,
|
|
|
|
name: smtpData.from.email as string,
|
|
|
|
type: CredentialsType.SMTP,
|
2022-11-02 19:45:46 +01:00
|
|
|
workspaceId: proWorkspaceId,
|
2022-10-06 08:33:46 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|