Changeset 87c9f1e


Ignore:
Timestamp:
02/27/25 00:42:38 (5 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
32e9876
Parents:
3c5302a
Message:

update the seed script. update the prisma schema, use mapping

Files:
6 added
25 edited
8 moved

Legend:

Unmodified
Added
Removed
  • prisma/schema.prisma

    r3c5302a r87c9f1e  
    99
    1010model Client {
    11   id              String        @id @default(uuid())
    12   tenantId        String       // Tenant identifier
    13   name            String
    14   email           String        @unique
    15   address         Json
    16   logoUrl         String?
    17   phoneNumber     String?
    18   vatNumber       String?
    19   companyNumber   String?
    20   representative  String
    21   status          CustomerStatus @default(active)
     11  id             String       @id @default(uuid())
     12  tenantId       String       @map("tenant_id")
     13  name           String
     14  email          String       @unique
     15  address        Json
     16  logoUrl        String?      @map("logo_url")
     17  phoneNumber    String?      @map("phone_number")
     18  vatNumber      String?      @map("vat_number")
     19  companyNumber  String?      @map("company_number")
     20  representative String
     21  status         ClientStatus @default(active)
     22  createdAt      DateTime     @default(now()) @map("created_at")
     23  updatedAt      DateTime     @updatedAt @map("updated_at")
    2224
    23   tenant          Tenant        @relation(fields: [tenantId], references: [id], onDelete: Cascade)
     25  tenant           Tenant    @relation(fields: [tenantId], references: [id], onDelete: Cascade)
    2426  invoicesReceived Invoice[] @relation("InvoiceTo")
    2527}
    2628
    2729model Service {
    28   id          String @id @default(uuid())
    29   name        String
    30   sprint      Float
    31   hour        Float
    32   month       Float
    33   tenantId    String
    34   tenant      Tenant  @relation(fields: [tenantId], references: [id], onDelete: Cascade)
     30  id       String @id @default(uuid())
     31  name     String
     32  sprint   Float
     33  hour     Float
     34  month    Float
     35  tenantId String @map("tenant_id")
     36  tenant   Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
    3537
    3638  lineItems LineItem[]
     
    3840
    3941model Invoice {
    40   id            String         @id @default(uuid())
    41   sent          Int?           // Number of times sent
    42   dueDate       DateTime
     42  id            String        @id @default(uuid())
     43  sent          Int?
     44  dueDate       DateTime      @map("due_date")
    4345  status        InvoiceStatus
    4446  currency      Currency
    45   quantityType  QuantityType
    46   subTotal      Float
    47   createDate    DateTime
     47  quantityType  QuantityType  @map("quantity_type")
     48  subTotal      Float         @map("sub_total")
     49  issueDate     DateTime      @map("issue_date")
    4850  month         Month
    4951  discount      Float?
    5052  taxes         Float?
    51   totalAmount   Float
    52   invoiceNumber String         @unique
    53   pdfRef        String?
     53  totalAmount   Float         @map("total_amount")
     54  invoiceNumber String        @unique @map("invoice_number")
     55  pdfRef        String?       @map("pdf_ref")
     56  createdAt     DateTime      @default(now()) @map("created_at")
     57  updatedAt     DateTime      @updatedAt @map("updated_at")
    5458
    55   invoiceFromId String
    56   invoiceFrom   Tenant        @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade)
     59  invoiceFromId String @map("tenant_id")
     60  invoiceFrom   Tenant @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade)
    5761
    58   invoiceToId   String
    59   invoiceTo     Client      @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)
     62  invoiceToId String @map("client_id")
     63  invoiceTo   Client @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)
    6064
    61   items         LineItem[]
     65  items LineItem[]
    6266}
    6367
    6468model LineItem {
    65   id          String   @id @default(uuid())
     69  id          String  @id @default(uuid())
    6670  title       String
    6771  price       Float
     
    6973  quantity    Int
    7074  description String?
    71   serviceId   String
    72   service     Service   @relation(fields: [serviceId], references: [id], onDelete: Cascade)
    73   invoiceId   String
    74   invoice     Invoice   @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
     75  serviceId   String  @map("service_id")
     76  service     Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
     77  invoiceId   String  @map("invoice_id")
     78  invoice     Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
    7579}
    7680
    7781model Tenant {
    78   id                String    @id @default(cuid())
     82  id                String     @id @default(cuid())
    7983  name              String
    80   email             String    @unique
    81   address           Json     
    82   bankAccounts      Json?     
    83   logoUrl           String?
    84   phoneNumber       String?
    85   vatNumber         String?
    86   companyNumber     String?
     84  email             String     @unique
     85  address           Json
     86  bankAccounts      Json?      @map("bank_accounts")
     87  logoUrl           String?    @map("logo_url")
     88  phoneNumber       String?    @map("phone_number")
     89  vatNumber         String?    @map("vat_number")
     90  companyNumber     String?    @map("company_number")
    8791  representative    String
    88   lastInvoiceNumber String    @default("0")
    89   createdAt         DateTime  @default(now())
    90   updatedAt         DateTime  @updatedAt
     92  lastInvoiceNumber String     @default("0") @map("last_invoice_number")
     93  createdAt         DateTime   @default(now()) @map("created_at")
     94  updatedAt         DateTime   @updatedAt @map("updated_at")
    9195  invoicesSent      Invoice[]
    9296  services          Service[]
    9397  employees         Employee[]
    94   clients           Client[]  // Add the relation to clients
     98  clients           Client[]
     99  users             User[]
    95100}
    96101
    97102model Employee {
    98   id          String         @id @default(uuid())
    99   name        String
    100   email       String         @unique
    101   status      EmployeeStatus @default(active)
    102   iban        String?
    103   cv          String?
    104   photo       String?
    105   project     String?
    106   tenantId    String
    107   tenant      Tenant         @relation(fields: [tenantId], references: [id], onDelete: Cascade)
     103  id        String         @id @default(uuid())
     104  name      String
     105  email     String         @unique
     106  status    EmployeeStatus @default(active)
     107  iban      String?
     108  cv        String?
     109  photo     String?
     110  project   String?
     111  tenantId  String         @map("tenant_id")
     112  tenant    Tenant         @relation(fields: [tenantId], references: [id], onDelete: Cascade)
     113  createdAt DateTime       @default(now()) @map("created_at")
     114  updatedAt DateTime       @updatedAt @map("updated_at")
    108115}
    109116
    110 // Enums
    111 enum CustomerStatus {
    112   active
    113   banned
    114   inactive
     117model User {
     118  id          String   @id @default(uuid())
     119  uid         String   @unique // Firebase UID
     120  email       String   @unique
     121  displayName String   @map("display_name")
     122  role        UserRole
     123  tenantId    String   @map("tenant_id")
     124  tenant      Tenant   @relation(fields: [tenantId], references: [id], onDelete: Cascade)
     125  createdAt   DateTime @default(now()) @map("created_at")
     126  updatedAt   DateTime @updatedAt @map("updated_at")
     127}
     128
     129enum UserRole {
     130  ADMIN   @map("ADMIN")
     131  MANAGER @map("MANAGER")
     132  USER    @map("USER")
     133}
     134
     135enum ClientStatus {
     136  active   @map("ACTIVE")
     137  banned   @map("BANNED")
     138  inactive @map("INACTIVE")
    115139}
    116140
    117141enum InvoiceStatus {
    118   draft
    119   processing
    120   pending
    121   overdue
    122   paid
     142  draft      @map("DRAFT")
     143  processing @map("PROCESSING")
     144  pending    @map("PENDING")
     145  overdue    @map("OVERDUE")
     146  paid       @map("PAID")
    123147}
    124148
    125149enum Currency {
    126   EUR
    127   USD
     150  EUR @map("EUR")
     151  USD @map("USD")
    128152}
    129153
    130154enum QuantityType {
    131   Unit
    132   Hour
    133   Sprint
    134   Month
     155  Unit   @map("UNIT")
     156  Hour   @map("HOUR")
     157  Sprint @map("SPRINT")
     158  Month  @map("MONTH")
    135159}
    136160
    137161enum Month {
    138   January
    139   February
    140   March
    141   April
    142   May
    143   June
    144   July
    145   August
    146   September
    147   October
    148   November
    149   December
     162  January   @map("JANUARY")
     163  February  @map("FEBRUARY")
     164  March     @map("MARCH")
     165  April     @map("APRIL")
     166  May       @map("MAY")
     167  June      @map("JUNE")
     168  July      @map("JULY")
     169  August    @map("AUGUST")
     170  September @map("SEPTEMBER")
     171  October   @map("OCTOBER")
     172  November  @map("NOVEMBER")
     173  December  @map("DECEMBER")
    150174}
    151175
    152176enum EmployeeStatus {
    153   active
    154   inactive
     177  active   @map("ACTIVE")
     178  inactive @map("INACTIVE")
    155179}
  • prisma/seed.js

    r3c5302a r87c9f1e  
    66  // Clear existing data
    77  await prisma.service.deleteMany();
     8  await prisma.user.deleteMany();
    89  await prisma.tenant.deleteMany();
    910
    1011  // Define default tenant data
    1112  const tenantData = {
    12     name: "Default Company",
    13     email: "contact@defaultcompany.com",
     13    id: "cm7lxc3p00000pb7kmdrxsfod",
     14    name: "MVP Masters",
     15    email: "info@mvpmasters.com",
    1416    address: {
    15       street: "123 Business Street",
    16       city: "Business City",
    17       state: "BS",
    18       zip: "12345",
    19       country: "United States"
     17      street: "Makedonska Treta Brigada 56",
     18      city: "Skopje",
     19      state: "Macedonia",
     20      zip: "1000",
     21      country: "Macedonia"
    2022    },
    21     phoneNumber: "+1 234 567 8900",
    22     representative: "John Doe",
     23    phoneNumber: "+389 72 233 943",
     24    representative: "Naum Shapkarovski",
    2325    lastInvoiceNumber: "1",
    2426    logoUrl: "https://example.com/default-logo.png",
     
    7274  });
    7375
     76  // Add default admin user
     77  const defaultUser = await prisma.user.create({
     78    data: {
     79      id: 'dK2y3WezYWWltHCaBRvUFlddkOr2',
     80      uid: 'dK2y3WezYWWltHCaBRvUFlddkOr2',
     81      email: 'naum@mvpmasters.com',
     82      displayName: 'Naum',
     83      role: 'ADMIN',
     84      tenantId: 'cm7lxc3p00000pb7kmdrxsfod'
     85    }
     86  });
     87
    7488  console.log('Seeded default tenant:', defaultTenant);
     89  console.log('Seeded default user:', defaultUser);
    7590
    7691  console.log('🌱 Seeding database...');
  • service-account.json

    r3c5302a r87c9f1e  
    11{
    22  "type": "service_account",
    3   "project_id": "mvp-masters",
    4   "private_key_id": "41113eebee172158f148448927355ce095b111f3",
    5   "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCjMylcnnaenb6k\nDRY++GyIHbyyzQc+5ChXd6ixB5x0KYLLDs/6hqgSeIjI3urLee7i05NeQYVGIXGE\nvjqOhTdjwr11hIHRcNMIAjMYaI4HNiJHweQa72ux9dB1cZpYpQQrBuG5k3Sf/WjO\ntfiPnP7a7dR00KctsL22FAm4JH+CvfTWQoLpa7n3bhQmNOXZmCLb2ZRU6AkGuYh+\nq5ko5epj7sCtyqAcefUJXysC0EpRySgbeQsXewyvBrSOx2onPnjq+q0Zw9PdVhOH\nSr3zwdQq9DDLYOH1YB1DbaOEI+8tybCT3HHIOKJpCVga/mVZtzoEBR4zbbnkzshe\nS7IDPh2NAgMBAAECggEAIqDFrzkRZsUGUTVUqc5Y6wXSRucRmULcm3iQkuWQSSaQ\nscjGEPyW93pbXbHNBJkt+rOVcpu47WFFvrqFXr29+70zqZaQ3BGSOYIL+Osgbb/L\nBMpLffqcsZE8ptrQuuvip0WJyjBTP+pLXYcHg2N2wRnTKWkne96jVlnImSmnY6RW\n57V0ch/1PjX3SUQaBST6/BkW4qeo93rDU+qhuirtWhTcP64BQyX2CYzzJayLbNuL\ndETvIOaIEw48aBbHGHsmkxUw4E0UaYctaRDAZNlmxA2hulosG6F/TiAQ6/fF+ZCC\nssk5DM5/hGb62/H+Hdoyru/OIjYqNAScgWFjPm50wQKBgQC3Q9qcdm2qzkupEOfj\n2/ATjiXwZkcOjqWFAZuwI0wh4pbuK6dwzUypicMPf9UbGbp48xJKedzXSV5cC+bs\nCubZjdp5pwDyz1gj2QrHTZ37BV93OQyFdjpKVGZHUNVXsDdRmEG3wdrA+TXbGsnU\nLcQrUjjJSlx+PKVUya8OB2PFwQKBgQDj+KMhYbGXsoWWJyV8dzl/jOHc2axW6kc5\nPvnx48sMDgCwHSDTKC5h3IOrbBXTdAlbqztLMCyd7O0OTPFFBbBz4WdICPdl3n0h\nMYySReqjW/cG+ataLRNZ3p1DtKwxLDONSEEib0XyW2x2i4S8QMwUM31hbusbtBz6\ngBnUGJ1CzQKBgQCM/4GUW3FotqtzefRPVQnSoc0Ctk35HzqtqF0WGTIb5+9jcuay\nXOGclscih6F35kWXhLwP3M5SPLqCaw3RkVmnDAKJEjoilfAkNHqceFURqkKWwaem\njx2tzl2ahNB/VK5a8p+tN1KMobAT0PpzanrBMdNK2xFqdlJld35ddsYGgQKBgQCs\n7WFJJCMj0C6XLNC5rnK2N3bpIVEiiQpH+WZ9v265kTGiZiYNJtCwOSbD9PRFdyLW\nH3iV21As55kWnPTzh5JHBLdkpDCOXIwMjtpz5odLLaqf5um9OK4SINSolDd+AWqF\nhEasST4Ezqbi8YhZiMmFlV1JeGrtk93bgyqUgathDQKBgDrnDmIUr9czUIUHIiyz\nFuUDAVqzVAGNol3KknCGfxPssGj7ln+ml7b+db44QKloWxDvtXKiUEVBzYsTsTnz\nX40/oD5FlobeEYUNSIUza/SAhf8KzX6ISo/Ogk8YMd4mvZxeeXPFQHgHd3mJR1s9\ngnNcqCHEulwV+m9E3dnNU6ds\n-----END PRIVATE KEY-----\n",
    6   "client_email": "firebase-adminsdk-6i4ka@mvp-masters.iam.gserviceaccount.com",
    7   "client_id": "104648727229584211592",
     3  "project_id": "agency-os-prod",
     4  "private_key_id": "1e74e55e80a03fc705c995b8d2430f6d4761a281",
     5  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCUrVSjMy575tLw\n2bw10FkzfIRxgY0UWPvlhwH1o8iRV9PQMgPr4HmGwK9CmUIqa3LRdi4KzrrCPYoP\noBzMxJCuPSR9ii9XNdqH0uLolP05xOkfCpxUMR5dgS3ExreX+d9xwFVwjfoHRiuw\nNYoayYZrJakhmzmRAU5oiwVZzFtBilQKkvnQJbIIlovksczBE4xUlTz4xmrZWtvQ\nzEnthzxCDrdCvrw5YtafOGpPNg0rEbA9+IwykPWNR+YYVQXLuIKHNYQSV+SlmYAz\n9CdN3Yl+TIsX01aPMJ+gHPr3OhVTk3a97I6WJ7/NIIMDnEvnVU5dYn8j9GwxIWqP\nIWfs9NizAgMBAAECggEASlXLTnmlkR9ccj17A7DzGHH2SkYKwpSnBSCWUzmba0ft\nSFfpbALk4AHw3qx/z3O/iYi8Bn1MFRftslhMbfkNmYBKgVYYy1LKu0QuXTk4zqxs\nHjAQ72tLklanCo6MdrjhBh+y2D60NvTXnRd3wGLoCSRgRsQ0aRKtIEn51+b77W03\n7VLrXjoXdA6/J4X7NGXN12z4YCUnq7MjTcWoGKYnM0nnay8fFdQw598/CfZBY+zb\nYw9u9E8//OCmQ9p15nmcky+ZOq1lbjPLvOamErLHI+Z+bdRlqQugURItT6rTn4rs\nxxn+VqZ33TDo8iu5jOueEFyu6v/Irs/pQmWQjO/V6QKBgQDHDlqxeD05ac/Mus2m\ncUZesbZPEOLf1iuNRGGyZhUWIH63neCBtMxmpunG27u8Zcc4nOSDb8gVowkrBwRf\nxOT9QkW4Z++0CykMoZFrHySjrx6pgG5ylR6hutJZ8aI07uLU+H1DnkInQwmNrA38\njYu239ofZWsRYB/OXAtMLHqDtwKBgQC/NYcJkyADsZB+UNguwxwPxi2U6vaBh2a4\n+W2F0LI47tNkwXtfNPlDRdTwraoucKlPvu6gcHvSt+MQEPkx1gwdnIgiBoeooi4P\nLDUp4OKWdTPo+s4D0W8Z5h2l5/Fegu/Fn6l0iu8hldeAknttwrwTaoq7M+LeJtcX\nuW+Cjkcq5QKBgEMPi/BkIMQ56J8BhA0B9oIqfs/uUXC1l6CVHBDdIVd+BRLZJmys\nO3yN2Q58sqfK5i4ldTruqsrXTVxolcmp7LeB3zk8Et5mMCMoP3SGXnKiqcLTGOKT\naGl2Ji3VIR+SJ2s2eAUSyRivFgXbpC6khSBMFBElusd0yeJc0hWMmo3LAoGASilt\nvdX1pdkaDRQ4NTLx0GByT38uqyCkQ/xicXN3nMNs9Hhi7JN0VpZgOBVzm12RHeAV\nV98o95rhE9sxfBXkTxvmZSQZO9vjd3kTCbIy0F6XCrc0bqCtseLh/vZOVPT+IK2D\noTM9+s3ObwzhmLneDr3VHzTJupZf+NCwoneivM0CgYEAxIp4qoX/cBpUTfR2Q99r\nzaaYufgs4PcekDPXykJxrdjDmP5cOSIwyAUf6k1fTUB3qyhtlyq481K3dQBpKOP3\nbQAJrxl6w+/rNS2YIdjM9RXw1wHNiLd0RfaNtzdebdiILYzRzSLdBmtzwXKmw7Cu\ntS4FVx/E+qdHsOyggGub24k=\n-----END PRIVATE KEY-----\n",
     6  "client_email": "firebase-adminsdk-fbsvc@agency-os-prod.iam.gserviceaccount.com",
     7  "client_id": "102922480115315079115",
    88  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    99  "token_uri": "https://oauth2.googleapis.com/token",
    1010  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    11   "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-6i4ka%40mvp-masters.iam.gserviceaccount.com",
     11  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40agency-os-prod.iam.gserviceaccount.com",
    1212  "universe_domain": "googleapis.com"
    1313}
  • src/api/invoice.ts

    r3c5302a r87c9f1e  
    8181// Add this interface for the create invoice payload
    8282interface CreateInvoicePayload {
    83   createDate: Date;
     83  issueDate: Date;
    8484  dueDate: Date;
    8585  items: any[];
  • src/app/api/customers/route.ts

    r3c5302a r87c9f1e  
    33import prisma from 'src/lib/prisma';
    44import { authenticateRequest } from 'src/lib/auth-middleware';
    5 import { CustomerStatus } from '@prisma/client';
    6 import { Prisma } from '@prisma/client';
     5import { Prisma, ClientStatus } from '@prisma/client';
    76
    87export async function GET(request: NextRequest) {
     
    2524    const validatedFilters = customerTableFiltersSchema.parse(filters);
    2625
    27     // Replace Prisma query with raw SQL
    28     const customers = await prisma.$queryRaw`
    29       SELECT * FROM "Client"
    30       WHERE "tenantId" = ${tenantId}
    31         AND LOWER(name) LIKE LOWER(${`%${validatedFilters.name}%`})
    32         ${
    33           validatedFilters.status
    34             ? Prisma.sql`AND status = ${validatedFilters.status}::"CustomerStatus"`
    35             : Prisma.sql`AND TRUE`
    36         }
    37     `;
     26    //   const customers = await prisma.$queryRaw`
     27    //   SELECT * FROM "Client"
     28    //   WHERE "tenant_id" = ${tenantId}
     29    //     AND LOWER(name) LIKE LOWER(${`%${validatedFilters.name}%`})
     30    //     ${
     31    //       validatedFilters.status
     32    //         ? Prisma.sql`AND status = ${validatedFilters.status}::"CustomerStatus"`
     33    //         : Prisma.sql`AND TRUE`
     34    //     }
     35    // `;
     36
     37    const customers = await prisma.client.findMany({
     38      where: {
     39        tenantId,
     40        name: {
     41          contains: validatedFilters.name,
     42          mode: 'insensitive',
     43        },
     44        ...(validatedFilters.status && {
     45          status: validatedFilters.status as ClientStatus,
     46        }),
     47      },
     48    });
    3849
    3950    return NextResponse.json(customers);
     
    6071      data: {
    6172        ...validatedData,
    62         // userId,
    6373        tenantId,
    6474      },
  • src/app/api/invoices/[id]/route.ts

    r3c5302a r87c9f1e  
    100100        data: {
    101101          invoiceNumber: validation.data.invoiceNumber,
    102           createDate: validation.data.createDate,
     102          issueDate: validation.data.issueDate,
    103103          dueDate: validation.data.dueDate,
    104104          status: validation.data.status,
  • src/app/api/invoices/route.ts

    r3c5302a r87c9f1e  
    4545          ? { equals: validatedFilters.status as InvoiceStatus }
    4646          : undefined,
    47         createDate: {
     47        issueDate: {
    4848          ...(validatedFilters.startDate && { gte: validatedFilters.startDate }),
    4949          ...(validatedFilters.endDate && { lte: validatedFilters.endDate }),
     
    108108        quantityType: validatedData.quantityType,
    109109        subTotal: validatedData.subTotal,
    110         createDate: validatedData.createDate,
     110        issueDate: validatedData.issueDate,
    111111        month: validatedData.month,
    112112        discount: validatedData.discount,
  • src/app/api/invoices/totals/route.ts

    r3c5302a r87c9f1e  
    2020    const searchParams = request.nextUrl.searchParams;
    2121    const startDate = searchParams.get('startDate')
    22       ? new Date(searchParams.get('startDate')!)
     22      ? new Date(searchParams.get('issueDate')!)
    2323      : null;
    2424
     
    3232        status,
    3333        currency,
    34         SUM("totalAmount") as total
     34        SUM("total_amount") as total
    3535      FROM "Invoice"
    36       WHERE "createDate" >= ${startDate}
    37         AND "invoiceFromId" = ${tenantId}
     36      WHERE "issue_date" >= ${startDate}
     37        AND "tenant_id" = ${tenantId}
    3838      GROUP BY status, currency
    3939    `;
  • src/app/dashboard/customer/list/page.tsx

    r3c5302a r87c9f1e  
    11// sections
    2 import { CustomerListView } from 'src/sections/user/view';
     2import { CustomerListView } from 'src/sections/client/view';
    33
    44// ----------------------------------------------------------------------
  • src/app/dashboard/customer/new/page.tsx

    r3c5302a r87c9f1e  
    11// sections
    2 import { CustomerCreateView } from 'src/sections/user/view';
     2import { CustomerCreateView } from 'src/sections/client/view';
    33
    44// ----------------------------------------------------------------------
  • src/app/loading.tsx

    r3c5302a r87c9f1e  
    77
    88export default function Loading() {
    9   return <SplashScreen />;
     9  return (
     10    <div className="flex min-h-screen items-center justify-center">
     11      <div className="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-blue-500"></div>
     12    </div>
     13  );
    1014}
  • src/app/not-found.tsx

    r3c5302a r87c9f1e  
    11// sections
    22import { NotFoundView } from 'src/sections/error';
     3import Link from 'next/link';
    34
    45// ----------------------------------------------------------------------
     
    89};
    910
    10 export default function NotFoundPage() {
    11   return <NotFoundView />;
     11export default function NotFound() {
     12  return (
     13    <div className="flex min-h-screen flex-col items-center justify-center">
     14      <h2 className="text-2xl font-bold mb-4">Page Not Found</h2>
     15      <p className="mb-4">Could not find requested resource</p>
     16      <Link href="/" className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
     17        Return Home
     18      </Link>
     19    </div>
     20  );
    1221}
  • src/auth/context/firebase/auth-provider.tsx

    r3c5302a r87c9f1e  
    2121import { AuthContext } from './auth-context';
    2222import { ActionMapType, AuthStateType, AuthUserType } from '../../types';
     23import { getUser } from 'src/api/user';
    2324
    2425// ----------------------------------------------------------------------
     
    7172        if (user) {
    7273          if (user.emailVerified) {
    73             const userProfile = doc(db, collections.administrator, user.uid);
    74 
    75             const docSnap = await getDoc(userProfile);
    76 
    77             const profile = docSnap.data();
    78 
    79             dispatch({
    80               type: Types.INITIAL,
    81               payload: {
    82                 user: {
    83                   ...user,
    84                   ...profile,
    85                   id: user.uid,
     74            try {
     75              const profile = await getUser();
     76              console.log('profile', profile);
     77
     78              dispatch({
     79                type: Types.INITIAL,
     80                payload: {
     81                  user: { ...profile, emailVerified: user.emailVerified },
    8682                },
    87               },
    88             });
     83              });
     84            } catch (error) {
     85              console.error('Failed to fetch user profile:', error);
     86              dispatch({
     87                type: Types.INITIAL,
     88                payload: {
     89                  user: null,
     90                },
     91              });
     92            }
    8993          } else {
    9094            dispatch({
     
    145149  const register = useCallback(
    146150    async (email: string, password: string, firstName: string, lastName: string) => {
    147       const newUser = await createUserWithEmailAndPassword(auth, email, password);
    148 
    149       await sendEmailVerification(newUser.user);
    150 
    151       const userProfile = doc(collection(db, collections.administrator), newUser.user?.uid);
    152 
    153       await setDoc(userProfile, {
    154         uid: newUser.user?.uid,
    155         email,
    156         displayName: `${firstName} ${lastName}`,
    157       });
     151      // const newUser = await createUserWithEmailAndPassword(auth, email, password);
     152      // await sendEmailVerification(newUser.user);
     153      // const userProfile = doc(collection(db, collections.administrator), newUser.user?.uid);
     154      // await setDoc(userProfile, {
     155      //   uid: newUser.user?.uid,
     156      //   email,
     157      //   displayName: `${firstName} ${lastName}`,
     158      // });
    158159    },
    159160    []
  • src/layouts/dashboard/nav-horizontal.tsx

    r3c5302a r87c9f1e  
    4141          data={navData}
    4242          config={{
    43             currentRole: user?.role || 'admin',
     43            currentRole: user?.role || 'ADMIN',
    4444          }}
    4545        />
  • src/layouts/dashboard/nav-mini.tsx

    r3c5302a r87c9f1e  
    5151          data={navData}
    5252          config={{
    53             currentRole: user?.role || 'admin',
     53            currentRole: user?.role || 'ADMIN',
    5454          }}
    5555        />
  • src/layouts/dashboard/nav-vertical.tsx

    r3c5302a r87c9f1e  
    5858        data={navData}
    5959        config={{
    60           currentRole: user?.role || 'admin',
     60          currentRole: user?.role || 'ADMIN',
    6161        }}
    6262      />
  • src/lib/auth-middleware.ts

    r3c5302a r87c9f1e  
    2121  try {
    2222    // Verify the token
    23     // const decodedToken = await auth.verifyIdToken(token);
    24     // const userId = decodedToken.uid;
    25     // const tenantId = decodedToken.customClaims?.tenantId || 'cm7lxc3p00000pb7kmdrxsfod';
     23    const decodedToken = await auth.verifyIdToken(token);
     24    const userId = decodedToken.uid;
    2625
    27     // if (!userId || !tenantId) {
    28     //   return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
    29     // }
     26    const tenantId = decodedToken.customClaims?.tenantId || 'cm7lxc3p00000pb7kmdrxsfod';
    3027
    31     return { userId: 'nlswimR6mMQtirTNlMeqhqcSZeD3', tenantId: 'cm7lxc3p00000pb7kmdrxsfod' };
     28    if (!userId || !tenantId) {
     29      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
     30    }
     31
     32    return { userId, tenantId: 'cm7lxc3p00000pb7kmdrxsfod' };
    3233  } catch (error) {
     34    console.error('Error verifying token:', error);
    3335    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
    3436  }
  • src/schemas/invoice.ts

    r3c5302a r87c9f1e  
    6767  ]),
    6868  subTotal: z.number(),
    69   createDate: z.coerce.date(),
     69  issueDate: z.coerce.date(),
    7070  month: monthSchema,
    7171  discount: z.number().optional(),
  • src/sections/invoice/invoice-details.tsx

    r3c5302a r87c9f1e  
    261261              Date Issued
    262262            </Typography>
    263             {fDate(invoice.createDate)}
     263            {fDate(invoice.issueDate)}
    264264          </Stack>
    265265
  • src/sections/invoice/invoice-ee-pdf.tsx

    r3c5302a r87c9f1e  
    129129    discount,
    130130    invoiceTo,
    131     createDate,
     131    issueDate,
    132132    totalAmount,
    133133    invoiceFrom,
     
    229229          <View style={styles.col6}>
    230230            <Text style={[styles.subtitle1, styles.mb4]}>Date Issued</Text>
    231             <Text style={styles.body2}>{fDate(createDate)}</Text>
     231            <Text style={styles.body2}>{fDate(issueDate)}</Text>
    232232          </View>
    233233          <View style={styles.col6}>
  • src/sections/invoice/invoice-mk-pdf.tsx

    r3c5302a r87c9f1e  
    113113    discount,
    114114    invoiceTo,
    115     createDate,
     115    issueDate,
    116116    totalAmount,
    117117    invoiceFrom,
     
    179179          <View style={styles.col6}>
    180180            <Text style={[styles.subtitle1, styles.mb4]}>Date Issued</Text>
    181             <Text style={styles.body2}>{fDate(createDate)}</Text>
     181            <Text style={styles.body2}>{fDate(issueDate)}</Text>
    182182          </View>
    183183          <View style={styles.col6}>
  • src/sections/invoice/invoice-new-edit-form.tsx

    r3c5302a r87c9f1e  
    8181  const NewInvoiceSchema = Yup.object().shape({
    8282    invoiceNumber: Yup.string().nullable().required('Invoice number is required'),
    83     createDate: Yup.mixed<any>().nullable().required('Create date is required'),
     83    issueDate: Yup.mixed<any>().nullable().required('Create date is required'),
    8484    dueDate: Yup.mixed<any>()
    8585      .required('Due date is required')
     
    8787        'date-min',
    8888        'Due date must be later than create date',
    89         (value, { parent }) => value.getTime() > parent.createDate.getTime()
     89        (value, { parent }) => value.getTime() > parent.issueDate.getTime()
    9090      ),
    9191    invoiceFrom: Yup.mixed<any>().nullable().required('Invoice from is required'),
     
    117117          ? currentInvoice?.invoiceNumber
    118118          : incrementInvoiceNumber(tenant?.lastInvoiceNumber),
    119       createDate: currentInvoice?.createDate ? new Date(currentInvoice.createDate) : new Date(),
     119      issueDate: currentInvoice?.issueDate ? new Date(currentInvoice.issueDate) : new Date(),
    120120      dueDate: currentInvoice?.dueDate
    121121        ? new Date(currentInvoice.dueDate)
     
    175175
    176176      // Ensure dates are valid Date objects
    177       const createDate =
    178         data.createDate instanceof Date ? data.createDate : new Date(data.createDate);
     177      const issueDate = data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
    179178      const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
    180179
    181180      const currentTime = new Date();
    182       createDate.setHours(
     181      issueDate.setHours(
    183182        currentTime.getHours(),
    184183        currentTime.getMinutes(),
     
    197196        invoiceNumber: incrementInvoiceNumber(tenant?.lastInvoiceNumber),
    198197        status: 'draft',
    199         createDate,
     198        issueDate,
    200199        dueDate,
    201200        items: items.filter((item) => item.service !== null) as CreateInvoice['items'],
     
    246245      if (currentInvoice) {
    247246        // Ensure dates are valid Date objects
    248         const createDate =
    249           data.createDate instanceof Date ? data.createDate : new Date(data.createDate);
     247        const issueDate =
     248          data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
    250249        const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
    251250
     
    259258        const writeData = {
    260259          ...data,
    261           createDate,
     260          issueDate,
    262261          dueDate,
    263262          items,
     
    312311
    313312        // Ensure dates are valid Date objects
    314         const createDate =
    315           data.createDate instanceof Date ? data.createDate : new Date(data.createDate);
     313        const issueDate =
     314          data.issueDate instanceof Date ? data.issueDate : new Date(data.issueDate);
    316315        const dueDate = data.dueDate instanceof Date ? data.dueDate : new Date(data.dueDate);
    317316
     
    325324        const writeData = {
    326325          ...data,
    327           createDate,
     326          issueDate,
    328327          dueDate,
    329328          items,
  • src/sections/invoice/invoice-new-edit-status-date.tsx

    r3c5302a r87c9f1e  
    109109
    110110      <Controller
    111         name="createDate"
     111        name="issueDate"
    112112        control={control}
    113113        render={({ field, fieldState: { error } }) => (
  • src/sections/invoice/invoice-table-row.tsx

    r3c5302a r87c9f1e  
    5151    sent,
    5252    invoiceNumber,
    53     createDate,
     53    issueDate,
    5454    dueDate,
    5555    status,
     
    6060  } = row;
    6161
    62   console.log(createDate);
     62  console.log(issueDate);
    6363
    6464  const confirmSend = useBoolean();
     
    107107        <TableCell>
    108108          <ListItemText
    109             primary={format(new Date(createDate), 'dd MMM yyyy')}
    110             secondary={format(new Date(createDate), 'p')}
     109            primary={format(new Date(issueDate), 'dd MMM yyyy')}
     110            secondary={format(new Date(issueDate), 'p')}
    111111            primaryTypographyProps={{ typography: 'body2', noWrap: true }}
    112112            secondaryTypographyProps={{
  • src/sections/invoice/view/invoice-list-view.tsx

    r3c5302a r87c9f1e  
    5959  { id: 'currency', label: 'Currency' },
    6060  { id: 'invoicePeriod', label: 'Invoice Period' },
    61   { id: 'createDate', label: 'Create' },
     61  { id: 'issueDate', label: 'Create' },
    6262  { id: 'dueDate', label: 'Due' },
    6363  { id: 'sent', label: 'Sent', align: 'center' },
     
    152152
    153153  const table = useTable({
    154     defaultOrderBy: 'createDate',
     154    defaultOrderBy: 'issueDate',
    155155    defaultOrder: 'desc',
    156156    defaultDense: true,
     
    166166      collections.invoice,
    167167      JSON.stringify({
    168         where: [['createDate', '>=', filters.startDate]],
    169         orderBy: 'createDate',
     168        where: [['issueDate', '>=', filters.startDate]],
     169        orderBy: 'issueDate',
    170170        direction: 'desc',
    171171      }),
     
    275275    async (invoice: Invoice) => {
    276276      const serializedParams = JSON.stringify({
    277         where: [['createDate', '>=', filters.startDate]],
    278         orderBy: 'createDate',
     277        where: [['issueDate', '>=', filters.startDate]],
     278        orderBy: 'issueDate',
    279279        direction: 'desc',
    280280      });
     
    671671      inputData = inputData.filter(
    672672        (invoice) =>
    673           fTimestamp(invoice.createDate.getTime()) >= fTimestamp(startDate.getTime()) &&
    674           fTimestamp(invoice.createDate.getTime()) <= fTimestamp(endDate.getTime())
     673          fTimestamp(invoice.issueDate.getTime()) >= fTimestamp(startDate.getTime()) &&
     674          fTimestamp(invoice.issueDate.getTime()) <= fTimestamp(endDate.getTime())
    675675      );
    676676    }
Note: See TracChangeset for help on using the changeset viewer.