1- import { PrismaClient } from '@prisma/client ' ;
1+ import prisma from '$lib/prisma ' ;
22import { error } from '@sveltejs/kit' ;
33
4- const prisma = new PrismaClient ( ) ;
54
65/** @type {import('./$types').PageServerLoad } */
76export async function load ( { url, locals } ) {
87 try {
8+
99 const page = parseInt ( url . searchParams . get ( 'page' ) || '1' ) ;
1010 const limit = parseInt ( url . searchParams . get ( 'limit' ) || '20' ) ;
1111 const search = url . searchParams . get ( 'search' ) || '' ;
@@ -15,7 +15,7 @@ export async function load({ url, locals }) {
1515
1616 // Build where clause
1717 const where = {
18- organizationId : locals . user ?. organizationId , // Assuming user context
18+ organizationId : locals . org . id ,
1919 ...( search && {
2020 OR : [
2121 { firstName : { contains : search , mode : 'insensitive' } } ,
@@ -66,7 +66,13 @@ export async function load({ url, locals }) {
6666 } ) ,
6767 prisma . contact . count ( { where } ) ,
6868 prisma . user . findMany ( {
69- where : { organizationId : locals . user ?. organizationId } ,
69+ where : {
70+ organizations : {
71+ some : {
72+ organizationId : locals . org . id
73+ }
74+ }
75+ } ,
7076 select : {
7177 id : true ,
7278 name : true ,
@@ -96,6 +102,7 @@ export async function load({ url, locals }) {
96102export const actions = {
97103 delete : async ( { request, locals } ) => {
98104 try {
105+
99106 const data = await request . formData ( ) ;
100107 const contactId = data . get ( 'contactId' ) ;
101108
@@ -106,7 +113,7 @@ export const actions = {
106113 await prisma . contact . delete ( {
107114 where : {
108115 id : contactId ,
109- organizationId : locals . user ?. organizationId
116+ organizationId : locals . org . id
110117 }
111118 } ) ;
112119
0 commit comments