Add created_at to proejcts and pagination

This commit is contained in:
Michael Bumann
2021-11-28 15:59:12 -06:00
parent 8e4433ee34
commit 9b1b2513f3
4 changed files with 22 additions and 5 deletions

View File

@@ -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) => {

View File

@@ -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]!
}

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Project" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

View File

@@ -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 {