Skip to content

Commit

Permalink
Merge pull request #213 from UTDallasEPICS/eventContextPageFamily
Browse files Browse the repository at this point in the history
Event context page family
  • Loading branch information
pariahGH authored Dec 1, 2024
2 parents e4cb163 + 4d738b0 commit 9b39790
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 84 deletions.
1 change: 0 additions & 1 deletion components/ImageUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const onFile = async (event: Event) => {
const imageDataObj = {
contentLength: file.size,
contentType: file.type,
file,
pageCuid: props.pageCuid
}
const imageData = await $fetch('/api/image_upload', {
Expand Down
2 changes: 1 addition & 1 deletion pages/Page/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ setImageAutoSlide()
.text-xs.text-gray-600.pt-5 Amount Donated: {{ donationFormat(comment.amount) }}
CVReplySystem(:pageCuid="id" :familyCuid="familyCuid" :replies="replies" @displayReply="displayReply")
.py-4.grid.row-span-3.gap-2(v-if="replies?.length")
.p-2.bg-white.rounded-lg.mb-2.shadow-md.pb-4(v-for="(reply,i) in replies" :key="i")
.p-2.bg-white.rounded-lg.mb-2.shadow-md.pb-4(v-for="(reply,i) in replies.filter(item => !item.suspended)" :key="i")
.flex.justify-between.gap-5.pd-4
.ml-1.text-lg.font-bold {{reply.name}}
.ml-1.text-lg {{dateFormat(reply.date)}}
Expand Down
17 changes: 7 additions & 10 deletions server/api/familiesReports.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { PrismaClient } from "@prisma/client"
import {loginRedirectUrl} from "./auth0"
import type { User } from "@/types.d.ts"
import type { Family, Page } from "@/types.d.ts"
const prisma = new PrismaClient()
import type { User, Family, Page } from "@/types.d.ts"

/*
* /Users
Expand All @@ -16,21 +13,21 @@ export default defineEventHandler(async event => {
const end_date_date = end_date as Date
console.log(typeof end_date)
if(event.context.user?.user_role === "advocate" || event.context.user?.user_role === "admin") {
const [ count, count_date_ranged, all_families, paginated_pages, date_ranged_pages ] = await prisma.$transaction([
prisma.page.count(),
prisma.page.count({ where: {
const [ count, count_date_ranged, all_families, paginated_pages, date_ranged_pages ] = await event.context.client.$transaction([
event.context.client.page.count(),
event.context.client.page.count({ where: {
[date_field as string]: {
gte: new Date(start_date as string),
lte: new Date(end_date as string)
}
}}),
prisma.family.findMany({
event.context.client.family.findMany({
include: {
Pages: true,
FamilyMembers: true,
AdvocateResponsible: true
}}),
prisma.page.findMany({
event.context.client.page.findMany({
include: {
Family: {
include: {
Expand All @@ -41,7 +38,7 @@ export default defineEventHandler(async event => {
skip: (parseInt(dimensions as string) as number) * (page_number as number),
take: (parseInt(dimensions as string) as number)
}),
prisma.page.findMany({
event.context.client.page.findMany({
include: {
Family: {
include: {
Expand Down
4 changes: 1 addition & 3 deletions server/api/family.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 @@ const body = await readBody(event);
phone, address } = body
if(event.context.user?.user_role === "advocate" || event.context.user?.user_role === "admin") {
try {
const queryRes = await event.context.client?.family.create({
const queryRes = await event.context.client.family.create({
data: {
family_name: family_name,
AdvocateResponsible: {
Expand Down
4 changes: 1 addition & 3 deletions server/api/family_donations.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
import {loginRedirectUrl} from "../api/auth0"

/*
Expand All @@ -15,7 +13,7 @@ export default defineEventHandler(async event => {
}
if(event.context.user?.user_role === "admin") {
console.log(family_cuid)
const queryRes = await prisma.pageDonation.findMany({
const queryRes = await event.context.client.pageDonation.findMany({
where: {
familyCuid: family_cuid as string,
success: true
Expand Down
10 changes: 4 additions & 6 deletions server/api/family_pages.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()

/*
* /PageList/cuid
Expand All @@ -15,11 +13,11 @@ export default defineEventHandler(async event => {
}

if(event.context.user?.user_role === "advocate" || event.context.user?.user_role == "admin" || event.context.user?.familyCuid == family_cuid as string) {
const [count, pagesResult, pagesUnpaginated] = await prisma.$transaction([
prisma.page.count( { where: {
const [count, pagesResult, pagesUnpaginated] = await event.context.client.$transaction([
event.context.client.page.count( { where: {
familyCuid : family_cuid as string
}}),
prisma.page.findMany({
event.context.client.page.findMany({
where: {
familyCuid : family_cuid as string
},
Expand All @@ -39,7 +37,7 @@ export default defineEventHandler(async event => {
}
}
}),
prisma.page.findMany({
event.context.client.page.findMany({
where: {
familyCuid : family_cuid as string
},
Expand Down
10 changes: 4 additions & 6 deletions server/api/family_transaction_payout.post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
import {loginRedirectUrl} from "../api/auth0"
import { nanoid } from "nanoid"
import Stripe from "stripe"
Expand All @@ -13,7 +11,7 @@ export default defineEventHandler(async event => {
if(event.context.user?.user_role == "admin") {
// update success flag in transaction

const family = await prisma.family.findFirst({
const family = await event.context.client.family.findFirst({
where: {
cuid: familyCuid
}
Expand Down Expand Up @@ -45,8 +43,8 @@ export default defineEventHandler(async event => {
transfer.balance_transaction as string,
);
console.log(transferBalanceTransaction.fee_details)
await prisma.$transaction([
prisma.donationPayout.create({
await event.context.client.$transaction([
event.context.client.donationPayout.create({
data: {
transaction_id: transfer.id,
amount: body.amount,
Expand All @@ -62,7 +60,7 @@ export default defineEventHandler(async event => {
}
}
}}),
prisma.page.update({
event.context.client.page.update({
where: {
cuid: body.pageCuid as string
},
Expand Down
4 changes: 1 addition & 3 deletions server/api/image.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()

/*
* /EditPage/cuid and /Page/cuid
Expand All @@ -11,7 +9,7 @@ export default defineEventHandler(async event => {
const { pageCuid } = getQuery(event)

// retrives all the images that belong to a family page to a family page
const queryRes = await prisma.image.findMany({
const queryRes = await event.context.client.image.findMany({
where: {
pageCuid : pageCuid as string
}
Expand Down
4 changes: 1 addition & 3 deletions server/api/page.get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()

/*
* /EditPage/cuid or /Page/cuid
Expand All @@ -13,7 +11,7 @@ export default defineEventHandler(async event => {
if( (cuid as string) == "0" || cuid == undefined){
return false
}
const queryRes = await prisma.page.findFirst({
const queryRes = await event.context.client.page.findFirst({
where: {
cuid : cuid as string
},
Expand Down
9 changes: 3 additions & 6 deletions server/api/page.post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { PrismaClient } from "@prisma/client"
import { donationFormat } from "@/utils"
import type { Image } from "@/types.d.ts"
import {loginRedirectUrl} from "../api/auth0"
const prisma = new PrismaClient()

/*
* /EditPage/0
Expand All @@ -18,13 +15,13 @@ export default defineEventHandler(async event => {
data.donation_goal = Math.trunc(data.donation_goal * 100);
data.amount_raised = Math.trunc(data.amount_raised * 100);
try {
const family = await prisma.family.findFirst({
const family = await event.context.client.family.findFirst({
where: { cuid: familyCuid as string }
})

data.status = family?.stripe_account_id ? 'active' : 'no family stripe account'
// Creates a new entry in the database in the page model to a specfic user
const queryRes = await prisma.page.create({
const queryRes = await event.context.client.page.create({
data: {
...data, cuid: undefined,
User: {
Expand All @@ -44,7 +41,7 @@ export default defineEventHandler(async event => {
// Reason: the cuid for the family page is created in the above in the creation query
await Promise.all(
Images.map(async (image: Image) =>
await prisma.image.update({
await event.context.client.image.update({
where: {
cuid: image.cuid
},
Expand Down
13 changes: 7 additions & 6 deletions server/api/page.put.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { PrismaClient } from "@prisma/client"
import {loginRedirectUrl} from "../api/auth0"
import {loginRedirectUrl} from "./auth0"
import type { Image } from "@/types.d.ts"
const prisma = new PrismaClient()

/*
* /EditPage/cuid
Expand All @@ -27,22 +25,25 @@ export default defineEventHandler(async event => {
console.log("amount raised after removing formating ", data.amount_raised)
}
// updates a pre-existing page
const queryRes = await prisma.page.update({
const queryRes = await event.context.client.page.update({
where: {
cuid: data.cuid
},
data: {
...data
}
});

// Initially the images are not linked to a family page, so we add it here
// Reason: the cuid for the family page is created in the above in the creation query
// For page edit, images without a pageCuid are processed
// Changed the logic to work for puts a while ago.
// Image attaches to page on upload for existing page.
// Remove below?
/*await Promise.all(
Images.forEach(async (image: Image) => {
if(image.pageCuid == null) {
await prisma.image.update({
await event.context.prisma.image.update({
where: {
cuid: image.cuid
},
Expand Down
28 changes: 13 additions & 15 deletions server/api/page_list.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()

/*
* /PageList/cuid
Expand All @@ -17,9 +15,9 @@ export default defineEventHandler(async event => {
}

if(event.context.user?.user_role === "admin" && cuid === "") {
const [count, pagesResult] = await prisma.$transaction([
prisma.page.count(),
prisma.page.findMany({
const [count, pagesResult] = await event.context.client.$transaction([
event.context.client.page.count(),
event.context.client.page.findMany({
skip: page_number as number * 12,
take: 12,
include: {
Expand All @@ -31,16 +29,16 @@ export default defineEventHandler(async event => {
}
}})
])
console.log(pagesResult)
//console.log(pagesResult)
return {
Pagination: {
total: count
},
data: pagesResult
};
} else if(event.context.user?.user_role === "advocate" && cuid === "") {
const [count, pagesResult] = await prisma.$transaction([
prisma.page.count({
const [count, pagesResult] = await event.context.client.$transaction([
event.context.client.page.count({
where: {
Family: {
AdvocateResponsible: {
Expand All @@ -49,7 +47,7 @@ export default defineEventHandler(async event => {
},
}
}),
prisma.page.findMany({
event.context.client.page.findMany({
skip: page_number as number * 12,
take: 12,
where: {
Expand All @@ -68,23 +66,23 @@ export default defineEventHandler(async event => {
}
}})
])
console.log("here", pagesResult)
//console.log("here", pagesResult)
return {
Pagination: {
total: count
},
data: pagesResult
};
} else if(event.context.user?.user_role === "admin" && cuid !=="" || event.context.user?.user_role === "advocate" && cuid !=="" || event.context.user?.cuid == cuid || event.context.user?.familyCuid == cuid){
const [count, pagesResult, pagesUnpaginated] = await prisma.$transaction([
prisma.page.count({ where: {
const [count, pagesResult, pagesUnpaginated] = await event.context.client.$transaction([
event.context.client.page.count({ where: {
OR: [ {
userCuid: cuid as string },
{
familyCuid: cuid as string
} ]
}}),
prisma.page.findMany({
event.context.client.page.findMany({
where: {
OR: [ {
userCuid: cuid as string,
Expand All @@ -104,7 +102,7 @@ export default defineEventHandler(async event => {
}
}
}),
prisma.page.findMany({
event.context.client.page.findMany({
where: {
OR: [ {
userCuid: cuid as string },
Expand All @@ -122,7 +120,7 @@ export default defineEventHandler(async event => {
})
])

console.log(pagesResult)
//console.log(pagesResult)
return {
Pagination: {
total: count },
Expand Down
Loading

0 comments on commit 9b39790

Please sign in to comment.