Skip to content

Commit

Permalink
feat: add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Nov 21, 2024
1 parent 7cff233 commit 0229380
Show file tree
Hide file tree
Showing 109 changed files with 1,234 additions and 2,005 deletions.
7 changes: 6 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
public/.angular
public/dist
public/dist
*.pdf
*.ico
.DS_Store
*.png
.gitkeep
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 180,
"importOrder": ["^[./]"],
"importOrderSeparation": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrderParserPlugins": ["typescript", "decorators-legacy"]
}
31 changes: 0 additions & 31 deletions functions/.eslintrc.js

This file was deleted.

16 changes: 0 additions & 16 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@types/jest": "^29.5.8",
"@types/markdown-pdf": "^9.0.5",
"firebase-functions-test": "^3.1.0",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"typescript": "^4.9.0"
},
Expand Down
16 changes: 8 additions & 8 deletions functions/src/__tests__/utils/mail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Email } from "../../model";
import { getFrom } from "../../utils/mail";
import { Email } from '../../model';
import { getFrom } from '../../utils/mail';

it("should return from parameters for email", () => {
it('should return from parameters for email', () => {
const email = {
from: "mail",
fromname: "GDG Lille",
from: 'mail',
fromname: 'GDG Lille'
} as Email;

expect(getFrom(email)).toEqual({
From: {
Email: "mail",
Name: "GDG Lille",
},
Email: 'mail',
Name: 'GDG Lille'
}
});
});
19 changes: 9 additions & 10 deletions functions/src/cms4devfest-gdg.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { getConfiguration } from "./v3/infrastructure/getConfiguration";
import { sendToWebhooks } from "./v3/domain/sendToWebhooks";
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

import { sendToWebhooks } from './v3/domain/sendToWebhooks';
import { getConfiguration } from './v3/infrastructure/getConfiguration';

const firestore = admin.firestore();

export const onSendChangesToWebHooks = functions.firestore
.document("companies-2025/{companyId}")
.onUpdate(async (changes) => {
const configuration = await getConfiguration(firestore);
sendToWebhooks(configuration, changes);
});
export const onSendChangesToWebHooks = functions.firestore.document('companies-2025/{companyId}').onUpdate(async (changes) => {
const configuration = await getConfiguration(firestore);
sendToWebhooks(configuration, changes);
});
172 changes: 69 additions & 103 deletions functions/src/cms4devfest.ts
Original file line number Diff line number Diff line change
@@ -1,131 +1,101 @@
import { Timestamp } from "@google-cloud/firestore";
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import relanceConventionSignee from "./emails/template/relanceConventionSignee";
import { StatusEnum, onDocumentChange } from "./utils/document-change";
import { sendEmailToAllContacts } from "./utils/mail";
import { Timestamp } from '@google-cloud/firestore';
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

import relanceInformationsComplementaires from "./emails/template/relanceInformationsComplementaires";
import relancePaiement from "./emails/template/relancePaiement";
import { Company, Configuration } from "./model";
import {
sendNewPartnerToOrganizationTeam,
sendWelcomeEmail,
} from "./v3/domain/email";
import { getConfiguration } from "./v3/infrastructure/getConfiguration";
import relanceConventionSignee from './emails/template/relanceConventionSignee';
import relanceInformationsComplementaires from './emails/template/relanceInformationsComplementaires';
import relancePaiement from './emails/template/relancePaiement';
import { Company, Configuration } from './model';
import { StatusEnum, onDocumentChange } from './utils/document-change';
import { sendEmailToAllContacts } from './utils/mail';
import { sendNewPartnerToOrganizationTeam, sendWelcomeEmail } from './v3/domain/email';
import { getConfiguration } from './v3/infrastructure/getConfiguration';

admin.initializeApp();
const firestore = admin.firestore();

function addCreationDate(id: string) {
return firestore
.doc("companies-2025/" + id)
.doc('companies-2025/' + id)
.update({
creationDate: Timestamp.fromDate(new Date()),
creationDate: Timestamp.fromDate(new Date())
})
.catch((err) => console.log(err));
}

function updatesStatus(id: string, company: any, status: any) {
return firestore
.doc("companies-2025/" + id)
.doc('companies-2025/' + id)
.update({
...company,
status,
status
})
.catch((err) => console.log(err));
}

export const getAllPublicSponsors = functions.https.onRequest(
async (req, resp) => {
const edition = req.query.edition;
const data = await firestore.collection("companies-" + edition).get();
const partners = data.docs
.map((d) => ({
id: d.id,
...d.data(),
}))
.filter(
(p: any) =>
p.status.paid === StatusEnum.DONE &&
p.public &&
!!p.siteUrl &&
!!p.logoUrl
);
resp.send(partners);
}
);
export const getAllPublicSponsors = functions.https.onRequest(async (req, resp) => {
const edition = req.query.edition;
const data = await firestore.collection('companies-' + edition).get();
const partners = data.docs
.map((d) => ({
id: d.id,
...d.data()
}))
.filter((p: any) => p.status.paid === StatusEnum.DONE && p.public && !!p.siteUrl && !!p.logoUrl);
resp.send(partners);
});

const relance = (
emailFactory: (
partner: Record<string, any>,
configuration: Configuration
) => any,
partners: any[],
configuration: Configuration
) => {
const relance = (emailFactory: (partner: Record<string, any>, configuration: Configuration) => any, partners: any[], configuration: Configuration) => {
partners.forEach((c: any) => {
const emailTemplate = emailFactory(c, configuration);
sendEmailToAllContacts(c, emailTemplate, configuration);
});
};

export const relancePartnaireConventionASigner = functions.https.onCall(
async () => {
const configuration = await getConfiguration(firestore);
const data = await firestore.collection("companies-2025").get();
const partners = data.docs
.map((d) => d.data())
.filter((p) => p.status.sign === StatusEnum.PENDING);
relance(relanceConventionSignee, partners, configuration);
}
);
export const relancePartnaireConventionASigner = functions.https.onCall(async () => {
const configuration = await getConfiguration(firestore);
const data = await firestore.collection('companies-2025').get();
const partners = data.docs.map((d) => d.data()).filter((p) => p.status.sign === StatusEnum.PENDING);
relance(relanceConventionSignee, partners, configuration);
});

export const relancePartnaireFacture = functions.https.onCall(async () => {
const configuration = await getConfiguration(firestore);
const data = await firestore.collection("companies-2025").get();
const partners = data.docs
.map((d) => d.data())
.filter((p) => p.status.paid === StatusEnum.PENDING);
const data = await firestore.collection('companies-2025').get();
const partners = data.docs.map((d) => d.data()).filter((p) => p.status.paid === StatusEnum.PENDING);
relance(relancePaiement, partners, configuration);
});

export const relanceInformationPourGeneration = functions.https.onCall(
async () => {
const configuration = await getConfiguration(firestore);
const data = await firestore.collection("companies-2025").get();
const partners = data.docs
.map((d) => d.data())
.filter((p) => p.status.generated === StatusEnum.PENDING);
relance(relanceInformationsComplementaires, partners, configuration);
}
);
export const relanceInformationPourGeneration = functions.https.onCall(async () => {
const configuration = await getConfiguration(firestore);
const data = await firestore.collection('companies-2025').get();
const partners = data.docs.map((d) => d.data()).filter((p) => p.status.generated === StatusEnum.PENDING);
relance(relanceInformationsComplementaires, partners, configuration);
});

export const newPartner = functions.firestore
.document("companies-2025/{companyId}")
.onCreate(async (snap) => {
const configuration = await getConfiguration(firestore);
const company: Company = snap.data() as Company;
const id = snap.id;
export const newPartner = functions.firestore.document('companies-2025/{companyId}').onCreate(async (snap) => {
const configuration = await getConfiguration(firestore);
const company: Company = snap.data() as Company;
const id = snap.id;

if (!company.name) {
return;
}
await addCreationDate(id);
await sendWelcomeEmail(company, snap.id, configuration);
await sendNewPartnerToOrganizationTeam(company, configuration);
if (!company.name) {
return;
}
await addCreationDate(id);
await sendWelcomeEmail(company, snap.id, configuration);
await sendNewPartnerToOrganizationTeam(company, configuration);

return updatesStatus(id, company, {
filled: "done",
validated: "pending",
});
return updatesStatus(id, company, {
filled: 'done',
validated: 'pending'
});
});

export const partnershipUpdated = functions
.runWith({
memory: "1GB",
memory: '1GB'
})
.firestore.document("companies-2025/{companyId}")
.firestore.document('companies-2025/{companyId}')
.onUpdate(async (changes) => {
const configuration = await getConfiguration(firestore);
const before = changes.before.data() as Company;
Expand All @@ -138,20 +108,16 @@ export const partnershipUpdated = functions
return onDocumentChange(firestore, before, after, id, configuration);
});

exports.updateConventionSignedUrlProperty = functions.storage
.object()
.onFinalize(async (object) => {
const name = object.name || "";
return admin
.storage()
.bucket()
.file(name)
.getSignedUrl({ action: "read", expires: "03-17-2025" })
.then(([url]) => {
return firestore
.doc("companies-2025/" + name.replace("signed/", ""))
.update({
conventionSignedUrl: url,
});
exports.updateConventionSignedUrlProperty = functions.storage.object().onFinalize(async (object) => {
const name = object.name || '';
return admin
.storage()
.bucket()
.file(name)
.getSignedUrl({ action: 'read', expires: '03-17-2025' })
.then(([url]) => {
return firestore.doc('companies-2025/' + name.replace('signed/', '')).update({
conventionSignedUrl: url
});
});
});
});
Loading

0 comments on commit 0229380

Please sign in to comment.