diff --git a/src/accounts/account.controller.ts b/src/accounts/account.controller.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/accounts/account.dto.ts b/src/accounts/account.dto.ts deleted file mode 100644 index ddf43d8..0000000 --- a/src/accounts/account.dto.ts +++ /dev/null @@ -1,68 +0,0 @@ -export class AccountDto { - id: number; - customer_id?: string; - language_id: string; - username?: string; - password?: string; - group_id: GroupName; - status?: number; //link to be made with AccountSuspension, somehow - first_name?: string; - last_name?: string; - mandataire?: string; //sometimes the first_name and last_name are found here, sometimes its the name of someone who manage the account - title?: Title; - email?: string[]; - company?: string; - contact: string; - address?: string[]; //string of country, city, state, zip, road, number, apt concat. - tel_home?: string; - tel_office?: string; - tel_office_ext?: string; - cell?: string; - fax?: string; - land_owner: boolean; - commercial: boolean; - vip: boolean; - notes_client?: string[]; - terminate_reason?: string; - terminate_cie?: string; - terminate_note?: string; - terminate_date?: string; - mauvais_payeur: boolean; -}; - -export class AccountMemo { - last_updated: number; - staff_id: number; - memo?: string[]; -}; - -//represents the account_group table -class GroupName { - Admin: number = 1; - Comptabilite: number = 2; - Facturation: number = 3; - Staff: number = 4; - Client: number = 5; - Prospect: number = 6; - Fournisseur: number = 7; - Relais: number = 8; - Cabinet: number = 9; - ÉquipementMotorisé: number = 10; -}; - -//represents the country table -class Country { - canada: number = 120; - madagascar: number = 450; - virginIsland: number = 840; -}; - - -// enum placeholder to avoid direct entries to the DB -class Title { - m: string = 'M'; - mDot: string = 'M.'; - mr: string = 'Mr'; - mrs: string = 'Mrs'; - mme: string = 'Mme'; -}; diff --git a/src/accounts/account.module.ts b/src/accounts/account.module.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/accounts/account.service.ts b/src/accounts/account.service.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/errors/result-error.factory.ts b/src/common/errors/result-error.factory.ts new file mode 100644 index 0000000..5f7eec6 --- /dev/null +++ b/src/common/errors/result-error.factory.ts @@ -0,0 +1,4 @@ +export type Result = + | { success: true; data: T } + | { success: false; error: E }; + diff --git a/src/technical and support services/accounts/account.controller.ts b/src/technical and support services/accounts/account.controller.ts new file mode 100644 index 0000000..9443c1f --- /dev/null +++ b/src/technical and support services/accounts/account.controller.ts @@ -0,0 +1,19 @@ +import { Controller } from "@nestjs/common"; +import { AccountService } from "src/technical and support services/accounts/account.service"; + + +@Controller() +export class AccountController { + constructor(private readonly accountService: AccountService) { } + + findAllAccounts = async() => { + return await this.accountService.findAllAccounts(); + } + + findMemosByAccountId = async( + accountId:number, + ) => { + return await this.accountService.findMemosByAccountId(accountId); + } + +} \ No newline at end of file diff --git a/src/technical and support services/accounts/account.dto.ts b/src/technical and support services/accounts/account.dto.ts new file mode 100644 index 0000000..d5bba5e --- /dev/null +++ b/src/technical and support services/accounts/account.dto.ts @@ -0,0 +1,37 @@ +export class Account { + id: number; + customerId?: string; + language: string; + username?: string; + password?: string; + groupId: number; + status?: number; + firstName?: string; + lastName?: string; + mandataire?: string; //sometimes the first_name and last_name are found here, sometimes its the name of someone who manage the account + title?: string; + email?: string[]; + company?: string; + contact: string; + address?: string[]; //string of country, city, state, zip, road, number, apt concat. + telHome?: string; + telOffice?: string; + telOffice_ext?: string; + cell?: string; + fax?: string; + landOwner: boolean; + commercial: boolean; + vip: boolean; + notes_client?: string; + terminateReason?: string; + terminateCie?: string; + terminateNote?: string; + terminateDate?: string; + mauvaisPayeur: boolean; +}; + +export class AccountMemo { + last_updated: number; + staff_id: number; + memo?: string; +}; diff --git a/src/technical and support services/accounts/account.module.ts b/src/technical and support services/accounts/account.module.ts new file mode 100644 index 0000000..c548d85 --- /dev/null +++ b/src/technical and support services/accounts/account.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { AccountController } from "src/technical and support services/accounts/account.controller"; +import { AccountService } from "src/technical and support services/accounts/account.service"; + + +@Module({ + providers: [ + AccountService + ], + controllers: [ + AccountController + ], +}) export class AccountModule { }; \ No newline at end of file diff --git a/src/technical and support services/accounts/account.service.ts b/src/technical and support services/accounts/account.service.ts new file mode 100644 index 0000000..2e0c1a5 --- /dev/null +++ b/src/technical and support services/accounts/account.service.ts @@ -0,0 +1,91 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaClient } from "generated/prisma/client"; +import { Result } from "src/common/errors/result-error.factory"; +import { Account, AccountMemo } from "src/technical and support services/accounts/account.dto"; + + +@Injectable() +export class AccountService { + constructor(private readonly prisma: PrismaClient) { } + + findAllAccounts = async (): Promise> => { + const listOfAccounts: Account[] = []; + + const rawListOfAccounts = await this.prisma.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" } + } + } + + findMemosByAccountId = async (accountId: number): Promise> => { + const listOfMemos: AccountMemo[] = []; + + const rawListOfMemos = await this.prisma.account_memo.findMany({ + where: { account_id: accountId }, + select: { last_updated: true, staff_id: true, memo: true }, + }); + if (!rawListOfMemos) return { success: false, error: 'MEMOS_NOT_FOUND' }; + + for (const memo of rawListOfMemos) { + listOfMemos.push({ + last_updated: Number(memo.last_updated), + staff_id: Number(memo.staff_id), + memo: memo.memo ? memo.memo : '', + }); + } + return { success: true, data: listOfMemos } + } +} \ No newline at end of file diff --git a/src/deliveries/delivery.controller.ts b/src/technical and support services/deliveries/delivery.controller.ts similarity index 100% rename from src/deliveries/delivery.controller.ts rename to src/technical and support services/deliveries/delivery.controller.ts diff --git a/src/deliveries/delivery.dto.ts b/src/technical and support services/deliveries/delivery.dto.ts similarity index 100% rename from src/deliveries/delivery.dto.ts rename to src/technical and support services/deliveries/delivery.dto.ts diff --git a/src/deliveries/delivery.module.ts b/src/technical and support services/deliveries/delivery.module.ts similarity index 100% rename from src/deliveries/delivery.module.ts rename to src/technical and support services/deliveries/delivery.module.ts diff --git a/src/deliveries/delivery.service.ts b/src/technical and support services/deliveries/delivery.service.ts similarity index 100% rename from src/deliveries/delivery.service.ts rename to src/technical and support services/deliveries/delivery.service.ts diff --git a/src/devices/device.controller.ts b/src/technical and support services/devices/device.controller.ts similarity index 100% rename from src/devices/device.controller.ts rename to src/technical and support services/devices/device.controller.ts diff --git a/src/devices/device.dto.ts b/src/technical and support services/devices/device.dto.ts similarity index 100% rename from src/devices/device.dto.ts rename to src/technical and support services/devices/device.dto.ts diff --git a/src/devices/device.module.ts b/src/technical and support services/devices/device.module.ts similarity index 100% rename from src/devices/device.module.ts rename to src/technical and support services/devices/device.module.ts diff --git a/src/devices/device.service.ts b/src/technical and support services/devices/device.service.ts similarity index 100% rename from src/devices/device.service.ts rename to src/technical and support services/devices/device.service.ts diff --git a/src/fibre/fibre.controller.ts b/src/technical and support services/fibre/fibre.controller.ts similarity index 100% rename from src/fibre/fibre.controller.ts rename to src/technical and support services/fibre/fibre.controller.ts diff --git a/src/fibre/fibre.dto.ts b/src/technical and support services/fibre/fibre.dto.ts similarity index 100% rename from src/fibre/fibre.dto.ts rename to src/technical and support services/fibre/fibre.dto.ts diff --git a/src/fibre/fibre.module.ts b/src/technical and support services/fibre/fibre.module.ts similarity index 100% rename from src/fibre/fibre.module.ts rename to src/technical and support services/fibre/fibre.module.ts diff --git a/src/fibre/fibre.service.ts b/src/technical and support services/fibre/fibre.service.ts similarity index 100% rename from src/fibre/fibre.service.ts rename to src/technical and support services/fibre/fibre.service.ts diff --git a/src/phones/phone.controller.ts b/src/technical and support services/phones/phone.controller.ts similarity index 100% rename from src/phones/phone.controller.ts rename to src/technical and support services/phones/phone.controller.ts diff --git a/src/phones/phone.dto.ts b/src/technical and support services/phones/phone.dto.ts similarity index 100% rename from src/phones/phone.dto.ts rename to src/technical and support services/phones/phone.dto.ts diff --git a/src/phones/phone.module.ts b/src/technical and support services/phones/phone.module.ts similarity index 100% rename from src/phones/phone.module.ts rename to src/technical and support services/phones/phone.module.ts diff --git a/src/phones/phone.service.ts b/src/technical and support services/phones/phone.service.ts similarity index 100% rename from src/phones/phone.service.ts rename to src/technical and support services/phones/phone.service.ts diff --git a/src/product/product.controller.ts b/src/technical and support services/product/product.controller.ts similarity index 100% rename from src/product/product.controller.ts rename to src/technical and support services/product/product.controller.ts diff --git a/src/product/product.dto.ts b/src/technical and support services/product/product.dto.ts similarity index 100% rename from src/product/product.dto.ts rename to src/technical and support services/product/product.dto.ts diff --git a/src/product/product.module.ts b/src/technical and support services/product/product.module.ts similarity index 100% rename from src/product/product.module.ts rename to src/technical and support services/product/product.module.ts diff --git a/src/product/product.service.ts b/src/technical and support services/product/product.service.ts similarity index 100% rename from src/product/product.service.ts rename to src/technical and support services/product/product.service.ts diff --git a/src/staff/staff.controller.ts b/src/technical and support services/staff/staff.controller.ts similarity index 100% rename from src/staff/staff.controller.ts rename to src/technical and support services/staff/staff.controller.ts diff --git a/src/staff/staff.dto.ts b/src/technical and support services/staff/staff.dto.ts similarity index 100% rename from src/staff/staff.dto.ts rename to src/technical and support services/staff/staff.dto.ts diff --git a/src/staff/staff.module.ts b/src/technical and support services/staff/staff.module.ts similarity index 100% rename from src/staff/staff.module.ts rename to src/technical and support services/staff/staff.module.ts diff --git a/src/staff/staff.service.ts b/src/technical and support services/staff/staff.service.ts similarity index 100% rename from src/staff/staff.service.ts rename to src/technical and support services/staff/staff.service.ts diff --git a/src/television/television.controller.ts b/src/technical and support services/television/television.controller.ts similarity index 100% rename from src/television/television.controller.ts rename to src/technical and support services/television/television.controller.ts diff --git a/src/television/television.dto.ts b/src/technical and support services/television/television.dto.ts similarity index 100% rename from src/television/television.dto.ts rename to src/technical and support services/television/television.dto.ts diff --git a/src/television/television.module.ts b/src/technical and support services/television/television.module.ts similarity index 100% rename from src/television/television.module.ts rename to src/technical and support services/television/television.module.ts diff --git a/src/television/television.service.ts b/src/technical and support services/television/television.service.ts similarity index 100% rename from src/television/television.service.ts rename to src/technical and support services/television/television.service.ts diff --git a/src/tickets/ticket.controller.ts b/src/technical and support services/tickets/ticket.controller.ts similarity index 100% rename from src/tickets/ticket.controller.ts rename to src/technical and support services/tickets/ticket.controller.ts diff --git a/src/tickets/ticket.dto.ts b/src/technical and support services/tickets/ticket.dto.ts similarity index 100% rename from src/tickets/ticket.dto.ts rename to src/technical and support services/tickets/ticket.dto.ts diff --git a/src/tickets/ticket.module.ts b/src/technical and support services/tickets/ticket.module.ts similarity index 100% rename from src/tickets/ticket.module.ts rename to src/technical and support services/tickets/ticket.module.ts diff --git a/src/tickets/ticket.service.ts b/src/technical and support services/tickets/ticket.service.ts similarity index 100% rename from src/tickets/ticket.service.ts rename to src/technical and support services/tickets/ticket.service.ts