Dia TM
10/28/2021, 10:12 AMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique @db.VarChar(255)
firstname String @db.VarChar(255)
lastname String @db.VarChar(255)
created_at DateTime @default(now())
updated_at DateTime?
posts Post[]
@@map("users")
}
model Post {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
content String @db.Text
images Image[]
comments Comment[]
created_at DateTime @default(now())
updated_at DateTime?
user User @relation(fields: [userId], references: [id])
userId Int
@@map("posts")
}
model Image {
id Int @id @default(autoincrement())
puth String @db.VarChar(255)
Post Post @relation(fields: [postId], references: [id])
postId Int
@@map("images")
}
model Comment {
id Int @id @default(autoincrement())
comment String @db.Text
post Post @relation(fields: [postId], references: [id])
postId Int
@@map("comments")
}
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma.service';
import { Post, Prisma } from '@prisma/client';
@Injectable()
export class PostsService {
constructor(private prisma: PrismaService) {}
async findAll(): Promise<Post[]> {
return this.prisma.post.findMany({
include: {
user: {
select: {
firstname: true,
lastname: true,
},
},
images: {
select: {
id: true,
puth: true,
},
},
_count: {
select: {
comments: true
}
},
},
});
}
}
Ryan
10/28/2021, 10:14 AMDia TM
10/28/2021, 10:15 AMRyan
10/28/2021, 10:18 AMDia TM
10/28/2021, 10:19 AMmodel Image {
id Int @id @default(autoincrement())
puth String @db.VarChar(255)
Post Post @relation(fields: [postId], references: [id])
postId Int
User User @relation(fields: [userId], references: [id])
userId Int
@@map("images")
}
Dia TM
10/28/2021, 10:20 AMmodel Image {
id Int @id @default(autoincrement())
puth String @db.VarChar(255)
Post Post @relation(fields: [postId], references: [id])
postId Int
@@map("images")
}
Ryan
10/28/2021, 10:21 AMDia TM
10/28/2021, 10:22 AMDia TM
10/28/2021, 10:23 AMRyan
10/28/2021, 10:28 AMDia TM
10/28/2021, 10:29 AMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique @db.VarChar(255)
firstname String @db.VarChar(255)
lastname String @db.VarChar(255)
created_at DateTime @default(now())
updated_at DateTime?
posts Post[]
images Image[]
comments Comment[]
@@map("users")
}
model Post {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
content String @db.Text
images Image[]
comments Comment[]
created_at DateTime @default(now())
updated_at DateTime?
user User @relation(fields: [userId], references: [id])
userId Int
@@map("posts")
}
model Image {
id Int @id @default(autoincrement())
puth String @db.VarChar(255)
post Post @relation(fields: [postId], references: [id])
postId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@map("images")
}
model Comment {
id Int @id @default(autoincrement())
comment String @db.Text
post Post @relation(fields: [postId], references: [id])
postId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@map("comments")
}
Dia TM
10/28/2021, 10:30 AM