Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkPurchaseOrderStatus y correo de compra completada en 9punto5 #269

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

TextC0de
Copy link
Collaborator

Este PR implementa el envío de correos electrónicos de confirmación de compra específicos para tickets de 9punto5.

Los cambios principales incluyen:

  • Creación de una nueva plantilla de correo electrónico PurchaseOrderSuccessful9punto5 para 9punto5.
  • Modificación del servicio de correo transaccional para utilizar la nueva plantilla cuando se trata de la comunidad "9punto5".
  • Actualización de la lógica de sincronización del estado de pago de órdenes de compra para enviar el correo de confirmación cuando el pago se marca como completado.
  • Adición de pruebas unitarias para validar el nuevo flujo de envío de correos.

Copy link

github-actions bot commented Sep 12, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 81.73% 14197 / 17369
🔵 Statements 81.73% 14197 / 17369
🔵 Functions 77.07% 390 / 506
🔵 Branches 78.97% 1022 / 1294
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
src/authz/helpers.ts 83.33% 87.5% 85.71% 83.33% 89-107
src/datasources/db/purchaseOrders.ts 100% 100% 100% 100%
src/generated/types.ts 100% 100% 100% 100%
src/schema/purchaseOrder/actions.tsx 42.56% 60% 55.55% 42.56% 30-51, 97-102, 107-112, 143-234, 237-305, 308-546, 616-617, 653-654, 661-664, 711-712
src/schema/purchaseOrder/mutations.tsx 71.87% 83.33% 80% 71.87% 36-76, 118-119, 149-150
src/schema/purchaseOrder/tests/checkPurchaseOrderStatus.generated.ts 100% 100% 100% 100%
src/schema/userTickets/mutations.ts 84.93% 67.36% 94.73% 84.93% 99-100, 146-147, 169-170, 211-212, 223-224, 235-236, 283-284, 295-300, 312-317, 320-325, 374-379, 394-399, 446-447, 457-458, 478-481, 493-494, 500-527, 538, 561-562, 583-584, 630-635, 638-643
workers/purchase_order_payment_sync_cron/scheduled.tsx 60.24% 50% 33.33% 60.24% 50-54, 56-83
Generated in workflow #1177

