From 17b47ffd917a47d0182768d2aa30ba603567e498 Mon Sep 17 00:00:00 2001 From: radmehr Date: Sun, 27 Sep 2026 16:49:06 +0330 Subject: [PATCH] feat: add records deletion before seeding --- src/database/seeds/seed.ts | 19 +++++++++++++++++++ .../auth/http/verify-otp.post.endpoints.http | 4 ++-- .../http/submissions.get.endpoints.http | 2 +- .../http/submissions.post.endpoints.http | 14 +++++++------- .../tests/http/tests.get.endpoints.http | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/database/seeds/seed.ts b/src/database/seeds/seed.ts index d426809..d48baf9 100644 --- a/src/database/seeds/seed.ts +++ b/src/database/seeds/seed.ts @@ -47,12 +47,31 @@ async function prepareTests() { } } +export async function clearDatabase() { + await dataSource.query(` + DO $$ + DECLARE + r RECORD; + BEGIN + FOR r IN ( + SELECT tablename + FROM pg_tables + WHERE schemaname = 'public' + ) + LOOP + EXECUTE 'TRUNCATE TABLE "' || r.tablename || '" RESTART IDENTITY CASCADE'; + END LOOP; + END $$; + `); +} + async function seed() { try { await dataSource.initialize(); console.log('Database connection initialized.'); + await clearDatabase(); await seedSuperuser(); await prepareTests(); diff --git a/src/modules/auth/http/verify-otp.post.endpoints.http b/src/modules/auth/http/verify-otp.post.endpoints.http index 456f9e6..25b61d3 100644 --- a/src/modules/auth/http/verify-otp.post.endpoints.http +++ b/src/modules/auth/http/verify-otp.post.endpoints.http @@ -2,8 +2,8 @@ POST {{baseUrl}}/auth/verify-otp Content-Type: application/json { - "phone": "09121212123", - "otp": "26989" + "phone": "09333026363", + "otp": "55333" } {{ diff --git a/src/modules/submissions/http/submissions.get.endpoints.http b/src/modules/submissions/http/submissions.get.endpoints.http index c8e41c6..e57375a 100644 --- a/src/modules/submissions/http/submissions.get.endpoints.http +++ b/src/modules/submissions/http/submissions.get.endpoints.http @@ -1,4 +1,4 @@ -GET {{baseUrl}}/submissions/6183e332-d28d-45ba-90a7-942f9d15100f/history +GET {{baseUrl}}/submissions/1/history Authorization: Bearer {{$global.accessToken}} GET {{baseUrl}}/submissions diff --git a/src/modules/submissions/http/submissions.post.endpoints.http b/src/modules/submissions/http/submissions.post.endpoints.http index 80b2cdb..259a095 100644 --- a/src/modules/submissions/http/submissions.post.endpoints.http +++ b/src/modules/submissions/http/submissions.post.endpoints.http @@ -1,17 +1,17 @@ POST {{baseUrl}}/submissions/start Content-Type: application/json -# Authorization: Bearer {{$global.accessToken}} +Authorization: Bearer {{$global.accessToken}} { - "testId": 3 + "testId": 1 } -POST {{baseUrl}}/submissions/6183e332-d28d-45ba-90a7-942f9d15100f/answer +POST {{baseUrl}}/submissions/2/answer Content-Type: application/json -# Authorization: Bearer {{$global.accessToken}} +Authorization: Bearer {{$global.accessToken}} { - "choiceId": 57 - // "numericValue": 10 - // "choiceIds": [45] + "choiceId": 33 + // "numericValue": 1 + // "choiceIds": [] } diff --git a/src/modules/tests/http/tests.get.endpoints.http b/src/modules/tests/http/tests.get.endpoints.http index d9a36b6..ad04733 100644 --- a/src/modules/tests/http/tests.get.endpoints.http +++ b/src/modules/tests/http/tests.get.endpoints.http @@ -1,3 +1,3 @@ GET {{baseUrl}}/tests -GET {{baseUrl}}/tests/4 +GET {{baseUrl}}/tests/1