diff --git a/functions/graphql/resolvers.js b/functions/graphql/resolvers.js index ac81fee..aebf446 100644 --- a/functions/graphql/resolvers.js +++ b/functions/graphql/resolvers.js @@ -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) => { diff --git a/functions/graphql/typeDefs.js b/functions/graphql/typeDefs.js index e15ae35..7955391 100644 --- a/functions/graphql/typeDefs.js +++ b/functions/graphql/typeDefs.js @@ -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]! } diff --git a/prisma/migrations/20211128213034_add_created_at_to_project/migration.sql b/prisma/migrations/20211128213034_add_created_at_to_project/migration.sql new file mode 100644 index 0000000..6a2df84 --- /dev/null +++ b/prisma/migrations/20211128213034_add_created_at_to_project/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Project" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ffce0ec..87cd39e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 {