From 789e9acf89e49974f19a5eedbc905a8c4da4b0e5 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Wed, 4 Feb 2026 08:27:38 -0500 Subject: [PATCH] fix(mariaDB): fixed account service functions to use new prisma setup --- .../accounts/account.service.ts | 66 +------------------ .../accounts/test-account.service.ts | 58 ++++++++++++++++ 2 files changed, 60 insertions(+), 64 deletions(-) create mode 100644 src/customer-support/accounts/test-account.service.ts diff --git a/src/customer-support/accounts/account.service.ts b/src/customer-support/accounts/account.service.ts index 455a90d..5d13bb4 100644 --- a/src/customer-support/accounts/account.service.ts +++ b/src/customer-support/accounts/account.service.ts @@ -1,12 +1,12 @@ import { Injectable } from "@nestjs/common"; -import { PrismaClient } from "prisma/generated/mariadb/client"; +import { PrismaClient as MariaDbPrismaClient } from "prisma/generated/mariadb/client"; import { Result } from "src/common/errors/result-error.factory"; import { Account, AccountMemo } from "src/customer-support/accounts/account.dto"; @Injectable() export class AccountService { - constructor(private readonly prismaMariaDb: PrismaClient) { } + constructor(private readonly prismaMariaDb: MariaDbPrismaClient) { } findAllAccounts = async (): Promise> => { const listOfAccounts: Account[] = []; @@ -89,65 +89,3 @@ export class AccountService { return { success: true, data: listOfMemos } } } - -export const findAllAccounts = async (prismaMariaDb: PrismaClient): Promise> => { - const listOfAccounts: Account[] = []; - - const rawListOfAccounts = await prismaMariaDb.account.findMany({}); - if (!rawListOfAccounts) return { success: false, error: 'ACCOUNTS_NOT_FOUND' } - try { - - for (const account of rawListOfAccounts) { - const emailList: string[] = [ - account.email ? account.email : '', - account.email_autre ? account.email_autre : '', - ]; - - const addressList: string[] = [ - account.address1 ? account.address1 : '', - account.address2 ? account.address2 : '', - account.city ? account.city : '', - account.state ? account.state : '', - account.zip ? account.zip : '', - account.country_id.toString(), - ]; - - listOfAccounts.push({ - id: Number(account.id), - customerId: account.customer_id ? account.customer_id : '', - language: account.language_id, - username: account.username ? account.username : '', - password: account.password ? account.password : '', - groupId: account.group_id ? account.group_id : 0, - status: account.status ? account.status : 0, - firstName: account.first_name ? account.first_name : '', - lastName: account.last_name ? account.last_name : '', - mandataire: account.mandataire ? account.mandataire : '', - title: account.title ? account.title : '', - email: emailList, - company: account.company ? account.company : '', - contact: account.contact, - address: addressList, - telHome: account.tel_home ? account.tel_home : '', - telOffice: account.tel_office ? account.tel_office : '', - telOffice_ext: account.tel_office_ext ? account.tel_office_ext : '', - cell: account.cell ? account.cell : '', - fax: account.fax ? account.fax : '', - landOwner: account.land_owner, - commercial: account.commercial, - vip: account.vip, - notes_client: account.notes_client ? account.notes_client : '', - terminateReason: account.terminate_reason ? account.terminate_reason : '', - terminateCie: account.terminate_cie ? account.terminate_cie : '', - terminateNote: account.terminate_note ? account.terminate_note : '', - terminateDate: account.terminate_date ? account.terminate_date : '', - mauvaisPayeur: account.mauvais_payeur, - }); - } - console.log(listOfAccounts); - return { success: true, data: listOfAccounts }; - - } catch (error) { - return { success: false, error: error + " \n An error occured during retrieving the list of accounts" } - } - } \ No newline at end of file diff --git a/src/customer-support/accounts/test-account.service.ts b/src/customer-support/accounts/test-account.service.ts new file mode 100644 index 0000000..2efc754 --- /dev/null +++ b/src/customer-support/accounts/test-account.service.ts @@ -0,0 +1,58 @@ +#!/usr/bin/env ts-node + +import { adapterMariaDb } from 'prisma.config.mariadb'; +import { PrismaClient as MariaDbPrismaClient } from 'prisma/generated/mariadb/client'; +import { AccountService } from 'src/customer-support/accounts/account.service'; + +async function main() { + // Initialize the Prisma client + const prismaMariaDb = new MariaDbPrismaClient({ adapter: adapterMariaDb }); + + // Initialize the service + const accountService = new AccountService(prismaMariaDb); + + try { + // Test 1: Find all accounts + console.log('=== Testing findAllAccounts ==='); + const accountsResult = await accountService.findAllAccounts(); + + if (accountsResult.success) { + console.log(`✓ Successfully retrieved ${accountsResult.data.length} accounts`); + console.log('First account:', JSON.stringify(accountsResult.data[0], null, 2)); + } else { + console.error('✗ Error:', accountsResult.error); + } + + // Test 2: Find memos by account ID + console.log('\n=== Testing findMemosByAccountId ==='); + // Replace with an actual account ID from your database + const testAccountId = 1; + const memosResult = await accountService.findMemosByAccountId(testAccountId); + + if (memosResult.success) { + console.log(`✓ Successfully retrieved ${memosResult.data.length} memos for account ${testAccountId}`); + if (memosResult.data.length > 0) { + console.log('First memo:', JSON.stringify(memosResult.data[0], null, 2)); + } + } else { + console.error('✗ Error:', memosResult.error); + } + + } catch (error) { + console.error('Unexpected error:', error); + } finally { + // Clean up: disconnect from database + await prismaMariaDb.$disconnect(); + } +} + +// Run the main function +main() + .then(() => { + console.log('\n✓ Test completed'); + process.exit(0); + }) + .catch((error) => { + console.error('\n✗ Test failed:', error); + process.exit(1); + }); \ No newline at end of file