diff --git a/src/app.module.ts b/src/app.module.ts index 4f9ba68..f75b786 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -14,9 +14,11 @@ import { IdentityAndAccountModule } from 'src/identity-and-account/identity-and- import { ChatbotModule } from 'src/chatbot/chatbot.module'; import { PrismaMariadbModule } from 'prisma/mariadb/prisma-mariadb.module'; import { PrismaLegacyModule } from 'prisma/prisma-legacy/prisma-legacy.module'; +import { AccountModule } from 'src/customer-support/accounts/account.module'; @Module({ imports: [ + AccountModule, AuthenticationModule, ConfigModule.forRoot({ isGlobal: true }), ScheduleModule.forRoot(), //cronjobs diff --git a/src/customer-support/account-testing.http b/src/customer-support/account-testing.http new file mode 100644 index 0000000..7ada5af --- /dev/null +++ b/src/customer-support/account-testing.http @@ -0,0 +1,6 @@ +# GET http://localhost:3000/accounts + +# GET http://localhost:3000/accounts/6912 + + +GET http://localhost:3000/accounts/account/6912 \ No newline at end of file diff --git a/src/customer-support/accounts/account.controller.ts b/src/customer-support/accounts/account.controller.ts index d85b8be..0ecfd1d 100644 --- a/src/customer-support/accounts/account.controller.ts +++ b/src/customer-support/accounts/account.controller.ts @@ -1,19 +1,28 @@ import { Controller, Get, Param } from "@nestjs/common"; -import { AccountService } from "src/customer-support/accounts/account.service"; +import { AccountMemoService } from "src/customer-support/accounts/services/account-memo.service"; +import { AccountService } from "src/customer-support/accounts/services/account.service"; -@Controller() +@Controller('accounts') export class AccountController { - constructor(private readonly accountService: AccountService) { } + constructor( + private readonly accountService: AccountService, + private readonly memoService: AccountMemoService, + ) { } @Get() findAllAccounts(){ return this.accountService.findAllAccounts(); } - @Get() + @Get('account/:id') + findAccountById(@Param('accountId') accountId: number){ + return this.accountService.findAccountById(accountId); + } + + @Get(':id') findMemosByAccountId(@Param('accountId') accountId: number) { - return this.accountService.findMemosByAccountId(accountId); + return this.memoService.findMemosByAccountId(accountId); } } \ No newline at end of file diff --git a/src/customer-support/accounts/account.module.ts b/src/customer-support/accounts/account.module.ts index 61d8c37..fa09197 100644 --- a/src/customer-support/accounts/account.module.ts +++ b/src/customer-support/accounts/account.module.ts @@ -1,13 +1,10 @@ import { Module } from "@nestjs/common"; +import { PrismaMariaDbService } from "prisma/mariadb/prisma-mariadb.service"; import { AccountController } from "src/customer-support/accounts/account.controller"; -import { AccountService } from "src/customer-support/accounts/account.service"; +import { AccountService } from "src/customer-support/accounts/services/account.service"; @Module({ - providers: [ - AccountService - ], - controllers: [ - AccountController - ], + controllers: [ AccountController ], + providers: [ AccountService, PrismaMariaDbService ], }) export class AccountModule { }; \ No newline at end of file diff --git a/src/customer-support/accounts/services/account-create.service.ts b/src/customer-support/accounts/services/account-create.service.ts new file mode 100644 index 0000000..75db581 --- /dev/null +++ b/src/customer-support/accounts/services/account-create.service.ts @@ -0,0 +1,6 @@ +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class AccountCreateService { + +} \ No newline at end of file diff --git a/src/customer-support/accounts/services/account-memo-update.service.ts b/src/customer-support/accounts/services/account-memo-update.service.ts new file mode 100644 index 0000000..eae8577 --- /dev/null +++ b/src/customer-support/accounts/services/account-memo-update.service.ts @@ -0,0 +1,6 @@ +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class AccountMemoUpdateService { + +} \ No newline at end of file diff --git a/src/customer-support/accounts/services/account-memo.service.ts b/src/customer-support/accounts/services/account-memo.service.ts new file mode 100644 index 0000000..b247408 --- /dev/null +++ b/src/customer-support/accounts/services/account-memo.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaMariaDbService } from "prisma/mariadb/prisma-mariadb.service"; +import { Result } from "src/common/errors/result-error.factory"; +import { AccountMemo } from "src/customer-support/accounts/account.dto"; + +@Injectable() +export class AccountMemoService { + constructor(private readonly prismaMariaDb: PrismaMariaDbService) { } + + findMemosByAccountId = async (accountId: number): Promise> => { + const listOfMemos: AccountMemo[] = []; + + const rawListOfMemos = await this.prismaMariaDb.account_memo.findMany({ + where: { 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/customer-support/accounts/services/account-update.service.ts b/src/customer-support/accounts/services/account-update.service.ts new file mode 100644 index 0000000..6db2e15 --- /dev/null +++ b/src/customer-support/accounts/services/account-update.service.ts @@ -0,0 +1,56 @@ +// import { Injectable } from "@nestjs/common"; +// import { PrismaMariaDbService } from "prisma/mariadb/prisma-mariadb.service"; +// import { Result } from "src/common/errors/result-error.factory"; +// import { Account } from "src/customer-support/accounts/account.dto"; + +// @Injectable() +// export class AccountUpdateService { +// constructor(private readonly prisma: PrismaMariaDbService) { } + +// async updateAccount(account: Account): Promise> { + +// const oldAccountInfos = await this.prisma.account.findUnique({ +// where: { id: account.id }, +// }); +// if (!oldAccountInfos) return { success: false, error: 'ACCOUNT_NOT_FOUND' }; + +// await this.prisma.account.update({ +// where: { id: oldAccountInfos.id }, +// data: { +// customer_id: account.customerId, +// language_id: account.language, +// username: account.username, +// password: account.password, +// group_id: account.groupId, +// status: account.status, +// first_name: account.firstName, +// last_name: account.lastName, +// mandataire: account.mandataire, +// title: account.title, +// email: account.email, +// company: account.company, +// contact: account.contact, +// address1: account.address, +// address2: account.address, +// tel_home: account.telHome, +// tel_office: account.telOffice, +// tel_office_ext: account.telOffice_ext, +// cell: account.cell, +// fax: account.fax, +// land_owner: account.landOwner, +// commercial: account.commercial, +// vip: account.vip, +// notes_client: account.notes_client, +// terminate_reason: account.terminateReason, +// terminate_cie: account.terminateCie, +// terminate_date: account.terminateDate, +// terminate_note: account.terminateNote, +// mauvais_payeur: account.mauvaisPayeur, +// }, +// }); + + + + +// } +// } \ No newline at end of file diff --git a/src/customer-support/accounts/account.service.ts b/src/customer-support/accounts/services/account.service.ts similarity index 53% rename from src/customer-support/accounts/account.service.ts rename to src/customer-support/accounts/services/account.service.ts index 0554c8f..6019d26 100644 --- a/src/customer-support/accounts/account.service.ts +++ b/src/customer-support/accounts/services/account.service.ts @@ -1,12 +1,12 @@ import { Injectable } from "@nestjs/common"; -import { PrismaClient as MariadbClient } from "prisma/mariadb/generated/prisma/client/mariadb/client"; +import { PrismaMariaDbService } from "prisma/mariadb/prisma-mariadb.service"; import { Result } from "src/common/errors/result-error.factory"; -import { Account, AccountMemo } from "src/customer-support/accounts/account.dto"; +import { Account } from "src/customer-support/accounts/account.dto"; @Injectable() export class AccountService { - constructor(private readonly prismaMariaDb: MariadbClient) { } + constructor(private readonly prismaMariaDb: PrismaMariaDbService) { } findAllAccounts = async (): Promise> => { const listOfAccounts: Account[] = []; @@ -70,22 +70,59 @@ export class AccountService { } } - findMemosByAccountId = async (accountId: number): Promise> => { - const listOfMemos: AccountMemo[] = []; + findAccountById = async (accountId: number): Promise> => { - const rawListOfMemos = await this.prismaMariaDb.account_memo.findMany({ - where: { account_id: accountId }, - select: { last_updated: true, staff_id: true, memo: true }, + const rawAccount = await this.prismaMariaDb.account.findUnique({ + where: { id: accountId } }); - if (!rawListOfMemos) return { success: false, error: 'MEMOS_NOT_FOUND' }; + if (!rawAccount) return { success: false, error: 'ACCOUNT_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 : '', - }); + const emailList: string[] = [ + rawAccount.email ? rawAccount.email : '', + rawAccount.email_autre ? rawAccount.email_autre : '', + ]; + + const addressList: string[] = [ + rawAccount.address1 ? rawAccount.address1 : '', + rawAccount.address2 ? rawAccount.address2 : '', + rawAccount.city ? rawAccount.city : '', + rawAccount.state ? rawAccount.state : '', + rawAccount.zip ? rawAccount.zip : '', + rawAccount.country_id.toString(), + ]; + + const account: Account = { + id: Number(rawAccount.id), + customerId: rawAccount.customer_id ? rawAccount.customer_id : '', + language: rawAccount.language_id, + username: rawAccount.username ? rawAccount.username : '', + password: rawAccount.password ? rawAccount.password : '', + groupId: rawAccount.group_id ? rawAccount.group_id : 0, + status: rawAccount.status ? rawAccount.status : 0, + firstName: rawAccount.first_name ? rawAccount.first_name : '', + lastName: rawAccount.last_name ? rawAccount.last_name : '', + mandataire: rawAccount.mandataire ? rawAccount.mandataire : '', + title: rawAccount.title ? rawAccount.title : '', + email: emailList, + company: rawAccount.company ? rawAccount.company : '', + contact: rawAccount.contact, + address: addressList, + telHome: rawAccount.tel_home ? rawAccount.tel_home : '', + telOffice: rawAccount.tel_office ? rawAccount.tel_office : '', + telOffice_ext: rawAccount.tel_office_ext ? rawAccount.tel_office_ext : '', + cell: rawAccount.cell ? rawAccount.cell : '', + fax: rawAccount.fax ? rawAccount.fax : '', + landOwner: rawAccount.land_owner, + commercial: rawAccount.commercial, + vip: rawAccount.vip, + notes_client: rawAccount.notes_client ? rawAccount.notes_client : '', + terminateReason: rawAccount.terminate_reason ? rawAccount.terminate_reason : '', + terminateCie: rawAccount.terminate_cie ? rawAccount.terminate_cie : '', + terminateNote: rawAccount.terminate_note ? rawAccount.terminate_note : '', + terminateDate: rawAccount.terminate_date ? rawAccount.terminate_date : '', + mauvaisPayeur: rawAccount.mauvais_payeur, } - return { success: true, data: listOfMemos } + + return { success: true, data: account }; } } diff --git a/src/main.ts b/src/main.ts index f73a72d..434e5d8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,20 +6,11 @@ if (!(globalThis as any).crypto) { import { ensureAttachmentsTmpDir } from './time-and-attendance/attachments/config/attachment.fs'; import { NestFactory, Reflector } from '@nestjs/core'; import { AppModule } from './app.module'; -// import { JwtAuthGuard } from './modules/authentication/guards/jwt-auth.guard'; import { ModulesGuard } from './common/guards/modules.guard'; -// import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -// import { writeFileSync } from 'fs'; import * as session from 'express-session'; import * as passport from 'passport'; import { PrismaSessionStore } from '@quixo3/prisma-session-store'; import { PrismaPostgresService } from 'prisma/postgres/prisma-postgres.service'; -// import { initSupervisor } from 'scripts/init-supervisor'; -// import { initializePaidTimeOff } from 'scripts/init-paid-time-off'; -// import { initializePreferences } from 'scripts/init-preferences-access'; -// import { extractOldTimesheets } from 'scripts/migrate-timesheets'; -// import { extractOldShifts } from 'scripts/migrate-shifts'; -// import { extractOldExpenses } from 'scripts/migrate-expenses'; const SESSION_TOKEN_DURATION_MINUTES = 180 @@ -30,7 +21,6 @@ async function bootstrap() { const reflector = app.get(Reflector); app.useGlobalGuards( - // new JwtAuthGuard(reflector), //Authentification JWT new ModulesGuard(reflector), //deny-by-default and Module-based Access Control ); @@ -60,36 +50,6 @@ async function bootstrap() { credentials: true, }); - // //swagger config - // const config = new DocumentBuilder() - // .setTitle('Targo_Backend') - // .setDescription('Documentation de l`API REST pour Targo (NestJS + Prisma)') - // .setVersion('1.0') - // .addBearerAuth({ - // type: 'http', - // scheme: 'bearer', - // bearerFormat: 'JWT', - // name: 'Authorization', - // description: 'Invalid JWT token', - // in: 'header', - // }, 'access-token') - // .addTag('Users') - // .addTag('Employees') - // .addTag('Customers') - // .addTag('Timesheets') - // .addTag('Shifts') - // .addTag('Leave Requests') - // .addTag('Shift Codes') - // .addTag('OAuth Access Tokens') - // .addTag('Authorization') - // .build(); - - // //document builder for swagger docs - // const documentFactory = () => SwaggerModule.createDocument(app, config); - // const document = documentFactory() - // SwaggerModule.setup('api/docs', app, document); - // writeFileSync('./docs/swagger/swagger-spec.json', JSON.stringify(document, null, 2)); - await ensureAttachmentsTmpDir(); await app.listen(process.env.PORT ?? 3000);