Index: src/app/api/invoices/route.ts
===================================================================
--- src/app/api/invoices/route.ts	(revision dc3406b4adcd188a5b90d471779b2da7665882cc)
+++ src/app/api/invoices/route.ts	(revision 5d6f37a75130aab7d9a67b5b430603eff2c0ca6e)
@@ -1,7 +1,6 @@
 import { NextRequest, NextResponse } from 'next/server';
-import { createInvoiceSchema, invoiceSchema, invoiceTableFiltersSchema } from 'src/schemas';
+import { invoiceSchema, invoiceTableFiltersSchema } from 'mvpmasters-shared';
 import prisma from 'src/lib/prisma';
 import { auth } from 'src/lib/firebase-admin';
-import { InvoiceStatus } from '@prisma/client';
 
 // Helper function to get userId from Authorization header
@@ -24,7 +23,7 @@
   try {
     const userId = await getUserId(request);
-    // if (!userId) {
-    //   return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
-    // }
+    if (!userId) {
+      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
+    }
 
     const searchParams = request.nextUrl.searchParams;
@@ -42,10 +41,9 @@
     const invoices = await prisma.invoice.findMany({
       where: {
-        status: validatedFilters.status
-          ? { equals: validatedFilters.status as InvoiceStatus }
-          : undefined,
-        issueDate: {
-          ...(validatedFilters.startDate && { gte: validatedFilters.startDate }),
-          ...(validatedFilters.endDate && { lte: validatedFilters.endDate }),
+        userId,
+        status: validatedFilters.status ? { equals: validatedFilters.status } : undefined,
+        createDate: {
+          gte: validatedFilters.startDate,
+          lte: validatedFilters.endDate,
         },
         items:
@@ -74,57 +72,17 @@
   try {
     const userId = await getUserId(request);
-    // if (!userId) {
-    //   return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
-    // }
+    if (!userId) {
+      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
+    }
 
     const body = await request.json();
-    const validatedData = createInvoiceSchema.parse(body);
-
-    const tenant = await prisma.tenant.findUnique({
-      where: { id: validatedData.invoiceFrom.id },
-    });
-
-    const toCustomer = await prisma.client.findUnique({
-      where: { id: validatedData.invoiceTo.id },
-    });
-
-    if (!tenant || !toCustomer) {
-      return NextResponse.json({ error: 'Invoice sender or recipient not found' }, { status: 404 });
-    }
-
-    // Update lastInvoiceNumber in tenant
-    const updatedTenant = await prisma.tenant.update({
-      where: { id: tenant.id },
-      data: {
-        lastInvoiceNumber: validatedData.invoiceNumber,
-      },
-    });
+    const validatedData = invoiceSchema.parse(body);
 
     const invoice = await prisma.invoice.create({
       data: {
-        dueDate: validatedData.dueDate,
-        status: validatedData.status,
-        currency: validatedData.currency,
-        quantityType: validatedData.quantityType,
-        subTotal: validatedData.subTotal,
-        issueDate: validatedData.issueDate,
-        month: validatedData.month,
-        discount: validatedData.discount,
-        taxes: validatedData.taxes,
-        totalAmount: validatedData.totalAmount,
-        invoiceNumber: validatedData.invoiceNumber,
-        invoiceFromId: tenant.id,
-        invoiceToId: toCustomer.id,
+        ...validatedData,
+        userId,
         items: {
-          create: validatedData.items.map((item) => ({
-            title: item.title,
-            price: item.price,
-            total: item.total,
-            quantity: item.quantity,
-            description: item.description,
-            service: {
-              connect: { id: item.service.id },
-            },
-          })),
+          create: validatedData.items,
         },
       },
@@ -142,5 +100,4 @@
     return NextResponse.json(invoice, { status: 201 });
   } catch (error) {
-    console.error(error);
     return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
   }
