Uncle
Uncle
PPrisma
Created by Uncle on 9/2/2024 in #help-and-questions
Validator questions
Thanks by the way
13 replies
PPrisma
Created by Uncle on 9/2/2024 in #help-and-questions
Validator questions
That worked. Can somebody explain what I was missing / why that worked?
13 replies
PPrisma
Created by Uncle on 9/2/2024 in #help-and-questions
Validator questions
My client instantiation
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
omit:{
user: {
passwordHash: true
}
}
})
export default prisma
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
omit:{
user: {
passwordHash: true
}
}
})
export default prisma
13 replies
PPrisma
Created by Uncle on 9/2/2024 in #help-and-questions
Validator questions
model User {
id String @id @default(cuid()) @map("id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
email String? @unique
givenName String?
familyName String?
organizationName String?
emailVerified Boolean? @map("email_verified")
passwordHash String? @map("password_hash")
employee Boolean @default(false)
admin Boolean @default(false)
customerLeases Lease[] @relation(name: "customer")
employeeLeases Lease[] @relation(name: "employee")
contactInfo ContactInfo[]
paymentMade PaymentRecord[] @relation(name: "customer")
paymentReceived PaymentRecord[] @relation(name: "employee")
customerInvoices Invoice[]
session Session[]
verification Verification[]

@@unique([id, email])
@@unique([email, givenName, familyName])
@@index([id, email])
@@map("users")
}
model User {
id String @id @default(cuid()) @map("id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
email String? @unique
givenName String?
familyName String?
organizationName String?
emailVerified Boolean? @map("email_verified")
passwordHash String? @map("password_hash")
employee Boolean @default(false)
admin Boolean @default(false)
customerLeases Lease[] @relation(name: "customer")
employeeLeases Lease[] @relation(name: "employee")
contactInfo ContactInfo[]
paymentMade PaymentRecord[] @relation(name: "customer")
paymentReceived PaymentRecord[] @relation(name: "employee")
customerInvoices Invoice[]
session Session[]
verification Verification[]

@@unique([id, email])
@@unique([email, givenName, familyName])
@@index([id, email])
@@map("users")
}
13 replies
PPrisma
Created by Uncle on 9/2/2024 in #help-and-questions
Validator questions
my User model:
13 replies
PPrisma
Created by Uncle on 8/17/2024 in #help-and-questions
Module '"prisma/prisma-client"' has no exported member 'PrismaClient'.
It's now fixed its self. Which is kinda worrisome.
4 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
Thanks
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
It seems to have been an issue with awaiting and Array.forEach(). Refactoring to for await fixed it.
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
and the last few querrys: Query: SELECT "public"."users"."id", "public"."users"."email" FROM "public"."users" WHERE ("public"."users"."id") NOT IN (SELECT "t1"."customerId" FROM "public"."Lease" AS "t1" WHERE (1=1 AND "t1"."customerId" IS NOT NULL)) LIMIT $1 OFFSET $2 Params: [1,0] Duration: 1ms Query: SELECT "public"."ContactInfo"."id", "public"."ContactInfo"."email","public"."ContactInfo"."givenName","public"."ContactInfo"."familyName","public"."ContactInfo"."organizationName","public"."ContactInfo"."address1", "public"."ContactInfo"."address2", "public"."ContactInfo"."address3","public"."ContactInfo"."city","public"."ContactInfo"."state","public"."ContactInfo"."zip","public"."ContactInfo"."phoneNum1","public"."ContactInfo"."phoneNum2","public"."ContactInfo"."phoneNum1Validated","public"."ContactInfo"."phoneNum2Validated", "public"."ContactInfo"."softDelete" FROM "public"."ContactInfo" WHERE "public"."ContactInfo"."email" IN ($1) OFFSET $2 Params: ["[email protected]",0] Duration: 1ms Query: SELECT "public"."ContactInfo"."id", "public"."ContactInfo"."email", "public"."ContactInfo"."givenName", "public"."ContactInfo"."familyName", "public"."ContactInfo"."organizationName", "public"."ContactInfo"."address1","public"."ContactInfo"."address2","public"."ContactInfo"."address3","public"."ContactInfo"."city","public"."ContactInfo"."state","public"."ContactInfo"."zip","public"."ContactInfo"."phoneNum1", "public"."ContactInfo"."phoneNum2", "public"."ContactInfo"."phoneNum1Validated", "public"."ContactInfo"."phoneNum2Validated", "public"."ContactInfo"."softDelete" FROM "public"."ContactInfo" WHERE "public"."ContactInfo"."email" IN ($1) OFFSET $2 Params: ["[email protected]",0] Duration: 0ms Query: SELECT "public"."users"."id", "public"."users"."email" FROM "public"."users" WHERE ("public"."users"."id") NOT IN (SELECT "t1"."customerId" FROM "public"."Lease" AS "t1" WHERE (1=1 AND "t1"."customerId" IS NOT NULL)) LIMIT $1 OFFSET $2 Params: [1,0] Duration: 2ms
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
and how that gets call in the main() function pricedUnits.forEach(async (unit) => { const unitLeases: Date[] = Array.from({ length: Math.floor(Math.random() * maxLeases) + 1 }); let leaseStart = new Date(earliestStarting); const today = new Date; let numMonthsLeft = monthDif(leaseStart, today); unitLeases.forEach(async () => { const lengthOfLease = Math.floor(Math.random() * numMonthsLeft) + 1; let leaseEnd = new Date(addMonths(leaseStart, lengthOfLease)); if (leaseEnd > today || monthDif(leaseEnd, today) < 3) { leaseEnd = null; } leases.push(await createLease(unit, leaseStart, leaseEnd)); leaseStart = addMonths(leaseEnd, 1); numMonthsLeft = monthDif(leaseStart, today); }); });
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
the createLease function async function createLease(unit: UnitPricing, leaseStart: Date, leaseEnd: Date) { const employees = await prisma.employee.findMany({ select: { userId: true }, }); const employeeList: string[] = []; employees.forEach((employee) => { employeeList.push(employee.userId); }); const employee = employees[Math.floor(Math.random() * employees.length)]; const customer = await prisma.user.findFirst({ where: { customerLeases: { none: {} } }, select: { id: true, contactInfo: true, }, }); let leaseEnded:Date | null = null; if (leaseEnd) { leaseEnded = new Date(leaseEnd); } const lease = await prisma.lease.create({ data: { customerId: customer!.id, employeeId: employee.userId, contactInfoId: customer!.contactInfo[0].id, unitNum: unit.unitNum, price: unit.price, leaseEffectiveDate: new Date(leaseStart), leaseEnded, }, }); return lease; }
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
model Lease { id String @id @default(cuid()) customer User @relation(fields: [customerId], references: [id], onDelete: NoAction, onUpdate: NoAction) customerId String employee Employee @relation(fields: [employeeId], references: [userId], onDelete: NoAction, onUpdate: NoAction) employeeId String contactInfo ContactInfo @relation(fields: [contactInfoId], references: [id], onUpdate: NoAction, onDelete: NoAction) contactInfoId String unitPrice UnitPricing @relation(fields: [price, unitNum], references: [price, unitNum], onUpdate: NoAction) unitNum String price Int leaseCreatedAt DateTime @default(now()) leaseReturnedAt DateTime? leaseEffectiveDate DateTime leaseEnded DateTime? invoices Invoice[] @@unique([id, unitNum, price]) @@index([id, leaseCreatedAt(sort: Desc)]) }
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
model ContactInfo { id String @id @default(cuid()) user User @relation(fields: [email], references: [email], onUpdate: NoAction) email String givenName String familyName String organizationName String? address1 String address2 String? address3 String? city String state String zip String phoneNum1 String phoneNum2 String? leases Lease[] phoneNum1Validated Boolean @default(false) phoneNum2Validated Boolean? @default(false) softDelete Boolean @default(false) }
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
model User { id String @id @default(cuid()) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") email String @unique emailVerified DateTime? @map("email_verified") customerLeases Lease[] contactInfo ContactInfo[] paymentMade PaymentRecord[] customerInvoices Invoice[] employee Employee? session Session[] account Account[] @@unique([id, email]) @@index([id, email]) @@map("users") }\
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
My schema parts:
17 replies