PrismaClientValidationError: Invalid ` .create()` invocation in

Hi There i'm new in this discord server, I wanna to ask about my project error, here's the details: schema.prisma
generator client {
provider = "prisma-client"
output = "../src/generated/client"
runtime = "bun"
}

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

model Event {
id String @id @default(uuid())
created_at DateTime @default(now())
updated_at DateTime @updatedAt
title String @unique
start_date DateTime
end_date DateTime
location String
description String?
presence Presence[]

@@index([title])
}
...
generator client {
provider = "prisma-client"
output = "../src/generated/client"
runtime = "bun"
}

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

model Event {
id String @id @default(uuid())
created_at DateTime @default(now())
updated_at DateTime @updatedAt
title String @unique
start_date DateTime
end_date DateTime
location String
description String?
presence Presence[]

@@index([title])
}
...
event.service.ts
async createEvent(data: Prisma.EventCreateInput) {
log(`data: ${data}`);
return await this.prisma.event
.create({
data,
})
.then(() => this.logger.log(`Create Event: ${data.title}`));
}
async createEvent(data: Prisma.EventCreateInput) {
log(`data: ${data}`);
return await this.prisma.event
.create({
data,
})
.then(() => this.logger.log(`Create Event: ${data.title}`));
}
event.controller.ts
async createEvent(@Body() input: EventDto) {
const data = await this.eventService.createEvent(input);
return formatResponse(
true,
`Berhasil menambahkan data Event: ${input.title}`,
data,
null,
);
}
async createEvent(@Body() input: EventDto) {
const data = await this.eventService.createEvent(input);
return formatResponse(
true,
`Berhasil menambahkan data Event: ${input.title}`,
data,
null,
);
}
5 Replies
Prisma AI Help
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into #ask-ai if you get antsy for a second opinion!
Slaughtered
SlaughteredOP2w ago
event.dto.ts
export class EventDto {
@IsString()
@IsNotEmpty()
@ApiProperty({
description: "The title of the event",
example: "Event Title",
})
title: string;

@IsDate()
@ApiProperty({
description: "The start date of the event",
example: "2021-01-01T00:00:00.000Z",
required: false,
})
start_date: Date;

@IsDate()
@ApiProperty({
description: "The end date of the event",
example: "2021-01-01T00:00:00.000Z",
required: false,
})
end_date: Date;

@IsString()
@ApiProperty({
description: "The description of the event",
example: "Event Description",
required: false,
})
location: string;

@IsString()
@ApiProperty({
description: "The description of the event",
example: "Event Description",
required: false,
})
description: string | null;
}
export class EventDto {
@IsString()
@IsNotEmpty()
@ApiProperty({
description: "The title of the event",
example: "Event Title",
})
title: string;

@IsDate()
@ApiProperty({
description: "The start date of the event",
example: "2021-01-01T00:00:00.000Z",
required: false,
})
start_date: Date;

@IsDate()
@ApiProperty({
description: "The end date of the event",
example: "2021-01-01T00:00:00.000Z",
required: false,
})
end_date: Date;

@IsString()
@ApiProperty({
description: "The description of the event",
example: "Event Description",
required: false,
})
location: string;

@IsString()
@ApiProperty({
description: "The description of the event",
example: "Event Description",
required: false,
})
description: string | null;
}
I have done running prisma generate and still got an error, what should i do now? thanks and yeah when i print an input from event.service.ts it says like this:
data: function anonymous(
) {

}
data: function anonymous(
) {

}
Nurul
Nurul2w ago
Hey! Can you share the error message that you are getting? Which parameters are missing? Can you share what you are passing as data in prisma.event.create call?
Slaughtered
SlaughteredOP2w ago
sure i'll provide you wait there Error: Invalid value for argument data: We could not serialize [object Function] value. Serialize the object to JSON or implement a ".toJSON()" method on it. data:
const data: {
title: string;
start_date: Date;
end_date: Date;
location: string;
description: string | null;
}
const data: {
title: string;
start_date: Date;
end_date: Date;
location: string;
description: string | null;
}
oh when i was using a prisma generated type (EventCreateInput in controller and service) it work but what when wrong with my dto? here's my main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const port = process.env.PORT ?? 3000;
const config = new DocumentBuilder()
.setTitle("Website Rajawali")
.setDescription("API Documentation")
.setVersion("0.1")
.addServer(`http://localhost:${port}`, "Local Environment")
.addBearerAuth()
.build();
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup("api", app, documentFactory);

app.setGlobalPrefix("api");
app.enableCors();
app.useGlobalFilters(new HttpExceptionFilter());
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
await app.listen(port);
}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const port = process.env.PORT ?? 3000;
const config = new DocumentBuilder()
.setTitle("Website Rajawali")
.setDescription("API Documentation")
.setVersion("0.1")
.addServer(`http://localhost:${port}`, "Local Environment")
.addBearerAuth()
.build();
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup("api", app, documentFactory);

app.setGlobalPrefix("api");
app.enableCors();
app.useGlobalFilters(new HttpExceptionFilter());
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
await app.listen(port);
}
oh lol it because i just using import type at dto sorry, and thanks for the response
Nurul
Nurul7d ago
Ah. no worries! Glad to hear that you were able to resolve it

Did you find this page helpful?