Skip to content

Commit

Permalink
Merge pull request #214 from UTDallasEPICS/UIAndFunctionaltweaks
Browse files Browse the repository at this point in the history
UI and functionaltweaks
  • Loading branch information
pariahGH authored Nov 15, 2024
2 parents 4ce3f34 + d2005dd commit e4cb163
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 33 deletions.
5 changes: 1 addition & 4 deletions server/api/complete_onboarding.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import Stripe from "stripe"
const runtime = useRuntimeConfig()

const stripeSecretKey = runtime.STRIPE_SECRET;
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()

// This api endpoint happens after a family member onboards to Stripe Connect.
// After the family has submitted all of their details to Stripe, their Carson's Village pages will be active.

Expand All @@ -19,7 +16,7 @@ export default defineEventHandler(async event => {
console.log(stripeAccountFull)
// if the user backed out of the onboard, they will be redirected back to the onboard
if(stripeAccountFull.details_submitted) {
const queryRes = await prisma.page.updateMany({
const queryRes = await event.context.client.page.updateMany({
where: {
familyCuid : event.context.user?.familyCuid as string
},
Expand Down
12 changes: 5 additions & 7 deletions server/api/integrations/stripe/complete_session/[id].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import { nanoid } from "nanoid"
const prisma = new PrismaClient()
import Stripe from "stripe"
const runtime = useRuntimeConfig()
//require('dotenv').config()
Expand All @@ -20,7 +18,7 @@ export default defineEventHandler(async event => {
const { subscribing } = getQuery(event)
try {
// get amount donated from transaction
const transaction = await prisma.pageDonation.findFirst({
const transaction = await event.context.client.pageDonation.findFirst({
where: { transaction_id: transaction_id as string},
include: {
Page: {
Expand Down Expand Up @@ -59,7 +57,7 @@ export default defineEventHandler(async event => {
}
// rejects if the transactionid has already been completed
// update success flag in transaction
const checkTransaction = await prisma.pageDonation.findFirst({
const checkTransaction = await event.context.client.pageDonation.findFirst({
where: { transaction_id: transaction_id as string}
})

Expand Down Expand Up @@ -89,12 +87,12 @@ export default defineEventHandler(async event => {
}
//console.log(duration)

await prisma.$transaction([
prisma.pageDonation.update({
await event.context.client.$transaction([
event.context.client.pageDonation.update({
where: { transaction_id: transaction_id as string},
data: { success: true }
}),
prisma.page.update({
event.context.client.page.update({
where: { cuid: transaction?.pageCuid },
data: {
last_donation_date: new Date(),
Expand Down
6 changes: 2 additions & 4 deletions server/api/integrations/stripe/create_session.post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import { nanoid } from "nanoid"
const prisma = new PrismaClient()
// Stripe API tokens
//import { loadStripe } from '@stripe/stripe-js'
import Stripe from "stripe"
Expand All @@ -25,7 +23,7 @@ export default defineEventHandler(async event => {
const userCuid = body._value.userCuid
const familyCuid = body._value.familyCuid
try {
const page = await prisma.page.findFirst({
const page = await event.context.client.page.findFirst({
where: {
cuid: page_cuid
}
Expand Down Expand Up @@ -61,7 +59,7 @@ export default defineEventHandler(async event => {

console.log(body.subscribed)

const queryRes = await prisma.pageDonation.create({
const queryRes = await event.context.client.pageDonation.create({
data: {
transaction_id: transaction_id,
amount: Math.trunc(parseFloat(body._value.amount as unknown as string) * 100) as number,
Expand Down
4 changes: 1 addition & 3 deletions server/api/user.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import {loginRedirectUrl} from "../api/auth0"
const prisma = new PrismaClient()

/*
* /EditUser/cuid
Expand All @@ -15,7 +13,7 @@ export default defineEventHandler(async event => {
}
// retrieves a single user
if(event.context.user?.user_role === "advocate" || event.context.user?.user_role === "admin") {
const queryRes = await prisma.user.findFirst({
const queryRes = await event.context.client.user.findFirst({
where: { cuid: (cuid as string) },
include: {
AdvocateFamily: true
Expand Down
8 changes: 3 additions & 5 deletions server/api/user.post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses"
const prisma = new PrismaClient()
const sesClient = new SESClient({ region: "us-east-1" });
import { loginRedirectUrl } from "../api/auth0"
import emailTemplates from "email-templates"
Expand Down Expand Up @@ -44,7 +42,7 @@ if(event.context.user?.user_role === "advocate" || event.context.user?.user_role
if(body.user_role == "advocate" || (body.user_role == "admin" && event.context.user?.user_role === "admin")) {
delete body.Pages
delete body.AdvocateFamily
const queryRes = await prisma.user.create({
const queryRes = await event.context.client.user.create({
data: {
...body, cuid: undefined, familyCuid: undefined
}
Expand All @@ -54,11 +52,11 @@ if(event.context.user?.user_role === "advocate" || event.context.user?.user_role
} else if(body.user_role == "family") {
delete body.Pages
delete body.AdvocateFamily
const userRes = await prisma.user.create({
const userRes = await event.context.client.user.create({
data: {
...body, cuid: undefined,
}})
const queryRes = await prisma.family.update({
const queryRes = await event.context.client.family.update({
where: { cuid: body.familyCuid },
data: {
updated_at: now,
Expand Down
6 changes: 2 additions & 4 deletions server/api/user.put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import {loginRedirectUrl} from "../api/auth0"
const prisma = new PrismaClient()

/* /EditUser/cuid
* function: PUT
Expand All @@ -18,7 +16,7 @@ if(event.context.user?.user_role == "advocate" || event.context.user?.user_role
// todo: add security so that admins can change any user, advocates can change those that they are responsible for, and users should not be able to change their own email (or stuff breaks obviously).
// todo: change api to use a more standard format. Here we specify the fields of the body instead of using ...body because ...body breaks here
if(body.user_role == 'family' && body.familyCuid !== '') {
const queryRes = await prisma.user.update({
const queryRes = await event.context.client.user.update({
where: {
cuid: body.cuid
},
Expand All @@ -36,7 +34,7 @@ if(event.context.user?.user_role == "advocate" || event.context.user?.user_role
}
});
} else {
const queryRes = await prisma.user.update({
const queryRes = await event.context.client.user.update({
where: {
cuid: body.cuid
},
Expand Down
10 changes: 4 additions & 6 deletions server/api/users.get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { PrismaClient } from "@prisma/client"
import {loginRedirectUrl} from "../api/auth0"
const prisma = new PrismaClient()

/*
* /Users
Expand All @@ -19,9 +17,9 @@ export default defineEventHandler(async event => {
} else {
orderBy = { [(sortedColumn as string) || 'last_name']: order || 'asc' };
}
const [ count, userData, unsortedUsers ] = await prisma.$transaction([
prisma.user.count(),
prisma.user.findMany({
const [ count, userData, unsortedUsers ] = await event.context.client.$transaction([
event.context.client.user.count(),
event.context.client.user.findMany({
orderBy: orderBy,
skip: page_number as number * 12,
take: 12,
Expand All @@ -30,7 +28,7 @@ export default defineEventHandler(async event => {
Family: true
}
}),
prisma.user.findMany({
event.context.client.user.findMany({
skip: page_number as number * 12,
take: 12,
include: {
Expand Down

0 comments on commit e4cb163

Please sign in to comment.