feat(editor): ✨ Add send email integration
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import { User } from 'db'
|
||||
import { Prisma, User } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { Credentials } from 'models'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
import { encrypt, methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getSession({ req })
|
||||
@ -16,6 +17,20 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'GET') {
|
||||
const credentials = await prisma.credentials.findMany({
|
||||
where: { ownerId: user.id },
|
||||
select: { name: true, type: true, ownerId: true, id: true },
|
||||
})
|
||||
return res.send({ credentials })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Omit<Credentials, 'ownerId'>
|
||||
const { encryptedData, iv } = encrypt(data.data)
|
||||
const credentials = await prisma.credentials.create({
|
||||
data: {
|
||||
...data,
|
||||
data: encryptedData,
|
||||
iv,
|
||||
ownerId: user.id,
|
||||
} as Prisma.CredentialsUncheckedCreateInput,
|
||||
})
|
||||
return res.send({ credentials })
|
||||
}
|
||||
|
Reference in New Issue
Block a user