Skip to content
This repository was archived by the owner on Nov 29, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/routes/(app)/app/contacts/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PrismaClient } from '@prisma/client';
import prisma from '$lib/prisma';
import { error } from '@sveltejs/kit';

const prisma = new PrismaClient();

/** @type {import('./$types').PageServerLoad} */
export async function load({ url, locals }) {
try {

const page = parseInt(url.searchParams.get('page') || '1');
const limit = parseInt(url.searchParams.get('limit') || '20');
const search = url.searchParams.get('search') || '';
Expand All @@ -15,7 +15,7 @@ export async function load({ url, locals }) {

// Build where clause
const where = {
organizationId: locals.user?.organizationId, // Assuming user context
organizationId: locals.org.id,
...(search && {
OR: [
{ firstName: { contains: search, mode: 'insensitive' } },
Expand Down Expand Up @@ -66,7 +66,13 @@ export async function load({ url, locals }) {
}),
prisma.contact.count({ where }),
prisma.user.findMany({
where: { organizationId: locals.user?.organizationId },
where: {
organizations: {
some: {
organizationId: locals.org.id
}
}
},
select: {
id: true,
name: true,
Expand Down Expand Up @@ -96,6 +102,7 @@ export async function load({ url, locals }) {
export const actions = {
delete: async ({ request, locals }) => {
try {

const data = await request.formData();
const contactId = data.get('contactId');

Expand All @@ -106,7 +113,7 @@ export const actions = {
await prisma.contact.delete({
where: {
id: contactId,
organizationId: locals.user?.organizationId
organizationId: locals.org.id
}
});

Expand Down