awesome-nest-boilerplate icon indicating copy to clipboard operation
awesome-nest-boilerplate copied to clipboard

Exception Inserting a new Post

Open Be-P opened this issue 2 years ago • 1 comments

Trying to create a new Post through Swagger I get the following exception:

query: START TRANSACTION
query: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, $1) RETURNING "id", "created_at", "updated_at" -- PARAMETERS: ["fecd4a62-56ae-45da-94b4-97004e39abc3"]
query: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"
query failed: INSERT INTO "posts"("id", "created_at", "updated_at", "user_id") VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT) RETURNING "id", "created_at", "updated_at"
error: error: null value in column "user_id" of relation "posts" violates not-null constraint

It seems that the line await this.postTranslationRepository.save(translations); tries to cascade insert the update to the postEntity without setting the userId. the second INSERT in the log gets executed by the postTranslationRepository

Steps to reproduce:

  • Start the boilerplate application
  • Create a User through Swagger
  • Create a Post with 2 translations through Swagger, you'll get the exception in the logs

Be-P avatar Sep 24 '22 16:09 Be-P

the same.

alexdeia avatar Oct 23 '22 12:10 alexdeia

Fixed by @nhutcorp, closes #296

NarHakobyan avatar Nov 09 '22 13:11 NarHakobyan