2
0

feat(editor): Add send email integration

This commit is contained in:
Baptiste Arnaud
2022-02-07 18:06:37 +01:00
parent f4336b83cc
commit d6238b3474
48 changed files with 2119 additions and 2606 deletions

View File

@ -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 })
}