Unmocked client dashboard page
This commit is contained in:
parent
a086572b14
commit
5ed44992a9
79
src/app/api/customer/CustomersController.ts
Normal file
79
src/app/api/customer/CustomersController.ts
Normal file
@ -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<Customer>(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<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
},
|
||||
};
|
||||
|
@ -36,16 +36,17 @@ export default class AuthService extends BaseService {
|
||||
|
||||
public async getCustomerJwtPayload(email:string): Promise<ICustomerJwtPayload | null> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
35
src/services/customer/CustomersService/CustomersService.ts
Normal file
35
src/services/customer/CustomersService/CustomersService.ts
Normal file
@ -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<Customers[]> {
|
||||
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<Customers | null> {
|
||||
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<Customers | null> {
|
||||
return this.customerRepository.findOneByContact(contactUid);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user