2
0

fix(results): 🐛 Make sure delete all works

This commit is contained in:
Baptiste Arnaud
2022-06-19 11:10:11 +02:00
parent d991dd5467
commit 18c5ea5207
5 changed files with 58 additions and 32 deletions

View File

@@ -47,10 +47,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
} }
if (req.method === 'DELETE') { if (req.method === 'DELETE') {
const typebotId = req.query.typebotId as string const typebotId = req.query.typebotId as string
const ids = req.query.ids as string[] const data = req.body as { ids: string[] }
const ids = data.ids
const results = await prisma.result.deleteMany({ const results = await prisma.result.deleteMany({
where: { where: {
id: { in: ids }, id: ids.length > 0 ? { in: ids } : undefined,
typebot: canWriteTypebot(typebotId, user), typebot: canWriteTypebot(typebotId, user),
}, },
}) })

View File

@@ -81,16 +81,15 @@ export const deleteResults = async (
typebotId: string, typebotId: string,
ids: string[] ids: string[]
) => { ) => {
const params = stringify( const params = stringify({
{ workspaceId,
ids, })
workspaceId,
},
{ indices: false }
)
return sendRequest({ return sendRequest({
url: `/api/typebots/${typebotId}/results?${params}`, url: `/api/typebots/${typebotId}/results?${params}`,
method: 'DELETE', method: 'DELETE',
body: {
ids,
},
}) })
} }

View File

@@ -5,13 +5,12 @@
"main": "./index.ts", "main": "./index.ts",
"types": "./index.ts", "types": "./index.ts",
"devDependencies": { "devDependencies": {
"prisma": "^3.14.0", "prisma": "^3.15.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.4", "typescript": "^4.6.4",
"dotenv-cli": "5.1.0" "dotenv-cli": "5.1.0"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "^3.14.0" "@prisma/client": "^3.15.2"
}, },
"scripts": { "scripts": {
"dx": "dotenv -e ../../apps/builder/.env.local prisma db push && yarn generate:schema && yarn start:sutdio ", "dx": "dotenv -e ../../apps/builder/.env.local prisma db push && yarn generate:schema && yarn start:sutdio ",

View File

@@ -1,5 +1,25 @@
import { CollaborationType, PrismaClient } from 'db'
import path from 'path' import path from 'path'
import { migrateWorkspace } from './workspaceMigration' const prisma = new PrismaClient({
log: [
{
emit: 'event',
level: 'query',
},
{
emit: 'stdout',
level: 'error',
},
{
emit: 'stdout',
level: 'info',
},
{
emit: 'stdout',
level: 'warn',
},
],
})
require('dotenv').config({ require('dotenv').config({
path: path.join( path: path.join(
@@ -9,7 +29,14 @@ require('dotenv').config({
}) })
const main = async () => { const main = async () => {
await migrateWorkspace() prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
const results =
await prisma.$queryRaw`DELETE FROM "public"."Result" WHERE "public"."Result"."typebotId"='ckzqqer3j002509l3np5x3v2y'`
console.log(results)
} }
main().then() main().then()

View File

@@ -3751,22 +3751,22 @@
mem "^8.0.0" mem "^8.0.0"
php-parser "3.1.0-beta.5" php-parser "3.1.0-beta.5"
"@prisma/client@^3.14.0": "@prisma/client@^3.15.2":
version "3.14.0" version "3.15.2"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.14.0.tgz#bb90405c012fcca11f4647d91153ed4c58f3bd48" resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.15.2.tgz#2181398147afc79bfe0d83c03a88dc45b49bd365"
integrity sha512-atb41UpgTR1MCst0VIbiHTMw8lmXnwUvE1KyUCAkq08+wJyjRE78Due+nSf+7uwqQn+fBFYVmoojtinhlLOSaA== integrity sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==
dependencies: dependencies:
"@prisma/engines-version" "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a" "@prisma/engines-version" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
"@prisma/engines-version@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a": "@prisma/engines-version@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e":
version "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a" version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a.tgz#4edae57cf6527f35e22cebe75e49214fc0e99ac9" resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#bf5e2373ca68ce7556b967cb4965a7095e93fe53"
integrity sha512-D+yHzq4a2r2Rrd0ZOW/mTZbgDIkUkD8ofKgusEI1xPiZz60Daks+UM7Me2ty5FzH3p/TgyhBpRrfIHx+ha20RQ== integrity sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==
"@prisma/engines@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a": "@prisma/engines@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e":
version "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a" version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a.tgz#7fa11bc26a51d450185c816cc0ab8cac673fb4bf" resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#f691893df506b93e3cb1ccc15ec6e5ac64e8e570"
integrity sha512-LwZvI3FY6f43xFjQNRuE10JM5R8vJzFTSmbV9X0Wuhv9kscLkjRlZt0BEoiHmO+2HA3B3xxbMfB5du7ZoSFXGg== integrity sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==
"@reach/observe-rect@^1.1.0": "@reach/observe-rect@^1.1.0":
version "1.2.0" version "1.2.0"
@@ -12377,12 +12377,12 @@ prism-react-renderer@^1.3.3:
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.3.tgz#9b5a4211a6756eee3c96fee9a05733abc0b0805c" resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.3.tgz#9b5a4211a6756eee3c96fee9a05733abc0b0805c"
integrity sha512-Viur/7tBTCH2HmYzwCHmt2rEFn+rdIWNIINXyg0StiISbDiIhHKhrFuEK8eMkKgvsIYSjgGqy/hNyucHp6FpoQ== integrity sha512-Viur/7tBTCH2HmYzwCHmt2rEFn+rdIWNIINXyg0StiISbDiIhHKhrFuEK8eMkKgvsIYSjgGqy/hNyucHp6FpoQ==
prisma@^3.14.0: prisma@^3.15.2:
version "3.14.0" version "3.15.2"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.14.0.tgz#dd67ece37d7b5373e9fd9588971de0024b49be81" resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.15.2.tgz#4ebe32fb284da3ac60c49fbc16c75e56ecf32067"
integrity sha512-l9MOgNCn/paDE+i1K2fp9NZ+Du4trzPTJsGkaQHVBufTGqzoYHuNk8JfzXuIn0Gte6/ZjyKj652Jq/Lc1tp2yw== integrity sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==
dependencies: dependencies:
"@prisma/engines" "3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a" "@prisma/engines" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e"
prismjs@^1.28.0: prismjs@^1.28.0:
version "1.28.0" version "1.28.0"