@TextC0de TextC0de changed the title Agregar envío de correo de compra completada para 9punto5 checkPurchaseOrderStatus y correo de compra completada en 9punto5 Sep 12, 2024
@@ -35,6 +35,9 @@ const isOwnerOfPurchaseOrder = async ({
const isOwner = await DB.query.purchaseOrdersSchema.findFirst({
where: (po, { eq, and }) =>
and(eq(po.id, purchaseOrderId), eq(po.userId, user.id)),
columns: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es esto necesario si estamos devolviendo un Boolean(isOwner)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En este caso la tabla no tiene muchas columnas ni hacemos joins pero creo creo que seleccionar solo las columnas necesarias es una buena práctica.
¿Es necesario? No

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘🏼 me parece overkill, pero no estoy en contra

email,
}: {
DB: ORM_TYPE;
type SendPurchaseOrderSuccessfulEmailArgs = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

porque este cambio? la idea inicial es no tener que obtener toda la data de cada purchase order previamente cuando quieras usar este metodo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que hay optimizar la aplicación para evitar hacer consultas repetidas.

  • Esta función era utilizada en createPaymentIntent si todos los tickets son gratis.
  • En createPaymentIntent se está utilizando la función "fetchPurchaseOrderInformation" que ya traía la información de los ticketTemplate, prices y currencies.
  • En esta función se estaba repitiendo la misma consulta.

Por eso en principio había hecho este cambio, para evitar consultas duplicadas a la BD.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sacar la informacion de la BDD tiene q ser... 150ms? al ojo? Por ahora, no buscaría optimizar llamadas o performance (aka, evitar hacer consultas, etc) sino, hacer la experiencia de desarrollo mas facil por ahora.

Si esta, dale dejemoslo, pero 300ms no van a causar un drop de uso.

@@ -419,14 +413,6 @@ export const createPaymentIntent = async ({

const userTicketsIds = userTickets.map((t) => t.id);

await sendConfirmationEmail({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si todos los tickets son gratis, esto debería generar una PO "lista"....

Estamos validando y enviando un correo en este caso en otro lado?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tienes razón, mala mia. Pasé por alto el "if (allTicketsAreFree)"
Me fijaré los tests de esto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿En que casos, uno le pasaría generatePaymentLink como null a la mutación "claimUserTicket"?
El caso que se me ocurre es cuando todos los tickets son gratuitos.

Si se le pasa "generatePaymentLink" como null, entonces "createPaymentIntent" nunca es llamado y el correo no va a ser enviado.

builder.mutationField("claimUserTicket", (t) =>

@@ -237,27 +237,200 @@ export const PoppinsFont = () => (
</>
);

const roboto = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tengo 2 preguntas:

  • Son necesarias todas estás fuentes? Quizás solo incluir las que necesitas
  • Esto descarga todas las fuentes así no las use?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto descarga todas las fuentes así no las use?

Si estan en el HTML final, deberian

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seguí el estilo de lo mismo que se está haciendo con poppins, en la Poppins se está haciendo lo mismo de cargar un montón de fuentes.

Entiendo que sí una font-face no es utilizada no se descarga:

Igual estuve averiguando y vi que Gmail no soporta custom web fonts:

Lo recomendable es usar web fonts que están disponibles en la mayoría de clientes de correo.

Hice unos tests en Gmail y efectivamente, no vi que se estuvieran haciendo peticiones a estas URLs definidas aquí por lo que tal vez ni si quiera vale mucho la pena tener custom fonts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Me fijo que se usa y solo hago la carga de eso?
¿Hago lo mismo para Poppins?

</>
);

const bebasNeue = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se agrego nueva fuente

@@ -40,14 +43,16 @@ const sendEmailFunction = async (
logger.info("Using batch send");
const resendArgsArray = resendArgs.map((args) => {
const { from, htmlContent, subject, to, tags } = args;

return {
const next: CreateEmailOptions = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se tipó este mapeo para asegurar que todo está correcto con lo que espera resend

{
name: purchaseOrder.user.name ?? purchaseOrder.user.username,
email: purchaseOrder.user.email,
if (communityInfo.name === "9punto5") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este if no me convence pero creo que es lo que hay por ahora

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

subject: "Tus tickets están listos 🎉 | 9punto5",
});
} else {
await sendTransactionalHTMLEmail(this.resend, this.logger, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entiendo que este correo no está terminado aún ¿tal vez directamente sacar esto por ahora y sumarlo en otro PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es necesario twekear el estilo, mejor dejarlo si no necesitamos borarlo

email,
}: {
DB: ORM_TYPE;
type SendPurchaseOrderSuccessfulEmailArgs = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que hay optimizar la aplicación para evitar hacer consultas repetidas.

  • Esta función era utilizada en createPaymentIntent si todos los tickets son gratis.
  • En createPaymentIntent se está utilizando la función "fetchPurchaseOrderInformation" que ya traía la información de los ticketTemplate, prices y currencies.
  • En esta función se estaba repitiendo la misma consulta.

Por eso en principio había hecho este cambio, para evitar consultas duplicadas a la BD.

@@ -237,27 +237,200 @@ export const PoppinsFont = () => (
</>
);

const roboto = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seguí el estilo de lo mismo que se está haciendo con poppins, en la Poppins se está haciendo lo mismo de cargar un montón de fuentes.

Entiendo que sí una font-face no es utilizada no se descarga:

Igual estuve averiguando y vi que Gmail no soporta custom web fonts:

Lo recomendable es usar web fonts que están disponibles en la mayoría de clientes de correo.

Hice unos tests en Gmail y efectivamente, no vi que se estuvieran haciendo peticiones a estas URLs definidas aquí por lo que tal vez ni si quiera vale mucho la pena tener custom fonts.

src/schema/purchaseOrder/actions.tsx Outdated Show resolved Hide resolved
@@ -35,6 +35,9 @@ const isOwnerOfPurchaseOrder = async ({
const isOwner = await DB.query.purchaseOrdersSchema.findFirst({
where: (po, { eq, and }) =>
and(eq(po.id, purchaseOrderId), eq(po.userId, user.id)),
columns: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘🏼 me parece overkill, pero no estoy en contra

subject: "Tus tickets están listos 🎉 | 9punto5",
});
} else {
await sendTransactionalHTMLEmail(this.resend, this.logger, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es necesario twekear el estilo, mejor dejarlo si no necesitamos borarlo

{
name: purchaseOrder.user.name ?? purchaseOrder.user.username,
email: purchaseOrder.user.email,
if (communityInfo.name === "9punto5") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

email,
}: {
DB: ORM_TYPE;
type SendPurchaseOrderSuccessfulEmailArgs = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sacar la informacion de la BDD tiene q ser... 150ms? al ojo? Por ahora, no buscaría optimizar llamadas o performance (aka, evitar hacer consultas, etc) sino, hacer la experiencia de desarrollo mas facil por ahora.

Si esta, dale dejemoslo, pero 300ms no van a causar un drop de uso.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants