2024-12-10
corvée(db) exporte la BDD de production
This commit is contained in:
parent
ace47f1701
commit
ac0efab9b2
8 changed files with 15893 additions and 217 deletions
|
|
@ -3,6 +3,7 @@ import { find as arrayFind, head as arrayHead } from "@mobily/ts-belt/Array";
|
|||
import { get as dictGet, map as dictMap, values as dictValues } from "@mobily/ts-belt/Dict";
|
||||
import { flatMap as optionFlatMap, getWithDefault as optionGetWithDefault } from "@mobily/ts-belt/Option";
|
||||
import { trim as stringTrim } from "@mobily/ts-belt/String";
|
||||
import { Option } from "@swan-io/boxed";
|
||||
import { EitherAsync, Maybe } from "purify-ts";
|
||||
import { match, P } from "ts-pattern";
|
||||
import { type AnySchema, ValiError } from "valibot";
|
||||
|
|
@ -10,7 +11,6 @@ import { type AnySchema, ValiError } from "valibot";
|
|||
import type { WCStoreCart, WCStoreShippingRateShippingRate } from "../lib/types/api/cart";
|
||||
import type { WCStoreCartUpdateCustomerArgs } from "../lib/types/api/cart-update-customer";
|
||||
import type { WCStoreShippingRateShippingRates } from "../lib/types/api/couts-livraison";
|
||||
import type { APIFetchErrors } from "../lib/types/api/erreurs";
|
||||
import type { WCV3Order, WCV3OrdersArgs } from "../lib/types/api/v3/orders";
|
||||
import type { EtatsPageGenerique } from "../lib/types/pages";
|
||||
import type { FetchErrors, HttpCodeErrors } from "../lib/types/reseau";
|
||||
|
|
@ -36,14 +36,7 @@ import {
|
|||
ERREUR_GENERIQUE_SOUMISSION_ADRESSES,
|
||||
} from "../constantes/messages-utilisateur";
|
||||
import { eitherJsonParse, eitherSessionStorageGet } from "../lib/dom";
|
||||
import {
|
||||
BadRequestError,
|
||||
leveErreur,
|
||||
NonExistingKeyError,
|
||||
reporteErreur,
|
||||
reporteEtJournaliseErreur,
|
||||
ServerError,
|
||||
} from "../lib/erreurs";
|
||||
import { leveErreur, type NonExistingKeyError, reporteErreur, reporteEtJournaliseErreur } from "../lib/erreurs";
|
||||
import { ErreurAdresseInvalide } from "../lib/erreurs/adresses";
|
||||
import { emetUniqueMessageBroadcastChannel } from "../lib/messages";
|
||||
import { diviseParCent, formateEnEuros } from "../lib/nombres";
|
||||
|
|
@ -172,20 +165,18 @@ export const initialiseBoutonCalculLivraison = (): void => {
|
|||
)
|
||||
// 4. Traite les cas d'Erreurs et récupère le Corps de la Réponse
|
||||
.chain((reponse: Response) =>
|
||||
EitherAsync<ErreurAdresseInvalide | HttpCodeErrors, unknown>(async ({ throwE }) =>
|
||||
// Simplifie les données à matcher
|
||||
EitherAsync<ErreurAdresseInvalide | HttpCodeErrors, unknown>(async ({ throwE }): Promise<unknown> =>
|
||||
match(await creeReponseSimplifiee(reponse))
|
||||
.with({ status: 200 }, rs => rs.body)
|
||||
// Problème d'adresse
|
||||
.with({ status: 200 }, (rs): unknown => rs.body)
|
||||
.with(
|
||||
{ body: P.when(body => estWCAddressError(body)), status: 400 },
|
||||
(r): never => throwE(new ErreurAdresseInvalide(r.body.data.params)),
|
||||
(rs): never => throwE(new ErreurAdresseInvalide(rs.body.data.params)),
|
||||
)
|
||||
.otherwise((rs): never => throwE(traiteErreursBackendWooCommerce(rs)))
|
||||
)
|
||||
)
|
||||
// 5. Vérifie le Schéma de la Réponse
|
||||
.chain((corpsReponse: unknown) => EitherAsync.liftEither(eitherParse(corpsReponse, WCStoreCartSchema)))
|
||||
.chain((corps: unknown) => EitherAsync.liftEither(eitherParse(corps, WCStoreCartSchema)))
|
||||
// 6. Exécute un Effet pour la mise à jour du DOM avec les Résultats
|
||||
.ifRight((panier: WCStoreCart): void => {
|
||||
E.MESSAGE_ADRESSES.textContent = " ";
|
||||
|
|
@ -294,11 +285,7 @@ export const initialiseBoutonCreationCommande = (): void => {
|
|||
reporteErreur(e);
|
||||
console.error(e.issues);
|
||||
})
|
||||
.with(P.instanceOf(SyntaxError), P.instanceOf(NonExistingKeyError), (e): void => {
|
||||
reporteErreur(e);
|
||||
console.error(e);
|
||||
})
|
||||
.exhaustive();
|
||||
.otherwise(reporteEtJournaliseErreur);
|
||||
|
||||
// Nettoie un stockage de session erroné
|
||||
sessionStorage.removeItem("shipping_rates");
|
||||
|
|
@ -372,64 +359,60 @@ export const initialiseBoutonCreationCommande = (): void => {
|
|||
.liftEither(eitherParse(argumentsFormulaire, WCV3OrdersArgsSchema))
|
||||
// 2. Exécute un Effet pour empêcher les requêtes concurrentes et lancer une animation de chargement
|
||||
.ifRight((): void => {
|
||||
// Désactive le Bouton pour empêcher des requêtes concurrentes
|
||||
majEtatChargementBouton(E.BOUTON_ACTIONS_FORMULAIRE, true);
|
||||
})
|
||||
// 3. Exécute la requête via fetch sous form d'EitherAsync
|
||||
.chain((args: WCV3OrdersArgs) =>
|
||||
EitherAsync<DOMException | Error | TypeError, Response>((): Promise<Response> =>
|
||||
eitherAsyncFetch(
|
||||
postBackend({
|
||||
authString: ETATS_PAGE.authString,
|
||||
corps: JSON.stringify(args),
|
||||
nonce: ETATS_PAGE.nonce,
|
||||
route: ROUTE_API_NOUVELLE_COMMANDES,
|
||||
})
|
||||
}),
|
||||
)
|
||||
)
|
||||
// 4. Traite les cas d'Erreurs et récupère le Corps de la Réponse
|
||||
.chain((reponse: Response) =>
|
||||
EitherAsync<APIFetchErrors, unknown>(async ({ throwE }): Promise<unknown> =>
|
||||
EitherAsync<HttpCodeErrors, unknown>(async ({ throwE }): Promise<unknown> =>
|
||||
match(await creeReponseSimplifiee(reponse))
|
||||
.with({ status: 201 }, (rs): unknown => rs.body)
|
||||
.with({ status: 500 }, (): never => throwE(new ServerError("500 Serveur Error")))
|
||||
.with({ status: 400 }, (): never => throwE(new BadRequestError("400 Bad Request Error")))
|
||||
.run()
|
||||
.otherwise((rs): never => throwE(traiteErreursBackendWooCommerce(rs)))
|
||||
)
|
||||
)
|
||||
// 5. Vérifie le Schéma de la Réponse
|
||||
.chain((corpsReponse: unknown) => EitherAsync.liftEither(eitherParse(corpsReponse, WCV3OrderSchema)))
|
||||
.chain((corps: unknown) => EitherAsync.liftEither(eitherParse(corps, WCV3OrderSchema)))
|
||||
// 6. Exécute un Effet pour la mise à jour du DOM avec les Résultats
|
||||
.ifRight((commande: WCV3Order): void => {
|
||||
E.BOUTON_ACTIONS_FORMULAIRE.removeAttribute(ATTRIBUT_CHARGEMENT);
|
||||
E.BOUTON_ACTIONS_FORMULAIRE.textContent = "OK!";
|
||||
E.MESSAGE_ADRESSES.textContent = " ";
|
||||
|
||||
const url = new URL(`https://${window.location.host}/checkout`);
|
||||
url.searchParams.append("order_key", commande.order_key);
|
||||
url.searchParams.append("order_id", String(commande.id));
|
||||
location.assign(url);
|
||||
// Redirige vers Stripe
|
||||
Option
|
||||
.fromNullable(new URL(`https://${window.location.host}/checkout`))
|
||||
.tapSome(url => url.searchParams.append("order_key", commande.order_key))
|
||||
.tapSome(url => url.searchParams.append("order_id", String(commande.id)))
|
||||
.tapSome(url => location.assign(url));
|
||||
})
|
||||
.ifLeft((erreur: BadRequestError | DOMException | ServerError | TypeError | ValiError<AnySchema>): void => {
|
||||
// 7. Traite les Erreurs et affiche un message à l'Utilisateur
|
||||
.ifLeft((erreur: FetchErrors | HttpCodeErrors | ValiError<AnySchema>): void => {
|
||||
match(erreur)
|
||||
.with(P.instanceOf(ValiError), (e): void => {
|
||||
reporteErreur(e);
|
||||
console.error("ValiError", e.issues);
|
||||
.with(P.instanceOf(ValiError), (e: ValiError<AnySchema>): void => {
|
||||
reporteEtJournaliseErreur(e);
|
||||
console.error(e.issues);
|
||||
E.MESSAGE_ADRESSES.textContent = ERREUR_GENERIQUE_CREATION_COMMANDE;
|
||||
})
|
||||
.with(
|
||||
P.instanceOf(BadRequestError),
|
||||
P.instanceOf(DOMException),
|
||||
P.instanceOf(ServerError),
|
||||
P.instanceOf(TypeError),
|
||||
(e): void => {
|
||||
reporteErreur(e);
|
||||
console.error(e);
|
||||
E.MESSAGE_ADRESSES.textContent = ERREUR_GENERIQUE_CREATION_COMMANDE;
|
||||
},
|
||||
)
|
||||
.otherwise((e): void => {
|
||||
reporteErreur(e);
|
||||
console.error("erreur inconnu", e);
|
||||
});
|
||||
.when(estErreurHttp, (e): void => {
|
||||
reporteEtJournaliseErreur(e);
|
||||
E.MESSAGE_ADRESSES.textContent = ERREUR_GENERIQUE_SOUMISSION_ADRESSES;
|
||||
})
|
||||
.when(estErreurFetch, (e): void => {
|
||||
reporteEtJournaliseErreur(e);
|
||||
E.MESSAGE_ADRESSES.textContent = ERREUR_GENERIQUE_RESEAU;
|
||||
})
|
||||
.exhaustive();
|
||||
|
||||
// Désactive l'animation de chargement et rend le Bouton de nouveau cliquable
|
||||
majEtatChargementBouton(E.BOUTON_ACTIONS_FORMULAIRE, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue