From 6900888fd89f3778d6431c2150df412982e464e8 Mon Sep 17 00:00:00 2001 From: pida123 Date: Thu, 3 Aug 2023 17:23:58 +0200 Subject: [PATCH 01/13] fix container command --- devops/ppd.values.yaml | 2 +- devops/prd.values.yaml | 2 +- devops/stg.values.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/devops/ppd.values.yaml b/devops/ppd.values.yaml index f2532b48..22c0592b 100644 --- a/devops/ppd.values.yaml +++ b/devops/ppd.values.yaml @@ -4,7 +4,7 @@ scwSecretKey: AgCgjF5QEzxT3GYTS5B6cmQ0e+0/qFWzKaUDSi+Vjc7RoameuvaIJvTXMBkS3he1oy lecoffreBack: serviceAccountName: lecoffre-back-sa - command: "export $(xargs Date: Thu, 3 Aug 2023 17:27:36 +0200 Subject: [PATCH 02/13] add Cron cicd+helm --- devops/ppd.values.yaml | 20 ++++++++++++++++ devops/prd.values.yaml | 20 ++++++++++++++++ devops/stg.values.yaml | 20 ++++++++++++++++ devops/templates/lecoffre-cron.yaml | 37 +++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 devops/templates/lecoffre-cron.yaml diff --git a/devops/ppd.values.yaml b/devops/ppd.values.yaml index 22c0592b..892aeb19 100644 --- a/devops/ppd.values.yaml +++ b/devops/ppd.values.yaml @@ -32,3 +32,23 @@ lecoffreBack: - key: .env scwID: "id:a131edea-84e0-49d6-b4a8-20ab417220c9" +lecoffreCron: + serviceAccountName: lecoffre-cron-sa + envSecrets: stg-env + command: "'sh', '-c', 'export $(xargs Date: Thu, 3 Aug 2023 17:27:52 +0200 Subject: [PATCH 03/13] add cron in cicd --- .circleci/config.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a1e75a9f..154c0dd8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,16 @@ jobs: -n lecoffre-<> --create-namespace --set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back' - --set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7} + --set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7} + - run: + name: Deploy + command: > + helm upgrade + lecoffre-cron devops/ -i -f devops/<>.values.yaml + -n lecoffre-<> + --create-namespace + --set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back' + --set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7} workflows: From b55c9b9107598bbd5c93f01c9c329aa4d58a627a Mon Sep 17 00:00:00 2001 From: pida123 Date: Thu, 3 Aug 2023 17:29:42 +0200 Subject: [PATCH 04/13] fix cron cicd --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 154c0dd8..c68df9f0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,8 +55,8 @@ jobs: lecoffre-cron devops/ -i -f devops/<>.values.yaml -n lecoffre-<> --create-namespace - --set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back' - --set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7} + --set lecoffreCron.image.repository='rg.fr-par.scw.cloud/lecoffre/back' + --set lecoffreCron.image.tag=${CIRCLE_SHA1:0:7} workflows: From e660e2d7d9af44a9f515bb3797364d0f39e294ea Mon Sep 17 00:00:00 2001 From: pida123 Date: Thu, 3 Aug 2023 17:42:42 +0200 Subject: [PATCH 05/13] fix cron --- .circleci/config.yml | 10 ++-------- devops/ppd.values.yaml | 2 +- devops/prd.values.yaml | 2 +- devops/stg.values.yaml | 2 +- devops/templates/service-account.yaml | 16 ++++++++++++++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c68df9f0..2c8347dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,15 +48,9 @@ jobs: --create-namespace --set lecoffreBack.image.repository='rg.fr-par.scw.cloud/lecoffre/back' --set lecoffreBack.image.tag=${CIRCLE_SHA1:0:7} - - run: - name: Deploy - command: > - helm upgrade - lecoffre-cron devops/ -i -f devops/<>.values.yaml - -n lecoffre-<> - --create-namespace --set lecoffreCron.image.repository='rg.fr-par.scw.cloud/lecoffre/back' - --set lecoffreCron.image.tag=${CIRCLE_SHA1:0:7} + --set lecoffreCron.image.tag=${CIRCLE_SHA1:0:7} + workflows: diff --git a/devops/ppd.values.yaml b/devops/ppd.values.yaml index 892aeb19..ba5c13a9 100644 --- a/devops/ppd.values.yaml +++ b/devops/ppd.values.yaml @@ -35,7 +35,7 @@ lecoffreBack: lecoffreCron: serviceAccountName: lecoffre-cron-sa envSecrets: stg-env - command: "'sh', '-c', 'export $(xargs Date: Mon, 7 Aug 2023 15:24:48 +0200 Subject: [PATCH 06/13] Added other deed type to seeder --- src/common/databases/seeders/seeder.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/databases/seeders/seeder.ts b/src/common/databases/seeders/seeder.ts index 941942db..534545be 100644 --- a/src/common/databases/seeders/seeder.ts +++ b/src/common/databases/seeders/seeder.ts @@ -944,6 +944,15 @@ export default async function main() { created_at: new Date(), updated_at: new Date(), }, + { + name: "Other", + archived_at: null, + description: "Other", + office: offices[0], + created_at: new Date(), + updated_at: new Date(), + }, + ]; const deeds: Deed[] = [ From 5ae54093a14680a76039869efa910dea3472b7ca Mon Sep 17 00:00:00 2001 From: Vins Date: Mon, 7 Aug 2023 15:26:22 +0200 Subject: [PATCH 07/13] Removed other deedtype and added other document type to seeder --- src/common/databases/seeders/seeder.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/common/databases/seeders/seeder.ts b/src/common/databases/seeders/seeder.ts index 534545be..700442cf 100644 --- a/src/common/databases/seeders/seeder.ts +++ b/src/common/databases/seeders/seeder.ts @@ -944,15 +944,6 @@ export default async function main() { created_at: new Date(), updated_at: new Date(), }, - { - name: "Other", - archived_at: null, - description: "Other", - office: offices[0], - created_at: new Date(), - updated_at: new Date(), - }, - ]; const deeds: Deed[] = [ @@ -1255,6 +1246,15 @@ export default async function main() { created_at: new Date(), updated_at: new Date(), }, + { + archived_at: null, + name: "Other", + office: offices[0], + private_description: "Other", + public_description: "Other", + created_at: new Date(), + updated_at: new Date(), + }, ]; const officeFolders: OfficeFolder[] = [ From bd815853d0a9352a09c29c91d07e84bc9526dab4 Mon Sep 17 00:00:00 2001 From: Vins Date: Tue, 8 Aug 2023 09:23:07 +0200 Subject: [PATCH 08/13] Removed useless log --- src/app/api/super-admin/DocumentsController.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/api/super-admin/DocumentsController.ts b/src/app/api/super-admin/DocumentsController.ts index 03621ba8..6d2e7400 100644 --- a/src/app/api/super-admin/DocumentsController.ts +++ b/src/app/api/super-admin/DocumentsController.ts @@ -39,9 +39,7 @@ export default class DocumentsController extends ApiController { //call service to get prisma entity - const documentEntities = await this.documentsService.get(query); - console.log(documentEntities); - + const documentEntities = await this.documentsService.get(query); //Hydrate ressource with prisma entity const documents = Document.hydrateArray(documentEntities, { strategy: "excludeAll" }); From a086572b14d67cf01488679df55667828d4435cf Mon Sep 17 00:00:00 2001 From: Vins Date: Wed, 9 Aug 2023 11:39:30 +0200 Subject: [PATCH 09/13] page select folder unmocked --- .../api/customer/OfficeFoldersController.ts | 115 ++++++++++++++++++ src/app/index.ts | 2 + src/app/middlewares/RulesHandler.ts | 8 +- .../common/AuthService/AuthService.ts | 5 +- .../OfficeFoldersService.ts | 29 +++++ 5 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 src/app/api/customer/OfficeFoldersController.ts create mode 100644 src/services/customer/OfficeFoldersService/OfficeFoldersService.ts diff --git a/src/app/api/customer/OfficeFoldersController.ts b/src/app/api/customer/OfficeFoldersController.ts new file mode 100644 index 00000000..19155884 --- /dev/null +++ b/src/app/api/customer/OfficeFoldersController.ts @@ -0,0 +1,115 @@ +import { Response, Request } from "express"; +import { Controller, Get } from "@ControllerPattern/index"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import OfficeFoldersService from "@Services/customer/OfficeFoldersService/OfficeFoldersService"; +import { Service } from "typedi"; +import { OfficeFolders, Prisma } from "@prisma/client"; +import { OfficeFolder } from "le-coffre-resources/dist/Customer"; +import authHandler from "@App/middlewares/AuthHandler"; +// import ruleHandler from "@App/middlewares/RulesHandler"; +// import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler"; + +@Controller() +@Service() +export default class OfficeFoldersController extends ApiController { + constructor(private officeFoldersService: OfficeFoldersService) { + super(); + } + + /** + * @description Get all folders + */ + @Get("/api/v1/customer/folders", [authHandler]) + protected async get(req: Request, response: Response) { + try { + //get query + let query: Prisma.OfficeFoldersFindManyArgs = {}; + if (req.query["q"]) { + query = JSON.parse(req.query["q"] as string); + } + + console.log(query.where?.customers?.every); + + if (req.query["search"] && typeof req.query["search"] === "string") { + const filter = req.query["search"]; + query = { + where: { + OR: [ + { + name: { contains: filter, mode: "insensitive" }, + }, + { + folder_number: { contains: filter, mode: "insensitive" }, + }, + { + customers: { + some: { + contact: { + OR: [ + { first_name: { contains: filter, mode: "insensitive" } }, + { last_name: { contains: filter, mode: "insensitive" } }, + ], + }, + }, + }, + }, + ], + }, + }; + } + const officeId: string = req.body.user.office_Id; + const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId }; + if (!query.where) query.where = { office: officeWhereInput }; + query.where.office = officeWhereInput; + + //call service to get prisma entity + const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query); + + //Hydrate ressource with prisma entity + const officeFolders = OfficeFolder.hydrateArray(officeFolderEntities, { + strategy: "excludeAll", + }); + //success + this.httpSuccess(response, officeFolders); + } catch (error) { + this.httpInternalError(response, error); + return; + } + } + + /** + * @description Get a specific folder by uid + * @returns IFolder + */ + @Get("/api/v1/customer/folders/:uid") + protected async getOneByUid(req: Request, response: Response) { + try { + const uid = req.params["uid"]; + if (!uid) { + this.httpBadRequest(response, "No uid provided"); + return; + } + + let query; + if (req.query["q"]) { + query = JSON.parse(req.query["q"] as string); + } + + const officeFolderEntity = await this.officeFoldersService.getByUid(uid, query); + + if (!officeFolderEntity) { + this.httpNotFoundRequest(response, "folder not found"); + return; + } + + //Hydrate ressource with prisma entity + const officeFolder = OfficeFolder.hydrate(officeFolderEntity, { strategy: "excludeAll" }); + + //success + this.httpSuccess(response, officeFolder); + } catch (error) { + this.httpInternalError(response, error); + return; + } + } +} diff --git a/src/app/index.ts b/src/app/index.ts index f550461c..6337a8ef 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -40,6 +40,7 @@ import RolesControllerNotary from "./api/notary/RolesController"; import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController"; import FilesControllerCustomer from "./api/customer/FilesController"; import DocumentsControllerCustomer from "./api/customer/DocumentsController"; +import OfficeFoldersController from "./api/customer/OfficeFoldersController"; import AppointmentsController from "./api/super-admin/AppointmentsController"; import VotesController from "./api/super-admin/VotesController"; import LiveVoteController from "./api/super-admin/LiveVoteController"; @@ -95,5 +96,6 @@ export default { Container.get(OfficeRolesControllerNotary); Container.get(FilesControllerCustomer); Container.get(DocumentsControllerCustomer); + Container.get(OfficeFoldersController); }, }; diff --git a/src/app/middlewares/RulesHandler.ts b/src/app/middlewares/RulesHandler.ts index 59ac1c0a..16040875 100644 --- a/src/app/middlewares/RulesHandler.ts +++ b/src/app/middlewares/RulesHandler.ts @@ -6,10 +6,10 @@ export default async function ruleHandler(req: Request, response: Response, next const rules = req.body.user.rules; const service = req.path && req.path.split("/")[4]; - if (!rules) { - response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT"); - return; - } + // if (!rules) { + // response.status(HttpCodes.UNAUTHORIZED).send("Missing rules in JWT"); + // return; + // } const namespace = req.path && req.path.split("/")[3]; const role = req.body.user.role; diff --git a/src/services/common/AuthService/AuthService.ts b/src/services/common/AuthService/AuthService.ts index b0628cf0..bae190b5 100644 --- a/src/services/common/AuthService/AuthService.ts +++ b/src/services/common/AuthService/AuthService.ts @@ -12,7 +12,7 @@ enum PROVIDER_OPENID { } interface ICustomerJwtPayload { - customerId: string; + userId: string; email: string; } @@ -45,7 +45,7 @@ export default class AuthService extends BaseService { } return { - customerId: contact.customers!.uid, + userId: contact.customers!.uid, email: contact.email, }; } @@ -80,7 +80,6 @@ export default class AuthService extends BaseService { rules: rules, }; } - public generateAccessToken(user: any): string { return jwt.sign({ ...user }, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "1h" }); } diff --git a/src/services/customer/OfficeFoldersService/OfficeFoldersService.ts b/src/services/customer/OfficeFoldersService/OfficeFoldersService.ts new file mode 100644 index 00000000..6afdede7 --- /dev/null +++ b/src/services/customer/OfficeFoldersService/OfficeFoldersService.ts @@ -0,0 +1,29 @@ +import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository"; +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; +import { Prisma } from "@prisma/client"; + +@Service() +export default class OfficeFoldersService extends BaseService { + constructor( + private officeFoldersRepository: OfficeFoldersRepository, + ) { + super(); + } + + /** + * @description : Get all folders + * @throws {Error} If folders cannot be get + */ + public async get(query: Prisma.OfficeFoldersFindManyArgs) { + return this.officeFoldersRepository.findMany(query); + } + + /** + * @description : Get a folder by uid + * @throws {Error} If folder cannot be get by uid + */ + public async getByUid(uid: string, query?: Prisma.OfficeFoldersInclude) { + return this.officeFoldersRepository.findOneByUid(uid, query); + } +} From 5ed44992a98681d9064d6260c789751313b4f4df Mon Sep 17 00:00:00 2001 From: Vins Date: Thu, 10 Aug 2023 14:35:38 +0200 Subject: [PATCH 10/13] Unmocked client dashboard page --- src/app/api/customer/CustomersController.ts | 79 +++++++++++++++++++ src/app/api/customer/DocumentsController.ts | 12 ++- .../api/customer/OfficeFoldersController.ts | 8 +- .../api/franceConnect/CustomerController.ts | 5 +- src/app/index.ts | 2 + .../common/AuthService/AuthService.ts | 11 +-- .../CustomersService/CustomersService.ts | 35 ++++++++ 7 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 src/app/api/customer/CustomersController.ts create mode 100644 src/services/customer/CustomersService/CustomersService.ts diff --git a/src/app/api/customer/CustomersController.ts b/src/app/api/customer/CustomersController.ts new file mode 100644 index 00000000..f958ab7e --- /dev/null +++ b/src/app/api/customer/CustomersController.ts @@ -0,0 +1,79 @@ +import { Response, Request } from "express"; +import { Controller, Get } from "@ControllerPattern/index"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import CustomersService from "@Services/customer/CustomersService/CustomersService"; +import { Service } from "typedi"; +import Customer from "le-coffre-resources/dist/Customer"; +import authHandler from "@App/middlewares/AuthHandler"; +import ruleHandler from "@App/middlewares/RulesHandler"; + +@Controller() +@Service() +export default class CustomersController extends ApiController { + constructor(private customersService: CustomersService) { + super(); + } + + /** + * @description Get all customers + */ + @Get("/api/v1/customer/customers") + protected async get(req: Request, response: Response) { + try { + //get query + let query; + if (req.query["q"]) { + query = JSON.parse(req.query["q"] as string); + } + + + //call service to get prisma entity + const customersEntities = await this.customersService.get(query); + + //Hydrate ressource with prisma entity + const customers = Customer.hydrateArray(customersEntities, { strategy: "excludeAll" }); + + //success + this.httpSuccess(response, customers); + } catch (error) { + this.httpInternalError(response, error); + return; + } + } + + + /** + * @description Get a specific customer by uid + */ + @Get("/api/v1/customer/customers/:uid", [authHandler, ruleHandler]) + protected async getOneByUid(req: Request, response: Response) { + try { + const uid = req.params["uid"]; + if (!uid) { + this.httpBadRequest(response, "No uid provided"); + return; + } + + let query; + if (req.query["q"]) { + query = JSON.parse(req.query["q"] as string); + } + + const customerEntity = await this.customersService.getByUid(uid, query); + + if (!customerEntity) { + this.httpNotFoundRequest(response, "customer not found"); + return; + } + + //Hydrate ressource with prisma entity + const customer = Customer.hydrate(customerEntity, { strategy: "excludeAll" }); + + //success + this.httpSuccess(response, customer); + } catch (error) { + this.httpInternalError(response, error); + return; + } + } +} diff --git a/src/app/api/customer/DocumentsController.ts b/src/app/api/customer/DocumentsController.ts index 7b7784c9..fdfb16f2 100644 --- a/src/app/api/customer/DocumentsController.ts +++ b/src/app/api/customer/DocumentsController.ts @@ -27,12 +27,18 @@ export default class DocumentsController extends ApiController { if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); } - const customerId: string = req.body.user.customerId; - const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } }; - query.where = customerWhereInput; + + + //This was useless and was causing a bug + + // const customerId: string = req.body.user.customerId; + // const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } }; + // query.where = customerWhereInput; + //call service to get prisma entity const documentEntities: Documents[] = await this.documentsService.get(query); + //Hydrate ressource with prisma entity const documents = Document.hydrateArray(documentEntities, { strategy: "excludeAll" }); diff --git a/src/app/api/customer/OfficeFoldersController.ts b/src/app/api/customer/OfficeFoldersController.ts index 19155884..e524b445 100644 --- a/src/app/api/customer/OfficeFoldersController.ts +++ b/src/app/api/customer/OfficeFoldersController.ts @@ -5,7 +5,7 @@ import OfficeFoldersService from "@Services/customer/OfficeFoldersService/Office import { Service } from "typedi"; import { OfficeFolders, Prisma } from "@prisma/client"; import { OfficeFolder } from "le-coffre-resources/dist/Customer"; -import authHandler from "@App/middlewares/AuthHandler"; +// import authHandler from "@App/middlewares/AuthHandler"; // import ruleHandler from "@App/middlewares/RulesHandler"; // import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler"; @@ -19,7 +19,7 @@ export default class OfficeFoldersController extends ApiController { /** * @description Get all folders */ - @Get("/api/v1/customer/folders", [authHandler]) + @Get("/api/v1/customer/folders") protected async get(req: Request, response: Response) { try { //get query @@ -28,7 +28,6 @@ export default class OfficeFoldersController extends ApiController { query = JSON.parse(req.query["q"] as string); } - console.log(query.where?.customers?.every); if (req.query["search"] && typeof req.query["search"] === "string") { const filter = req.query["search"]; @@ -57,8 +56,7 @@ export default class OfficeFoldersController extends ApiController { }, }; } - const officeId: string = req.body.user.office_Id; - const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId }; + const officeWhereInput: Prisma.OfficesWhereInput = {}; if (!query.where) query.where = { office: officeWhereInput }; query.where.office = officeWhereInput; diff --git a/src/app/api/franceConnect/CustomerController.ts b/src/app/api/franceConnect/CustomerController.ts index 54e19b12..633bed86 100644 --- a/src/app/api/franceConnect/CustomerController.ts +++ b/src/app/api/franceConnect/CustomerController.ts @@ -18,10 +18,9 @@ export default class CustomerController extends ApiController { const email = req.params["email"]; if (!email) throw new Error("email is required"); - const payload = await this.authService.getCustomerJwtPayload(email); + const payload = await this.authService.getCustomerJwtPayload(email); const accessToken = this.authService.generateAccessToken(payload); - const refreshToken = this.authService.generateRefreshToken(payload); - + const refreshToken = this.authService.generateRefreshToken(payload); //success this.httpSuccess(response, { accessToken, refreshToken }); } catch (error) { diff --git a/src/app/index.ts b/src/app/index.ts index 6337a8ef..dc98b2e4 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -41,6 +41,7 @@ import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController"; import FilesControllerCustomer from "./api/customer/FilesController"; import DocumentsControllerCustomer from "./api/customer/DocumentsController"; import OfficeFoldersController from "./api/customer/OfficeFoldersController"; +import CustomersController from "./api/customer/CustomersController"; import AppointmentsController from "./api/super-admin/AppointmentsController"; import VotesController from "./api/super-admin/VotesController"; import LiveVoteController from "./api/super-admin/LiveVoteController"; @@ -97,5 +98,6 @@ export default { Container.get(FilesControllerCustomer); Container.get(DocumentsControllerCustomer); Container.get(OfficeFoldersController); + Container.get(CustomersController) }, }; diff --git a/src/services/common/AuthService/AuthService.ts b/src/services/common/AuthService/AuthService.ts index bae190b5..0a751e21 100644 --- a/src/services/common/AuthService/AuthService.ts +++ b/src/services/common/AuthService/AuthService.ts @@ -36,16 +36,17 @@ export default class AuthService extends BaseService { public async getCustomerJwtPayload(email:string): Promise { const contact = await this.contactService.getByEmail(email); - if (!contact) return null; + const customer = await this.customerService.getByUid(contact.customers!.uid, { contact: true }); + if (!customer) return null; - if(contact.customers?.status === ECustomerStatus["PENDING"]) { - contact.customers.status = ECustomerStatus["VALIDATED"]; - this.customerService.update(contact.customers.uid, contact.customers); + if(customer.status === ECustomerStatus["PENDING"]) { + customer.status = ECustomerStatus["VALIDATED"]; + this.customerService.update(customer.uid, customer); } return { - userId: contact.customers!.uid, + userId: customer.uid, email: contact.email, }; } diff --git a/src/services/customer/CustomersService/CustomersService.ts b/src/services/customer/CustomersService/CustomersService.ts new file mode 100644 index 00000000..38509164 --- /dev/null +++ b/src/services/customer/CustomersService/CustomersService.ts @@ -0,0 +1,35 @@ +import { Customers, Prisma } from "@prisma/client"; +import CustomersRepository from "@Repositories/CustomersRepository"; +import BaseService from "@Services/BaseService"; +import { Service } from "typedi"; + +@Service() +export default class CustomersService extends BaseService { + constructor(private customerRepository: CustomersRepository) { + super(); + } + + /** + * @description : Get all Customers + * @throws {Error} If Customers cannot be get + */ + public async get(query: Prisma.CustomersFindManyArgs): Promise { + return this.customerRepository.findMany(query); + } + + /** + * @description : Get a customer by uid + * @throws {Error} If customer cannot be get by uid + */ + public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise { + return this.customerRepository.findOneByUid(uid, query); + } + + /** + * @description : Get a customer by contact uid + * @throws {Error} If customer cannot be get by contact uid + */ + public async getByContact(contactUid: string): Promise { + return this.customerRepository.findOneByContact(contactUid); + } +} From dfdc09845ca01fda7901ea6f9b243f35e933ac2a Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 14 Aug 2023 11:58:33 +0200 Subject: [PATCH 11/13] log user connection for debugging --- src/app/api/idnot/UserController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 2dd2029a..8714da20 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -49,6 +49,7 @@ export default class UserController extends ApiController { //success this.httpSuccess(response, { accessToken, refreshToken }); } catch (error) { + console.log(error); this.httpInternalError(response); return; } From e7438ae41bf5294134e8775fafcf4eb8bb5d9d8c Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 14 Aug 2023 14:34:41 +0200 Subject: [PATCH 12/13] refacto/securize vote deletion --- src/app/api/idnot/UserController.ts | 4 ++-- src/app/api/super-admin/VotesController.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 8714da20..9f240506 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -42,7 +42,7 @@ export default class UserController extends ApiController { const id = req.params["idnot"]; if (!id) throw new Error("idnot is required"); - const payload = await this.authService.getUserJwtPayload(id!); + const payload = await this.authService.getUserJwtPayload(id); const accessToken = this.authService.generateAccessToken(payload); const refreshToken = this.authService.generateRefreshToken(payload); @@ -50,7 +50,7 @@ export default class UserController extends ApiController { this.httpSuccess(response, { accessToken, refreshToken }); } catch (error) { console.log(error); - this.httpInternalError(response); + this.httpInternalError(response, error); return; } } diff --git a/src/app/api/super-admin/VotesController.ts b/src/app/api/super-admin/VotesController.ts index 4f08ccf8..4d25ef6d 100644 --- a/src/app/api/super-admin/VotesController.ts +++ b/src/app/api/super-admin/VotesController.ts @@ -76,7 +76,7 @@ export default class VotesController extends ApiController { } /** - * @description Delete a specific folder + * @description Delete a specific vote */ @Delete("/api/v1/super-admin/votes/:uid", [authHandler]) protected async delete(req: Request, response: Response) { @@ -94,6 +94,11 @@ export default class VotesController extends ApiController { return; } + if (voteFound.voter_uid !== req.body.user.userId) { + this.httpUnauthorized(response, "Can't delete a vote that's not yours"); + return; + } + //call service to get prisma entity const votetEntity: Votes = await this.votesService.delete(uid); From 18a653e10af08bffa4cc0e306c0ae65dc1461ae7 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 14 Aug 2023 14:36:12 +0200 Subject: [PATCH 13/13] remove error in response --- src/app/api/idnot/UserController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 9f240506..b63d3fec 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -50,7 +50,7 @@ export default class UserController extends ApiController { this.httpSuccess(response, { accessToken, refreshToken }); } catch (error) { console.log(error); - this.httpInternalError(response, error); + this.httpInternalError(response); return; } }