mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-28 18:54:35 +01:00
Add created_at to proejcts and pagination
This commit is contained in:
@@ -32,11 +32,24 @@ function getPaymetRequest(lightning_address, amount_in_sat) {
|
||||
module.exports = {
|
||||
Query: {
|
||||
allCategories: async (_source, args, context) => {
|
||||
return context.prisma.category.findMany();
|
||||
return context.prisma.category.findMany({
|
||||
orderBy: { title: 'desc'},
|
||||
include: {
|
||||
project: {
|
||||
take: 5,
|
||||
orderBy: { votes_count: "desc" }
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
allProjects: async (_source, args, context) => {
|
||||
const first = args.first || 50;
|
||||
const skip = args.skip || 0;
|
||||
return context.prisma.project.findMany({
|
||||
include: { category: true }
|
||||
orderBy: { created_at: 'desc' },
|
||||
include: { category: true },
|
||||
skip,
|
||||
first,
|
||||
});
|
||||
},
|
||||
getProject: async (_source, args, context) => {
|
||||
|
||||
@@ -15,6 +15,7 @@ module.exports = gql`
|
||||
type Category {
|
||||
id: Int!
|
||||
title: String!
|
||||
project: [Project]
|
||||
}
|
||||
|
||||
type Vote {
|
||||
@@ -27,7 +28,7 @@ module.exports = gql`
|
||||
}
|
||||
|
||||
type Query {
|
||||
allProjects: [Project]!
|
||||
allProjects(skip: Int!, first: Int!): [Project]!
|
||||
getProject(id: Int!): Project
|
||||
allCategories: [Category]!
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Project" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||
@@ -10,7 +10,7 @@ generator client {
|
||||
model Category {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
Project Project[]
|
||||
project Project[]
|
||||
}
|
||||
|
||||
model Project {
|
||||
@@ -24,7 +24,8 @@ model Project {
|
||||
category Category @relation(fields: [category_id], references: [id])
|
||||
category_id Int
|
||||
votes_count Int @default(0)
|
||||
Vote Vote[]
|
||||
vote Vote[]
|
||||
created_at DateTime @default(now())
|
||||
}
|
||||
|
||||
model Vote {
|
||||
|
||||
Reference in New Issue
Block a user