Skip to content

Commit

Permalink
fix: update code step
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Feb 18, 2024
1 parent d02d07a commit 03719de
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions functions/src/utils/document-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ export async function onDocumentChange(
id: string,
settings: Settings
) {
const document = firestore.doc("companies-2024/" + id);
console.log(`onDocumentChange ${id}: ${JSON.stringify(before.status)} -> ${JSON.stringify(after.status)}`);
const status = after.status;
if (status.generated === StatusEnum.PENDING) {
if (!!after.address && !!after.zipCode && !!after.city && !!after.siret && !!after.representant && !!after.role) {
return firestore.doc("companies-2024/" + id).update({
return document.update({
status: {
...status,
generated: StatusEnum.DONE,
Expand All @@ -52,14 +53,14 @@ export async function onDocumentChange(
await generateAndStoreProformaInvoiceAndConvention(after, id, settings, configurationFromFirestore);
await generateAndStoreInvoice(firestore, after, id, settings, configurationFromFirestore);

return firestore.doc("companies-2024/" + id).update({
return document.update({
...partnershipGenerated(after, id, settings, status.generated === StatusEnum.DONE),
});
} else if (before.status.validated !== status.validated && status.validated === StatusEnum.DONE) {
const sponsoringType = after.sponsoring.toLowerCase();
await decreasePacks(firestore, sponsoringType);

return firestore.doc("companies-2024/" + id).update({
return document.update({
...partnershipValidated(after, id, settings, status.validated === StatusEnum.DONE),
});
} else if (before.status.validated !== status.validated && status.validated === StatusEnum.REFUSED) {
Expand All @@ -68,7 +69,7 @@ export async function onDocumentChange(
const emailTemplate = ConventionSignedFactory(id, settings);
sendEmailToAllContacts(after, emailTemplate, settings);

return firestore.doc("companies-2024/" + id).update({
return document.update({
status: {
...status,
paid: StatusEnum.PENDING,
Expand All @@ -77,16 +78,15 @@ export async function onDocumentChange(
} else if (before.status.paid !== status.paid && status.paid === StatusEnum.DONE) {
const emailTemplate = PaymentReceivedFactory(after, id, settings);
sendEmailToAllContacts(after, emailTemplate, settings);
return firestore.doc("companies-2024/" + id).update({
return document.update({
public: true,
status: {
...status,
received: StatusEnum.PENDING,
code: StatusEnum.PENDING,
},
});
} else if (status.received === StatusEnum.PENDING && after.twitter && after.linkedin !== "") {
return firestore.doc("companies-2024/" + id).update({
return document.update({
status: {
...status,
received: StatusEnum.DONE,
Expand All @@ -103,14 +103,21 @@ export async function onDocumentChange(
settings
);
sendEmailToAllContacts(after, emailTemplate, settings);

return document.update({
status: {
...status,
code: StatusEnum.PENDING,
},
});
}
} else if (status.code === StatusEnum.PENDING && before.billetWebUrl !== after.billetWebUrl) {
const emailTemplate = BilletWebUrlFactory(after, settings);
sendEmailToAllContacts(after, emailTemplate, settings);
} else if (status.code === StatusEnum.PENDING) {
const billetWebDone = after.billetWebDone;
if (billetWebDone) {
return firestore.doc("companies-2024/" + id).update({
return document.update({
status: {
...status,
code: StatusEnum.DONE,
Expand Down

0 comments on commit 03719de

Please sign in to comment.