remove customers calls for customer namespace
This commit is contained in:
parent
7bba9ce8c3
commit
db97b00078
@ -1,67 +0,0 @@
|
||||
import Customer, { Contact } from "le-coffre-resources/dist/Customer";
|
||||
|
||||
import BaseCustomer from "../BaseCustomer";
|
||||
import { ECivility } from "le-coffre-resources/dist/Customer/Contact";
|
||||
|
||||
// TODO Type get query params -> Where + inclue + orderby
|
||||
export interface IGetCustomersparams {
|
||||
where?: {};
|
||||
include?: {};
|
||||
}
|
||||
|
||||
// TODO Type getbyuid query params
|
||||
|
||||
export type IPutCustomersParams = {
|
||||
uid?: Customer["uid"];
|
||||
contact?: Customer["contact"];
|
||||
};
|
||||
|
||||
export interface IPostCustomersParams {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
cell_phone_number: string;
|
||||
civility: ECivility;
|
||||
address?: Contact["address"];
|
||||
}
|
||||
|
||||
export default class Customers extends BaseCustomer {
|
||||
private static instance: Customers;
|
||||
private readonly baseURl = this.namespaceUrl.concat("/customers");
|
||||
|
||||
private constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this.instance) {
|
||||
return new this();
|
||||
} else {
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
public async get(q: IGetCustomersparams): Promise<Customer[]> {
|
||||
const url = new URL(this.baseURl);
|
||||
const query = { q };
|
||||
Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<Customer[]>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
public async getByUid(uid: string, q?: any): Promise<Customer> {
|
||||
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||
const query = { q };
|
||||
if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value)));
|
||||
try {
|
||||
return await this.getRequest<Customer>(url);
|
||||
} catch (err) {
|
||||
this.onError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
"use client";
|
||||
import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
||||
import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents";
|
||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
||||
@ -10,7 +9,7 @@ import React, { useCallback, useEffect, useState } from "react";
|
||||
|
||||
import classes from "./classes.module.scss";
|
||||
import { useRouter } from "next/router";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
import JwtService, { ICustomerJwtPayload } from "@Front/Services/JwtService/JwtService";
|
||||
import DepositOtherDocument from "@Front/Components/DesignSystem/DepositOtherDocument";
|
||||
import Folders from "@Front/Api/LeCoffreApi/Customer/Folders/Folders";
|
||||
|
||||
@ -25,15 +24,15 @@ export default function ClientDashboard(props: IProps) {
|
||||
const [isAddDocumentModalVisible, setIsAddDocumentModalVisible] = useState<boolean>(false);
|
||||
|
||||
const getDocuments = useCallback(async () => {
|
||||
let jwt;
|
||||
let jwt: ICustomerJwtPayload | undefined;;
|
||||
if (typeof document !== "undefined") {
|
||||
jwt = JwtService.getInstance().decodeJwt();
|
||||
jwt = JwtService.getInstance().decodeCustomerJwt();
|
||||
}
|
||||
if (!jwt || !jwt.email) return;
|
||||
const customers = await Customers.getInstance().get({
|
||||
where: { contact: { email: jwt.email }, office_folders: { some: { uid: folderUid } } },
|
||||
});
|
||||
const actualCustomer: Customer = customers[0]!;
|
||||
|
||||
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } });
|
||||
|
||||
const actualCustomer = folder?.customers?.find((customer) => customer.uid === jwt?.customerId);
|
||||
if(!actualCustomer) throw new Error("Customer not found");
|
||||
|
||||
const query: IGetDocumentsparams = {
|
||||
where: { depositor: { uid: actualCustomer.uid }, folder_uid: folderUid as string },
|
||||
@ -47,7 +46,8 @@ export default function ClientDashboard(props: IProps) {
|
||||
|
||||
const documentList = await Documents.getInstance().get(query);
|
||||
|
||||
const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true } });
|
||||
//const folder = await Folders.getInstance().getByUid(folderUid as string, { q: { office: true, customers: true } });
|
||||
|
||||
setFolder(folder);
|
||||
setDocuments(documentList);
|
||||
setCustomer(actualCustomer);
|
||||
|
@ -1,5 +1,4 @@
|
||||
import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
||||
import Documents, { IGetDocumentsparams } from "@Front/Api/LeCoffreApi/Customer/Documents/Documents";
|
||||
//import Customers from "@Front/Api/LeCoffreApi/Customer/Customers/Customers";
|
||||
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
|
||||
import DepositDocument from "@Front/Components/DesignSystem/DepositDocument";
|
||||
import TextField from "@Front/Components/DesignSystem/Form/TextField";
|
||||
@ -11,7 +10,6 @@ import Customer, { Document, DocumentType } from "le-coffre-resources/dist/Custo
|
||||
import React from "react";
|
||||
|
||||
import classes from "./classes.module.scss";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
|
||||
type IProps = {};
|
||||
type IState = {
|
||||
@ -109,27 +107,27 @@ export default class ClientDashboard extends Base<IProps, IState> {
|
||||
);
|
||||
}
|
||||
|
||||
public override async componentDidMount() {
|
||||
// TODO Get documents of the current customer according to userStore
|
||||
// REMOVE this mock
|
||||
// public override async componentDidMount() {
|
||||
// // TODO Get documents of the current customer according to userStore
|
||||
// // REMOVE this mock
|
||||
|
||||
const jwt = JwtService.getInstance().decodeJwt();
|
||||
const mockedCustomers = await Customers.getInstance().get({
|
||||
where: { contact: { email: jwt?.email } },
|
||||
});
|
||||
const mockedCustomer: Customer = mockedCustomers[0]!;
|
||||
// const jwt = JwtService.getInstance().decodeJwt();
|
||||
// const mockedCustomers = await Customers.getInstance().get({
|
||||
// where: { contact: { email: jwt?.email } },
|
||||
// });
|
||||
// const mockedCustomer: Customer = mockedCustomers[0]!;
|
||||
|
||||
const query: IGetDocumentsparams = {
|
||||
where: { depositor: { uid: mockedCustomer.uid } },
|
||||
include: {
|
||||
files: true,
|
||||
document_history: true,
|
||||
document_type: true,
|
||||
},
|
||||
};
|
||||
const documents: Document[] = await Documents.getInstance().get(query);
|
||||
this.setState({ documents, mockedCustomer });
|
||||
}
|
||||
// const query: IGetDocumentsparams = {
|
||||
// where: { depositor: { uid: mockedCustomer.uid } },
|
||||
// include: {
|
||||
// files: true,
|
||||
// document_history: true,
|
||||
// document_type: true,
|
||||
// },
|
||||
// };
|
||||
// const documents: Document[] = await Documents.getInstance().get(query);
|
||||
// this.setState({ documents, mockedCustomer });
|
||||
// }
|
||||
|
||||
private onCloseModalAddDocument() {
|
||||
this.setState({ isAddDocumentModalVisible: false });
|
||||
|
@ -15,7 +15,6 @@ import React from "react";
|
||||
|
||||
import BasePage from "../../Base";
|
||||
import classes from "./classes.module.scss";
|
||||
import OcrResult from "./OcrResult";
|
||||
import Files from "@Front/Api/LeCoffreApi/Notary/Files/Files";
|
||||
import TextAreaField from "@Front/Components/DesignSystem/Form/TextareaField";
|
||||
|
||||
|
@ -116,10 +116,9 @@ export default class MyAccount extends Base<IProps, IState> {
|
||||
}
|
||||
|
||||
public override async componentDidMount() {
|
||||
const jwtUncoded = JwtService.getInstance().decodeCustomerJwt();
|
||||
console.log(jwtUncoded);
|
||||
if (!jwtUncoded) return;
|
||||
const user = await Users.getInstance().getByUid(jwtUncoded.userId, {
|
||||
const jwtDecoded = JwtService.getInstance().decodeJwt();
|
||||
if (!jwtDecoded) return;
|
||||
const user = await Users.getInstance().getByUid(jwtDecoded.userId, {
|
||||
q: {
|
||||
office_membership: {
|
||||
include: {
|
||||
|
@ -25,7 +25,7 @@ export default function SelectFolder() {
|
||||
where: {
|
||||
customers: {
|
||||
some: {
|
||||
uid: jwt.userId || (jwt as any).customerId,
|
||||
uid: jwt.customerId || (jwt as any).customerId,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ export interface IUserJwtPayload {
|
||||
}
|
||||
|
||||
export interface ICustomerJwtPayload {
|
||||
userId: string;
|
||||
customerId: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user