Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Prisma model with tsoa #1481

Closed
ArkasDev opened this issue Sep 9, 2023 · 2 comments
Closed

How to use Prisma model with tsoa #1481

ArkasDev opened this issue Sep 9, 2023 · 2 comments

Comments

@ArkasDev
Copy link

ArkasDev commented Sep 9, 2023

I use Prisma as ORM service. Prisma provides its own schema for the model. Of course I want to use this model in the api interface. Unfortunately this is not recognized as is present just as "string".

Is it possible to use the Prisma model with tsoa?

user-controller.ts

import {User} from "@prisma/client";
import {Body, Controller, Example, Get, Post, Put, Route, SuccessResponse, Tags} from "tsoa";

@Route("user")
@Tags('user')
export class UserController extends Controller {

    @Post()
    @SuccessResponse("201", "Created")
    public async create(@Body() user: User): Promise<User> {
    }
}

prisma.schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {
  id                String           @id @default(auto()) @map("_id") @db.ObjectId
  email             String           @unique @map("_email")
}

Screenshot 2023-09-09 at 12 20 32

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Hello there ArkasDev 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@ArkasDev
Copy link
Author

I solved this problem using @brakebein/prisma-generator-nestjs-dto generator.

generator model {
  provider                        = "prisma-generator-nestjs-dto"
  output                          = "./model"
  outputToNestJsResourceStructure = "false"
  flatResourceStructure           = "false"
  exportRelationModifierClasses   = "true"
  reExport                        = "false"
  createDtoPrefix                 = "Create"
  updateDtoPrefix                 = "Update"
  dtoSuffix                       = "Dto"
  entityPrefix                    = ""
  entitySuffix                    = ""
  classValidation                 = "false"
  fileNamingStyle                 = "camel"
  noDependencies                  = "true"
  outputType                      = "class"
  definiteAssignmentAssertion     = "false"
  requiredResponseApiProperty     = "true"
  prettier                        = "true"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant