diff --git a/functions/graphql/resolvers.js b/functions/graphql/resolvers.js index 0b8c746..8cddfcd 100644 --- a/functions/graphql/resolvers.js +++ b/functions/graphql/resolvers.js @@ -14,7 +14,16 @@ module.exports = { }); }, }, - //Mutation: { - // vote: async (_source, args, context) => {}, - //}, + Mutation: { + vote: async (_source, args, context) => { + const project = await context.prisma.project.findUnique({where: { id: args.project_id }}); + console.log(project) + return context.prisma.vote.create({ + data: { + project_id: project.id, + amount_in_sat: args.amount_in_sat, + } + }); + }, + }, }; diff --git a/functions/graphql/typeDefs.js b/functions/graphql/typeDefs.js index ad3c646..6d23fc6 100644 --- a/functions/graphql/typeDefs.js +++ b/functions/graphql/typeDefs.js @@ -16,9 +16,20 @@ module.exports = gql` title: String! } + type Vote { + id: Int! + project: Project! + amount_in_sat: Int! + payment_request: String! + paid: Boolean! + } + type Query { allProjects: [Project]! getProject(id: Int!): Project allCategories: [Category]! } + type Mutation { + vote (project_id: Int!, amount_in_sat: Int!): Vote! + } `; diff --git a/package.json b/package.json index c0b825d..5caa02b 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,9 @@ "storybook": "start-storybook -p 6006 -s public", "build-storybook": "build-storybook -s public" }, + "prisma": { + "seed": "node prisma/seed.js" + }, "eslintConfig": { "extends": [ "react-app", diff --git a/migrations/20211128165357_init/migration.sql b/prisma/migrations/20211128171210_init/migration.sql similarity index 100% rename from migrations/20211128165357_init/migration.sql rename to prisma/migrations/20211128171210_init/migration.sql diff --git a/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml similarity index 100% rename from migrations/migration_lock.toml rename to prisma/migrations/migration_lock.toml diff --git a/schema.prisma b/prisma/schema.prisma similarity index 100% rename from schema.prisma rename to prisma/schema.prisma diff --git a/prisma/seed.js b/prisma/seed.js new file mode 100644 index 0000000..b8f95e5 --- /dev/null +++ b/prisma/seed.js @@ -0,0 +1,28 @@ +const { PrismaClient } = require('@prisma/client') +const prisma = new PrismaClient() + +async function main() { + const category = await prisma.category.create({ + data: { + title: 'El Salvador', + }, + }); + + const project = await prisma.project.create({ + data: { + title: "Captain Morgan", + description: "HQ on a VULCANO lake", + website: "https://github.com/peakshift", + category_id: category.id, + } + }); +} + +main() + .catch((e) => { + console.error(e) + process.exit(1) + }) + .finally(async () => { + await prisma.$disconnect() + }) \ No newline at end of file