db.ts 586 B

123456789101112131415161718192021222324
  1. /*
  2. /*
  3. * Using prisma-binding from
  4. * https://github.com/prisma/prisma-binding
  5. */
  6. import { Prisma } from 'prisma-binding'
  7. import { typeDefs } from '../database/generated/prisma-client/prisma-schema'
  8. export const db = new Prisma({
  9. typeDefs,
  10. endpoint: process.env.PRISMA_ENDPOINT,
  11. secret: process.env.PRISMA_SECRET,
  12. debug: false
  13. })
  14. export const populateUser = async (req: any, res: any, next: any) => {
  15. if (!req.userId) return next()
  16. const user = await db.query.user(
  17. { where: { id: req.userId } },
  18. '{id, email, name, permissions}'
  19. )
  20. req.user = user
  21. next()
  22. }