voting resolve and prisma seed and cleanup

This commit is contained in:
Michael Bumann
2021-11-28 11:13:14 -06:00
parent 0d0e57baaf
commit b4532cd1bd
7 changed files with 54 additions and 3 deletions

View File

@@ -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,
}
});
},
},
};

View File

@@ -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!
}
`;

View File

@@ -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",

28
prisma/seed.js Normal file
View File

@@ -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()
})