feat(accounts): controller, service, module and dtos implemented. 2 basics functions are implemented for testing routes
This commit is contained in:
parent
c357f4bdaa
commit
0b81325575
|
|
@ -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';
|
||||
};
|
||||
4
src/common/errors/result-error.factory.ts
Normal file
4
src/common/errors/result-error.factory.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export type Result<T, E> =
|
||||
| { success: true; data: T }
|
||||
| { success: false; error: E };
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
37
src/technical and support services/accounts/account.dto.ts
Normal file
37
src/technical and support services/accounts/account.dto.ts
Normal file
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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 { };
|
||||
|
|
@ -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<Result<Account[], string>> => {
|
||||
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<Result<AccountMemo[], string>> => {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user