diff --git a/next.config.js b/next.config.js index d31df2d0..b25da680 100644 --- a/next.config.js +++ b/next.config.js @@ -13,6 +13,7 @@ const nextConfig = { NEXT_PUBLIC_IDNOT_AUTHORIZE_ENDPOINT: process.env.NEXT_PUBLIC_IDNOT_AUTHORIZE_ENDPOINT, NEXT_PUBLIC_IDNOT_CLIENT_ID: process.env.NEXT_PUBLIC_IDNOT_CLIENT_ID, NEXT_PUBLIC_IDNOT_BASE_URL: process.env.NEXT_PUBLIC_IDNOT_BASE_URL, + NEXT_PUBLIC_DOCAPOSTE_API_URL: process.env.NEXT_PUBLIC_DOCAPOSTE_API_URL, }, // webpack: config => { // config.node = { diff --git a/src/common/Api/LeCoffreApi/Admin/BaseAdmin.ts b/src/common/Api/LeCoffreApi/Admin/BaseAdmin.ts new file mode 100644 index 00000000..fbcffb4d --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/BaseAdmin.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseAdmin extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/admin"); +} diff --git a/src/common/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts b/src/common/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts new file mode 100644 index 00000000..9cb83d35 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/DeedTypes/DeedTypes.ts @@ -0,0 +1,94 @@ +import { DeedType } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + document_types?: DeedType["document_types"]; +}; + +export type IPostDeedTypesParams = { + name?: DeedType["name"]; + description?: DeedType["description"]; +}; + +export type IGetDeedTypesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export default class DeedTypes extends BaseAdmin { + private static instance: DeedTypes; + private readonly baseURl = this.namespaceUrl.concat("/deed-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new DeedTypes(); + } else { + return this.instance; + } + } + + public async get(q: IGetDeedTypesParams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDeedTypesParams) { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async post(body: IPostDeedTypesParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async delete(uid: string) { + const url = new URL(this.baseURl); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/Deeds/Deeds.ts b/src/common/Api/LeCoffreApi/Admin/Deeds/Deeds.ts new file mode 100644 index 00000000..1c0ddef8 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/Deeds/Deeds.ts @@ -0,0 +1,49 @@ +import { Deed } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IGetDeedsParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export default class Deeds extends BaseAdmin { + private static instance: Deeds; + private readonly baseURl = this.namespaceUrl.concat("/deeds"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Deeds(); + } else { + return this.instance; + } + } + + public async get(q: IGetDeedsParams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/DocumentTypes/DocumentTypes.ts b/src/common/Api/LeCoffreApi/Admin/DocumentTypes/DocumentTypes.ts new file mode 100644 index 00000000..67851626 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/DocumentTypes/DocumentTypes.ts @@ -0,0 +1,86 @@ +import { DocumentType } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentTypesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentTypesParams = {}; + +export interface IPostDocumentTypesParams { + name: string; + public_description: string; + private_description: string; + office: { + uid: string; + }; +} + +export default class DocumentTypes extends BaseAdmin { + private static instance: DocumentTypes; + private readonly baseURl = this.namespaceUrl.concat("/document-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentTypesparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: DocumentType): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body as any); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentTypesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/Documents/Documents.ts b/src/common/Api/LeCoffreApi/Admin/Documents/Documents.ts new file mode 100644 index 00000000..e3f2159e --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/Documents/Documents.ts @@ -0,0 +1,93 @@ +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; +import { Document } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseAdmin from "../BaseAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentsparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentsParams = { + document_status?: EDocumentStatus; + refused_reason?: string; +}; + +export interface IPostDocumentsParams {} + +export default class Documents extends BaseAdmin { + private static instance: Documents; + private readonly baseURl = this.namespaceUrl.concat("/documents"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentsparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts b/src/common/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts new file mode 100644 index 00000000..06691262 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/OfficeRoles/OfficeRoles.ts @@ -0,0 +1,81 @@ +import { OfficeRole } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IGetRolesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export type IPutRoleParams = { + uid: OfficeRole["uid"]; + rules: OfficeRole["rules"]; +}; + +export type IPostRoleParams = { + name: OfficeRole["name"]; + office: OfficeRole["office"]; +}; + +export default class OfficeRoles extends BaseAdmin { + private static instance: OfficeRoles; + private readonly baseURl = this.namespaceUrl.concat("/office-roles"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new OfficeRoles(); + } else { + return this.instance; + } + } + + public async get(q?: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutRoleParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async post(body: IPostRoleParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/Roles/Roles.ts b/src/common/Api/LeCoffreApi/Admin/Roles/Roles.ts new file mode 100644 index 00000000..88bfed5a --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/Roles/Roles.ts @@ -0,0 +1,96 @@ +import { Role } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IGetRolesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export type IPutRoleParams = { + uid: Role["uid"]; + rules: Role["rules"]; +}; + +export type IPostRoleParams = { + name: Role["name"]; +}; +export default class Roles extends BaseAdmin { + private static instance: Roles; + private readonly baseURl = this.namespaceUrl.concat("/roles"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Roles(); + } else { + return this.instance; + } + } + + public async get(q?: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async post(body: IPostRoleParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getOne(q?: IGetRolesParams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + const res = await this.getRequest(url); + if (!res) return null; + if (res.length > 1) throw new Error("More than one role found"); + return res[0] ? res[0] : null; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutRoleParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/Rules/Rules.ts b/src/common/Api/LeCoffreApi/Admin/Rules/Rules.ts new file mode 100644 index 00000000..f8d79d90 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/Rules/Rules.ts @@ -0,0 +1,49 @@ +import { Rule } from "le-coffre-resources/dist/Admin"; + +import BaseAdmin from "../BaseAdmin"; + +export type IGetRulesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export default class Rules extends BaseAdmin { + private static instance: Rules; + private readonly baseURl = this.namespaceUrl.concat("/rules"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Rules(); + } else { + return this.instance; + } + } + + public async get(q: IGetRulesParams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Admin/Users/Users.ts b/src/common/Api/LeCoffreApi/Admin/Users/Users.ts new file mode 100644 index 00000000..6e50f59a --- /dev/null +++ b/src/common/Api/LeCoffreApi/Admin/Users/Users.ts @@ -0,0 +1,91 @@ +import User from "le-coffre-resources/dist/SuperAdmin"; +import BaseAdmin from "../BaseAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetUsersparams { + where?: {}; + include?: {}; + select?: {}; +} + +// TODO Type getbyuid query params + +export type IPutUsersParams = { + uid?: User["uid"]; + idNot?: User["idNot"]; + contact?: User["contact"]; + office_membership?: User["office_membership"]; + documents?: User["documents"]; +}; + +export default class Users extends BaseAdmin { + private static instance: Users; + private readonly baseURl = this.namespaceUrl.concat("/users"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all Users + */ + public async get(q: IGetUsersparams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a User + */ + // public async post(body: IPostDeedsParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutUsersParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Customer/BaseCustomer.ts b/src/common/Api/LeCoffreApi/Customer/BaseCustomer.ts new file mode 100644 index 00000000..f732de84 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/BaseCustomer.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseNotary extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/customer"); +} diff --git a/src/common/Api/LeCoffreApi/Customer/Customers/Customers.ts b/src/common/Api/LeCoffreApi/Customer/Customers/Customers.ts new file mode 100644 index 00000000..b596a695 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/Customers/Customers.ts @@ -0,0 +1,67 @@ +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 { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Customer/Documents/Documents.ts b/src/common/Api/LeCoffreApi/Customer/Documents/Documents.ts new file mode 100644 index 00000000..8590554b --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/Documents/Documents.ts @@ -0,0 +1,93 @@ +import { Document } from "le-coffre-resources/dist/Customer"; + +import BaseCustomer from "../BaseCustomer"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentsparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentsParams = { + document_status?: EDocumentStatus; + refused_reason?: string; +}; + +export interface IPostDocumentsParams {} + +export default class Documents extends BaseCustomer { + private static instance: Documents; + private readonly baseURl = this.namespaceUrl.concat("/documents"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentsparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Customer/Files/Files.ts b/src/common/Api/LeCoffreApi/Customer/Files/Files.ts new file mode 100644 index 00000000..6ae12cf0 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/Files/Files.ts @@ -0,0 +1,93 @@ +import { File } from "le-coffre-resources/dist/Customer"; +import BaseCustomer from "../BaseCustomer"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFilesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutFilesParams = {}; + +export interface IPostFilesParams {} + +export default class Files extends BaseCustomer { + private static instance: Files; + private readonly baseURl = this.namespaceUrl.concat("/files"); + + private constructor() { + super(); + } + + public static getInstance() { + return (this.instance ??= new this()); + } + + public async get(q: IGetFilesparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + const files = await this.getRequest(url); + return files; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a File + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequestFormData(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public getUploadLink(uid: string): string { + return this.baseURl.concat(`/download/${uid}`); + } + + public async getByUid(uid: string, q?: any): Promise { + 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 { + const file = await this.getRequest(url); + return file; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutFilesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Delete a folder only if the folder don't contains customers + */ + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Customer/Folders/Folders.ts b/src/common/Api/LeCoffreApi/Customer/Folders/Folders.ts new file mode 100644 index 00000000..27bfd731 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/Folders/Folders.ts @@ -0,0 +1,57 @@ +import { type OfficeFolder } from "le-coffre-resources/dist/Customer"; + +import BaseCustomer from "../BaseCustomer"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFoldersParams { + q?: { + select?: {}; + where?: {}; + include?: {}; + }; +} + +export default class Folders extends BaseCustomer { + private static instance: Folders; + private readonly baseURl = this.namespaceUrl.concat("/folders"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all folders + */ + public async get(q: IGetFoldersParams): Promise { + const url = new URL(this.baseURl); + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Customer/Users/Users.ts b/src/common/Api/LeCoffreApi/Customer/Users/Users.ts new file mode 100644 index 00000000..e64928bc --- /dev/null +++ b/src/common/Api/LeCoffreApi/Customer/Users/Users.ts @@ -0,0 +1,49 @@ +import BaseNotary from "../BaseCustomer"; +import User from "le-coffre-resources/dist/Notary"; + +export default class Users extends BaseNotary { + private static instance: Users; + private readonly baseURl = this.namespaceUrl.concat("/Users"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Users(); + } else { + return this.instance; + } + } + + public async get(): Promise { + const url = new URL(this.baseURl); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getOne(uid: string): Promise { + const url = new URL(this.baseURl.concat("/").concat(uid)); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + // public async post(params: User): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, params); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } +} diff --git a/src/common/Api/LeCoffreApi/Notary/BaseNotary.ts b/src/common/Api/LeCoffreApi/Notary/BaseNotary.ts new file mode 100644 index 00000000..2e1e013c --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/BaseNotary.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseNotary extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/notary"); +} diff --git a/src/common/Api/LeCoffreApi/Notary/Customers/Customers.ts b/src/common/Api/LeCoffreApi/Notary/Customers/Customers.ts new file mode 100644 index 00000000..c6c3918e --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/Customers/Customers.ts @@ -0,0 +1,90 @@ +import { Contact, Customer } from "le-coffre-resources/dist/Notary"; + +import BaseNotary from "../BaseNotary"; +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 BaseNotary { + 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 { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Customer + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutCustomersParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/DeedTypes/DeedTypes.ts b/src/common/Api/LeCoffreApi/Notary/DeedTypes/DeedTypes.ts new file mode 100644 index 00000000..5c051ef4 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/DeedTypes/DeedTypes.ts @@ -0,0 +1,84 @@ +import { DeedType } from "le-coffre-resources/dist/Notary"; + +import BaseNotary from "../BaseNotary"; + +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + document_types?: DeedType["document_types"]; +}; + +export type IPostDeedTypesParams = { + name?: DeedType["name"]; + description?: DeedType["description"]; +}; + +export type IGetDeedTypesParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export default class DeedTypes extends BaseNotary { + private static instance: DeedTypes; + private readonly baseURl = this.namespaceUrl.concat("/deed-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new DeedTypes(); + } else { + return this.instance; + } + } + + public async get(q?: IGetDeedTypesParams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDeedTypesParams) { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async post(body: IPostDeedTypesParams) { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/Deeds/Deeds.ts b/src/common/Api/LeCoffreApi/Notary/Deeds/Deeds.ts new file mode 100644 index 00000000..6e4c4dba --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/Deeds/Deeds.ts @@ -0,0 +1,72 @@ +import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary"; + +import BaseAdmin from "../BaseNotary"; + +export type IGetDeedsParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export type IPutDeedsParams = { + uid?: OfficeFolder["uid"]; + folder_number?: OfficeFolder["folder_number"]; + name?: OfficeFolder["name"]; + description?: OfficeFolder["description"]; + archived_description?: OfficeFolder["archived_description"]; + status?: OfficeFolder["status"]; + document_types?: Deed["document_types"]; +}; + +export default class Deeds extends BaseAdmin { + private static instance: Deeds; + private readonly baseURl = this.namespaceUrl.concat("/deeds"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Deeds(); + } else { + return this.instance; + } + } + + public async get(q: IGetDeedsParams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutDeedsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/DocumentTypes/DocumentTypes.ts b/src/common/Api/LeCoffreApi/Notary/DocumentTypes/DocumentTypes.ts new file mode 100644 index 00000000..3737ddf3 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/DocumentTypes/DocumentTypes.ts @@ -0,0 +1,86 @@ +import { DocumentType } from "le-coffre-resources/dist/Notary"; + +import BaseNotary from "../BaseNotary"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentTypesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentTypesParams = {}; + +export interface IPostDocumentTypesParams { + name: string; + public_description: string; + private_description: string | null; + office?: { + uid?: string; + }; +} + +export default class DocumentTypes extends BaseNotary { + private static instance: DocumentTypes; + private readonly baseURl = this.namespaceUrl.concat("/document-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentTypesparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: IPostDocumentTypesParams): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body as any); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentTypesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/Documents/Documents.ts b/src/common/Api/LeCoffreApi/Notary/Documents/Documents.ts new file mode 100644 index 00000000..45e68b9e --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/Documents/Documents.ts @@ -0,0 +1,93 @@ +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; +import { Document } from "le-coffre-resources/dist/Notary"; + +import BaseNotary from "../BaseNotary"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentsparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentsParams = { + document_status?: EDocumentStatus; + refused_reason?: string; +}; + +export interface IPostDocumentsParams {} + +export default class Documents extends BaseNotary { + private static instance: Documents; + private readonly baseURl = this.namespaceUrl.concat("/documents"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentsparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/Folders/Folders.ts b/src/common/Api/LeCoffreApi/Notary/Folders/Folders.ts new file mode 100644 index 00000000..800d3c96 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/Folders/Folders.ts @@ -0,0 +1,119 @@ +import { type OfficeFolder } from "le-coffre-resources/dist/Notary"; + +import BaseNotary from "../BaseNotary"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFoldersParams { + q?: { + select?: {}; + where?: {}; + include?: {}; + }; +} + +export default class Folders extends BaseNotary { + private static instance: Folders; + private readonly baseURl = this.namespaceUrl.concat("/folders"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all folders + */ + public async get(q: IGetFoldersParams): Promise { + const url = new URL(this.baseURl); + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a folder + */ + public async post(officeFolder: Partial): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, officeFolder); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: Partial): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Delete a folder only if the folder don't contains customers + */ + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + const targetedFolder = await this.getByUid(uid); + if (targetedFolder.customers) return Promise.reject(`The folder ${uid} contains customers`); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async archive(uid: string, body: Partial): Promise { + body.status = EFolderStatus.ARCHIVED; + try { + return await this.put(uid, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async restore(uid: string, body: Partial): Promise { + body.status = EFolderStatus.LIVE; + try { + return await this.put(uid, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/Notary/Users/Users.ts b/src/common/Api/LeCoffreApi/Notary/Users/Users.ts new file mode 100644 index 00000000..47a368a0 --- /dev/null +++ b/src/common/Api/LeCoffreApi/Notary/Users/Users.ts @@ -0,0 +1,48 @@ +import BaseNotary from "../BaseNotary"; +import User from "le-coffre-resources/dist/Notary"; + +export type IGetUsersParams = { + where?: {}; + include?: {}; + select?: {}; +}; + +export default class Users extends BaseNotary { + private static instance: Users; + private readonly baseURl = this.namespaceUrl.concat("/users"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new Users(); + } else { + return this.instance; + } + } + + public async get(q?: IGetUsersParams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat("/").concat(uid)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/BaseSuperAdmin.ts b/src/common/Api/LeCoffreApi/SuperAdmin/BaseSuperAdmin.ts new file mode 100644 index 00000000..848d5597 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/BaseSuperAdmin.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseSuperAdmin extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/super-admin"); +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts new file mode 100644 index 00000000..a345d13b --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Customers/Customers.ts @@ -0,0 +1,90 @@ +import { Contact, Customer } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; +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 BaseSuperAdmin { + 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 { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Customer + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutCustomersParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts b/src/common/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts new file mode 100644 index 00000000..9ce2dc89 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/DeedTypes/DeedTypes.ts @@ -0,0 +1,92 @@ +import { DeedType } from "le-coffre-resources/dist/Notary"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDeedTypesParams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDeedTypesParams = { + uid?: DeedType["uid"]; + name?: DeedType["name"]; + description?: DeedType["description"]; + deed?: DeedType["deed"]; + office?: DeedType["office"]; + archived_at?: DeedType["archived_at"]; + document_types?: DeedType["document_types"]; +}; + +export default class DeedTypes extends BaseSuperAdmin { + private static instance: DeedTypes; + private readonly baseURl = this.namespaceUrl.concat("/deed-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all DeedTypes + */ + public async get(q?: IGetDeedTypesParams): Promise { + const url = new URL(this.baseURl); + if(q){ + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a deed + */ + // public async post(body: IPostDeedTypesParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutDeedTypesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts new file mode 100644 index 00000000..a3360412 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Deeds/Deeds.ts @@ -0,0 +1,90 @@ +import { Deed, OfficeFolder } from "le-coffre-resources/dist/Notary"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDeedsParams { + q?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDeedsParams = { + uid?: OfficeFolder["uid"]; + folder_number?: OfficeFolder["folder_number"]; + name?: OfficeFolder["name"]; + description?: OfficeFolder["description"]; + archived_description?: OfficeFolder["archived_description"]; + status?: OfficeFolder["status"]; + document_types?: Deed["document_types"]; +}; + +export default class Deeds extends BaseSuperAdmin { + private static instance: Deeds; + private readonly baseURl = this.namespaceUrl.concat("/deeds"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all deeds + */ + public async get(q: IGetDeedsParams): Promise { + const url = new URL(this.baseURl); + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a deed + */ + // public async post(body: IPostDeedsParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutDeedsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts b/src/common/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts new file mode 100644 index 00000000..f151377e --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/DocumentTypes/DocumentTypes.ts @@ -0,0 +1,88 @@ +import { DocumentType } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentTypesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentTypesParams = {}; + +export interface IPostDocumentTypesParams { + name: string; + public_description: string; + private_description: string; + office: { + uid: string; + }; +} + +export default class DocumentTypes extends BaseSuperAdmin { + private static instance: DocumentTypes; + private readonly baseURl = this.namespaceUrl.concat("/document-types"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q?: IGetDocumentTypesparams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: IPostDocumentTypesParams): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body as any); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentTypesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Documents/Documents.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Documents/Documents.ts new file mode 100644 index 00000000..d7c0a95a --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Documents/Documents.ts @@ -0,0 +1,93 @@ +import { Document } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; +import { EDocumentStatus } from "le-coffre-resources/dist/Customer/Document"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetDocumentsparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutDocumentsParams = { + document_status?: EDocumentStatus; + refused_reason?: string; +}; + +export interface IPostDocumentsParams {} + +export default class Documents extends BaseSuperAdmin { + private static instance: Documents; + private readonly baseURl = this.namespaceUrl.concat("/documents"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q: IGetDocumentsparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a Document + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async getByUid(uid: string, q?: any): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutDocumentsParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Files/Files.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Files/Files.ts new file mode 100644 index 00000000..c3fe5580 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Files/Files.ts @@ -0,0 +1,93 @@ +import { File } from "le-coffre-resources/dist/SuperAdmin"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFilesparams { + where?: {}; + include?: {}; +} + +// TODO Type getbyuid query params + +export type IPutFilesParams = {}; + +export interface IPostFilesParams {} + +export default class Files extends BaseSuperAdmin { + private static instance: Files; + private readonly baseURl = this.namespaceUrl.concat("/files"); + + private constructor() { + super(); + } + + public static getInstance() { + return (this.instance ??= new this()); + } + + public async get(q: IGetFilesparams): Promise { + const url = new URL(this.baseURl); + const query = { q }; + if (q) Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + const files = await this.getRequest(url); + return files; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a File + */ + public async post(body: any): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequestFormData(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public getUploadLink(uid: string): string { + return this.baseURl.concat(`/download/${uid}`); + } + + public async getByUid(uid: string, q?: any): Promise { + 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 { + const file = await this.getRequest(url); + return file; + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async put(uid: string, body: IPutFilesParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Delete a folder only if the folder don't contains customers + */ + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts new file mode 100644 index 00000000..844095aa --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Folders/Folders.ts @@ -0,0 +1,119 @@ +import { type OfficeFolder } from "le-coffre-resources/dist/Notary"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; +import EFolderStatus from "le-coffre-resources/dist/Customer/EFolderStatus"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetFoldersParams { + q?: { + select?: {}; + where?: {}; + include?: {}; + }; +} + +export default class Folders extends BaseSuperAdmin { + private static instance: Folders; + private readonly baseURl = this.namespaceUrl.concat("/folders"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all folders + */ + public async get(q: IGetFoldersParams): Promise { + const url = new URL(this.baseURl); + Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a folder + */ + public async post(officeFolder: Partial): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, officeFolder); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: Partial): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Delete a folder only if the folder don't contains customers + */ + public async delete(uid: string): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + const targetedFolder = await this.getByUid(uid); + if (targetedFolder.customers) return Promise.reject(`The folder ${uid} contains customers`); + try { + return await this.deleteRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async archive(uid: string, body: Partial): Promise { + body.status = EFolderStatus.ARCHIVED; + try { + return await this.put(uid, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async restore(uid: string, body: Partial): Promise { + body.status = EFolderStatus.LIVE; + try { + return await this.put(uid, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes.ts b/src/common/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes.ts new file mode 100644 index 00000000..394e1b93 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes.ts @@ -0,0 +1,49 @@ +import { Appointment } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetLiveVotessparams { + where?: {}; + include?: {}; + select?: {}; +} + +export type IPostLiveVotesParams = { + appointment: Appointment; +}; + +export type LiveVote = { + uid: string; + appointment: Appointment; +}; + +export default class LiveVotes extends BaseSuperAdmin { + private static instance: LiveVotes; + private readonly baseURl = this.namespaceUrl.concat("/live-votes"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Create a LiveVotes + */ + public async post(body: IPostLiveVotesParams): Promise { + const url = new URL(this.baseURl); + try { + return await this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Offices/Offices.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Offices/Offices.ts new file mode 100644 index 00000000..595a62eb --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Offices/Offices.ts @@ -0,0 +1,53 @@ +import { Office } from "le-coffre-resources/dist/SuperAdmin"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +export interface IGetOfficesparams { + where?: {}; + include?: {}; + select?: {}; +} + +export default class Offices extends BaseSuperAdmin { + private static instance: Offices; + private readonly baseURl = this.namespaceUrl.concat("/offices"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + public async get(q?: IGetOfficesparams): Promise { + const url = new URL(this.baseURl); + if (q) { + const query = { q }; + Object.entries(query).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + } + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Users/Users.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Users/Users.ts new file mode 100644 index 00000000..319a01fd --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Users/Users.ts @@ -0,0 +1,91 @@ +import User from "le-coffre-resources/dist/SuperAdmin"; +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetUsersparams { + where?:{}, + include?:{}, + select?:{}, +} + +// TODO Type getbyuid query params + +export type IPutUsersParams = { + uid?: User["uid"]; + idNot?: User["idNot"]; + contact?: User["contact"]; + office_membership?: User["office_membership"]; + documents?: User["documents"]; +}; + +export default class Users extends BaseSuperAdmin { + private static instance: Users; + private readonly baseURl = this.namespaceUrl.concat("/users"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Get all Users + */ + public async get(q: IGetUsersparams): Promise { + 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(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Get a folder by uid + */ + public async getByUid(uid: string, q?: any): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + if (q) Object.entries(q).forEach(([key, value]) => url.searchParams.set(key, JSON.stringify(value))); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + /** + * @description : Create a User + */ + // public async post(body: IPostDeedsParams): Promise { + // const url = new URL(this.baseURl); + // try { + // return await this.postRequest(url, body); + // } catch (err) { + // this.onError(err); + // return Promise.reject(err); + // } + // } + + /** + * @description : Update the folder description + */ + public async put(uid: string, body: IPutUsersParams): Promise { + const url = new URL(this.baseURl.concat(`/${uid}`)); + try { + return await this.putRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/common/Api/LeCoffreApi/SuperAdmin/Votes/Votes.ts b/src/common/Api/LeCoffreApi/SuperAdmin/Votes/Votes.ts new file mode 100644 index 00000000..34907702 --- /dev/null +++ b/src/common/Api/LeCoffreApi/SuperAdmin/Votes/Votes.ts @@ -0,0 +1,44 @@ +import { Vote } from "le-coffre-resources/dist/SuperAdmin"; + +import BaseSuperAdmin from "../BaseSuperAdmin"; + +// TODO Type get query params -> Where + inclue + orderby +export interface IGetVotessparams { + where?: {}; + include?: {}; + select?: {}; +} + +export type IDeleteVotesParams = { + uid: Vote["uid"]; +}; + +export default class Votes extends BaseSuperAdmin { + private static instance: Votes; + private readonly baseURl = this.namespaceUrl.concat("/votes"); + + private constructor() { + super(); + } + + public static getInstance() { + if (!this.instance) { + return new this(); + } else { + return this.instance; + } + } + + /** + * @description : Create a Votes + */ + public async delete(body: IDeleteVotesParams): Promise { + const url = new URL(this.baseURl + "/" + body.uid); + try { + return await this.deleteRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Api/LeCoffreApi/Id360/BaseId360.ts b/src/front/Api/LeCoffreApi/Id360/BaseId360.ts new file mode 100644 index 00000000..49cb6e82 --- /dev/null +++ b/src/front/Api/LeCoffreApi/Id360/BaseId360.ts @@ -0,0 +1,5 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export default abstract class BaseNotary extends BaseApiService { + protected readonly namespaceUrl = this.getBaseUrl().concat("/id360"); +} diff --git a/src/front/Api/LeCoffreApi/Id360/Customers/Customers.ts b/src/front/Api/LeCoffreApi/Id360/Customers/Customers.ts new file mode 100644 index 00000000..edf23384 --- /dev/null +++ b/src/front/Api/LeCoffreApi/Id360/Customers/Customers.ts @@ -0,0 +1,45 @@ +import BaseId360 from "../BaseId360"; + +export interface IConnectionUrlResponse { + enrollment: { + franceConnectUrl: string; + processId: string; + } +} + +export default class Customers extends BaseId360 { + 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 login(): Promise { + const url = new URL(this.baseURl.concat(`/login`)); + try { + return await this.postRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } + + public async loginCallback(callbackToken: string | string[]): Promise { + const url = new URL(this.baseURl.concat(`/login-callback/${callbackToken}`)); + try { + return await this.postRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts b/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts index c3fe5580..101e1e57 100644 --- a/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts +++ b/src/front/Api/LeCoffreApi/SuperAdmin/Files/Files.ts @@ -51,8 +51,14 @@ export default class Files extends BaseSuperAdmin { } } - public getUploadLink(uid: string): string { - return this.baseURl.concat(`/download/${uid}`); + public async getUploadLink(uid: string) { + const url = new URL(this.baseURl.concat(`/download/${uid}`)); + try { + return await this.getRequest(url); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } } public async getByUid(uid: string, q?: any): Promise { diff --git a/src/front/Components/Elements/Rules/index.tsx b/src/front/Components/Elements/Rules/index.tsx index ecf66840..a7eb7865 100644 --- a/src/front/Components/Elements/Rules/index.tsx +++ b/src/front/Components/Elements/Rules/index.tsx @@ -43,4 +43,4 @@ export default function Rules(props: IProps) { if (!hasJwt || !isShowing) return null; return props.children; -} +} \ No newline at end of file diff --git a/src/front/Components/Layouts/Login/index.tsx b/src/front/Components/Layouts/Login/index.tsx index a552bbbb..5c621570 100644 --- a/src/front/Components/Layouts/Login/index.tsx +++ b/src/front/Components/Layouts/Login/index.tsx @@ -4,8 +4,6 @@ import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; import Module from "@Front/Config/Module"; -import JwtService from "@Front/Services/JwtService/JwtService"; -import UserStore from "@Front/Stores/UserStore"; import Image from "next/image"; import { useRouter } from "next/router"; import { useCallback } from "react"; @@ -13,6 +11,7 @@ import { useCallback } from "react"; import classes from "./classes.module.scss"; import LandingImage from "./landing-connect.jpeg"; import { FrontendVariables } from "@Front/Config/VariablesFront"; +import Customers from "@Front/Api/LeCoffreApi/Id360/Customers/Customers"; export default function Login() { const router = useRouter(); @@ -29,14 +28,12 @@ export default function Login() { const redirectCustomerOnConnection = useCallback(() => { async function getCustomer() { try { - await UserStore.instance.connectCustomer("antoine.bernard@outlook.com"); - await JwtService.getInstance().checkJwt(); - router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path); + const loginRes = await Customers.getInstance().login(); + router.push(loginRes.enrollment.franceConnectUrl); } catch (e) { console.error(e); } } - getCustomer(); }, [router]); diff --git a/src/front/Components/Layouts/LoginCallbackCustomer/classes.module.scss b/src/front/Components/Layouts/LoginCallbackCustomer/classes.module.scss new file mode 100644 index 00000000..72ae8ab8 --- /dev/null +++ b/src/front/Components/Layouts/LoginCallbackCustomer/classes.module.scss @@ -0,0 +1,29 @@ +@import "@Themes/constants.scss"; + +.root { + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + height: 100%; + max-width: 530px; + margin: auto; + + .title { + margin: 32px 0; + text-align: center; + @media (max-width: $screen-s) { + font-family: 48px; + } + } + + .loader { + width: 32px; + height: 32px; + } + + .forget-password { + margin-top: 32px; + margin-bottom: 8px; + } +} diff --git a/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx b/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx new file mode 100644 index 00000000..bd78a01c --- /dev/null +++ b/src/front/Components/Layouts/LoginCallbackCustomer/index.tsx @@ -0,0 +1,55 @@ +import LandingImage from "../Login/landing-connect.jpeg"; +import Image from "next/image"; +import CoffreIcon from "@Assets/Icons/coffre.svg"; +import { useRouter } from "next/router"; +import React, { useEffect } from "react"; +import classes from "./classes.module.scss"; +//import Module from "@Front/Config/Module"; +//import Auth from "@Front/Api/Auth/IdNot"; +import DefaultDoubleSidePage from "@Front/Components/LayoutTemplates/DefaultDoubleSidePage"; +import Typography, { ITypo } from "@Front/Components/DesignSystem/Typography"; +import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; +import Loader from "@Front/Components/DesignSystem/Loader"; +// import { FrontendVariables } from "@Front/Config/VariablesFront"; +// import CustomerStore from "@Front/Stores/CustomerStore"; +import Customers from "@Front/Api/LeCoffreApi/Id360/Customers/Customers"; +import CustomerStore from "@Front/Stores/CustomerStore"; +import Module from "@Front/Config/Module"; + + +export default function LoginCallBack() { + const router = useRouter(); + + useEffect(() => { + const getReport = async() => { + const tokenid360 = router.query["token"]; + if (!tokenid360) return; + // const variables = FrontendVariables.getInstance(); + // console.log(`${variables.DOCAPOST_API_URL}/enrollment/status/${tokenid360}/`) + // const reportRes = await fetch(`${variables.DOCAPOST_API_URL}/enrollment/status/${tokenid360}`, { method: "GET"}); + // const report = await reportRes.json() as id360ProcessResponse; + const token = await Customers.getInstance().loginCallback(tokenid360); + CustomerStore.instance.connect(token.accessToken, token.refreshToken); + router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path); + } + getReport(); + }),[router]; + + return ( + +
+ coffre + +
Connexion espace client
+
+
+ +
+ +
Vous n'arrivez pas à vous connecter ?
+
+ +
+
+ ); +} diff --git a/src/front/Config/VariablesFront.ts b/src/front/Config/VariablesFront.ts index 9011b674..8dec0730 100644 --- a/src/front/Config/VariablesFront.ts +++ b/src/front/Config/VariablesFront.ts @@ -17,6 +17,8 @@ export class FrontendVariables { public IDNOT_CLIENT_ID!: string; + public DOCAPOST_API_URL!: string; + public KEY_DATA!: string; public FC_AUTHORIZE_ENDPOINT!: string; diff --git a/src/front/Stores/CustomerStore.ts b/src/front/Stores/CustomerStore.ts new file mode 100644 index 00000000..b360998c --- /dev/null +++ b/src/front/Stores/CustomerStore.ts @@ -0,0 +1,77 @@ +"use client"; + +import Customer from "@Front/Api/Auth/franceConnect/Customer"; +import CookieService from "@Front/Services/CookieService/CookieService"; +import EventEmitter from "@Front/Services/EventEmitter"; +import JwtService from "@Front/Services/JwtService/JwtService"; + +export default class UserStore { + public static readonly instance = new this(); + protected readonly event = new EventEmitter(); + public accessToken: string | null = null; + public refreshToken: string | null = null; + + private constructor() {} + + public isConnected(): boolean { + return !!this.accessToken; + } + + public getRole(): string | undefined { + const decodedPayload = JwtService.getInstance().decodeJwt(); + return decodedPayload?.role; + } + + public async connect(accessToken: string, refreshToken: string) { + try { + //Save tokens in cookies + CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken); + CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken); + + this.event.emit("connection", this.accessToken); + } catch (error) { + console.error(error); + return false; + } + return true; + } + + public async connectCustomer(email: string) { + try { + //call connection function + const customer: any = await Customer.getInstance().login(email); + + //Save tokens in cookies + CookieService.getInstance().setCookie("leCoffreAccessToken", customer.accessToken); + CookieService.getInstance().setCookie("leCoffreRefreshToken", customer.refreshToken); + + this.event.emit("connection", this.accessToken); + } catch (error) { + console.error(error); + return false; + } + return true; + } + + public async disconnect() { + try { + //Remove tokens from cookies + CookieService.getInstance().deleteCookie("leCoffreAccessToken"); + CookieService.getInstance().deleteCookie("leCoffreRefreshToken"); + + this.event.emit("disconnection", this.accessToken); + } catch (error) { + console.error(error); + } + } + + public onDisconnect(callback: (userAddress: string) => void): () => void { + this.event.on("disconnection", callback); + return () => this.event.off("disconnection", callback); + } + + public onConnect(callback: (userAddress: string) => void): () => void { + this.event.on("connection", callback); + return () => this.event.off("connection", callback); + } +} diff --git a/src/middleware.ts b/src/middleware.ts index 8a9a4929..13034279 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,4 +1,3 @@ -import Notifications from "@Front/Api/LeCoffreApi/Notifications/Notifications"; import { ICustomerJwtPayload, IUserJwtPayload } from "@Front/Services/JwtService/JwtService"; import jwt_decode from "jwt-decode"; import { NextResponse } from "next/server"; @@ -21,8 +20,8 @@ export async function middleware(request: NextRequest) { const currentDate = new Date(); const time = currentDate.getTime(); const now = Math.floor(time / 1000); - if (token.exp < now) { + console.log("token expired"); return NextResponse.redirect(new URL("/login", request.url)); } diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 8419a1bb..b5ff011d 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -22,6 +22,7 @@ type AppPropsWithLayout = AppProps & { idNotClientId: string; fcAuthorizeEndpoint: string; fcClientId: string; + docaposteApiUrl: string; }; const MyApp = (({ @@ -36,7 +37,8 @@ const MyApp = (({ idNotAuthorizeEndpoint, idNotClientId, fcAuthorizeEndpoint, - fcClientId + fcClientId, + docaposteApiUrl }: AppPropsWithLayout) => { const getLayout = Component.getLayout ?? ((page) => ); @@ -51,6 +53,7 @@ const MyApp = (({ instance.IDNOT_CLIENT_ID = idNotClientId ?? "4501646203F3EF67"; instance.FC_AUTHORIZE_ENDPOINT= fcAuthorizeEndpoint ?? "https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize"; instance.FC_CLIENT_ID = fcClientId ?? "211286433e39cce01db448d80181bdfd005554b19cd51b3fe7943f6b3b86ab6e"; + instance.DOCAPOST_API_URL = docaposteApiUrl; return getLayout(); }) as AppType; @@ -67,7 +70,8 @@ MyApp.getInitialProps = async () => { idNotAuthorizeEndpoint: process.env["NEXT_PUBLIC_IDNOT_AUTHORIZE_ENDPOINT"], idNotClientId: process.env["NEXT_PUBLIC_IDNOT_CLIENT_ID"], fcAuthorizeEndpoint: process.env["NEXT_PUBLIC_FC_AUTHORIZE_ENDPOINT"], - fcClientId: process.env["NEXT_PUBLIC_FC_CLIENT_ID"] + fcClientId: process.env["NEXT_PUBLIC_FC_CLIENT_ID"], + docaposteApiUrl: process.env["NEXT_PUBLIC_DOCAPOST_API_URL"], }; }; diff --git a/src/pages/id360/customer-callback.tsx b/src/pages/id360/customer-callback.tsx new file mode 100644 index 00000000..a1270d2a --- /dev/null +++ b/src/pages/id360/customer-callback.tsx @@ -0,0 +1,5 @@ +import LoginCallBackCustomer from "@Front/Components/Layouts/LoginCallbackCustomer"; + +export default function Route() { + return ; +} \ No newline at end of file