Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
EricSvebakk committed Aug 9, 2024
2 parents 005c877 + 4ec0e6f commit a52c432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions app/pages/main/volunteering/logs/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function LogsPage() {
},
callback: (data) => {
if (data.data.length != 0) {
// console.log(data);
setUsers(
data.data.map((e) => {
return { ...e, name: `${e.firstName} ${e.lastName}`}
Expand Down Expand Up @@ -95,14 +96,17 @@ function LogsPage() {
},
callback: (data) => {
if (data.length == 0) return;
console.log(data.data);

const newLogs = data.data.map((e) => {
const p1 = e.LoggedByUser;
const p2 = e.LoggedForUser;
const p1name = p1 ? `${p1.firstName} ${p1.lastName}` : null
const p2name = p2 ? `${p2.firstName} ${p2.lastName}` : null;
return {
...e,
loggedBy: `${p1.firstName} ${p1.lastName}`,
loggedFor: `${p2.firstName} ${p2.lastName}`,
loggedBy: p1name,
loggedFor: p2name,
vouchers: e.duration * 0.5,
workedAt_num: parseISO(e.workedAt).getTime(),
workedAt: format(
Expand All @@ -115,8 +119,7 @@ function LogsPage() {
const newVouchers = data.data
.filter((e) => {
const person = e.LoggedForUser;
const personId = person.id;
return personId == session.data.user.id;
return person && person.id == session.data.user.id;
})
.reduce((total, e) => {
return (total += e.duration * 0.5);
Expand Down
14 changes: 7 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,20 @@ model ActivateToken {
createdAt DateTime? @default(now())
updatedAt DateTime?
userId String
User User @relation(fields: [userId], references: [id])
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId], map: "ActivateToken_userId_fkey")
}

model VoucherLog {
id String @id @default(cuid())
loggedFor String
loggedFor String?
usedAt DateTime @default(now()) @db.Timestamp(0)
amount Int
description String @db.VarChar(120)
semesterId Int
Semester Semester @relation(fields: [semesterId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "VoucherLog_Semester")
User User @relation(fields: [loggedFor], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "loggedFor0")
User User? @relation(fields: [loggedFor], references: [id], onUpdate: NoAction, map: "loggedFor0")
@@index([id], map: "logID_idx")
@@index([loggedFor], map: "loggedFor_idx")
Expand All @@ -251,16 +251,16 @@ model VoucherLog {
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
model WorkLog {
id String @id @default(cuid())
loggedBy String
loggedFor String
loggedBy String?
loggedFor String?
workedAt DateTime? @db.Timestamp(0)
createdAt DateTime? @default(now()) @db.Timestamp(0)
duration Int?
description String? @db.VarChar(120)
semesterId Int
Semester Semester @relation(fields: [semesterId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "WorkLog_Semester")
LoggedByUser User @relation("WorkLog_loggedByToUser", fields: [loggedBy], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "loggedBy")
LoggedForUser User @relation("WorkLog_loggedForToUser", fields: [loggedFor], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "loggedFor")
LoggedByUser User? @relation("WorkLog_loggedByToUser", fields: [loggedBy], references: [id], onUpdate: NoAction, map: "loggedBy")
LoggedForUser User? @relation("WorkLog_loggedForToUser", fields: [loggedFor], references: [id], onUpdate: NoAction, map: "loggedFor")
@@index([id], map: "logID_idx")
@@index([loggedBy], map: "loggedBy_idx")
Expand Down

0 comments on commit a52c432

Please sign in to comment.