PrismaP
Prisma12mo ago
12 replies
Arima

<fields> is missing.

Created a simple post request that should create a user with a specific name, but I get an error
generator client {
  provider = "prisma-client-js"
}

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


model User {
  id String @unique @default(cuid())
  name String
  @@map("users")
}


app.controllers.ts:
import { Body, Controller, Get, Post } from '@nestjs/common';
import { AppService } from './app.service';

@Controller('users')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello() {
    this.appService.getHello().then(console.log);
  }

  @Post()
  createUser(@Body("name") name: string) {
    this.appService.createUser(name).then(console.log);
  }
}

app.service.ts:
import { Injectable } from '@nestjs/common';
import PrismaService  from './prisma.service';

@Injectable()
export class AppService {
  constructor(
    private prisma: PrismaService
  ) {}
  async getHello() {
    return this.prisma.user.count();
  }

  async createUser(name: string) {
    return this.prisma.user.create({
      data: {
        name: name
      }
    });
  }
}


I don't even know what can cause it, I'm new to this field, but I read a couple of articles in detail on how to get started. But it didn't work. By the way, this request works properly!


PrismaClientValidationError:
Invalid this.prisma.user.create() invocation in
C:\Users\reven\proj\src\app.service.ts:14:29

11 }
12
13 async createUser(name: string) {
→ 14 return this.prisma.user.create({
data: {
+ name: String
}
})

Argument name is missing.
Was this page helpful?