merged dev

This commit is contained in:
Vins 2023-09-25 14:44:57 +02:00
commit 702337d984
13 changed files with 1198 additions and 182 deletions

1075
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -62,6 +62,7 @@
"node-fetch": "^2.6.11",
"node-schedule": "^2.1.1",
"prisma-query": "^2.0.0",
"puppeteer": "^21.3.2",
"reflect-metadata": "^0.1.13",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",

View File

@ -17,6 +17,52 @@ export default class OfficeFoldersController extends ApiController {
super();
}
/**
* @description Download a folder anchoring proof document
*/
@Get("/api/v1/notary/anchors/download/:uid", [authHandler, ruleHandler, folderHandler])
protected async download(req: Request, response: Response) {
try {
const uid = req.params["uid"];
if (!uid) {
this.httpBadRequest(response, "No uid provided");
return;
}
const query = {
documents: {
include: {
files: true,
},
},
};
const officeFolderFound = await this.officeFoldersService.getByUid(uid, query);
if (!officeFolderFound) {
this.httpNotFoundRequest(response, "Office folder not found");
return;
}
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
const folderHashes = getFolderHashes(officeFolder);
if (folderHashes.length === 0) {
this.httpNotFoundRequest(response, "No file hash to anchor");
return;
}
const sortedHashes = [...folderHashes].sort();
const buffer = await this.secureService.download(sortedHashes);
this.httpSuccess(response, buffer);
} catch (error) {
this.httpInternalError(response, error);
return;
}
}
/**
* @description Create a new folder anchor
*/

View File

@ -5,10 +5,11 @@ import { Document } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
import { ETemplates } from "./Templates/EmailTemplates";
import MailchimpService from "@Services/common/MailchimpService/MailchimpService";
import { BackendVariables } from "@Common/config/variables/Variables";
@Service()
export default class EmailBuilder {
public constructor(private mailchimpService: MailchimpService ,private documentsService: DocumentsService){}
public constructor(private mailchimpService: MailchimpService ,private documentsService: DocumentsService, protected variables: BackendVariables){}
public async sendDocumentEmails(documentEntity: Documents){
if(documentEntity.document_status !== "ASKED" && documentEntity.document_status !== "REFUSED") return;
@ -17,19 +18,19 @@ export default class EmailBuilder {
if(!documentPrisma) throw new Error("Document not found");
const document = Document.hydrate<Document>(documentPrisma);
const to = document.depositor!.contact!.email;
const civility = this.getCivility(document.depositor!.contact!.civility);
const templateVariables = {
civility: document.depositor!.contact!.civility,
civility: civility,
last_name: document.depositor!.contact!.last_name,
office_name: document.folder!.office!.name,
link: "http://localhost:3000"
link: this.variables.APP_HOST
};
let templateName = ETemplates.DOCUMENT_ASKED;
let subject = "Document Asked";
let subject = "Documents demandés";
if(documentEntity.document_status === "REFUSED"){
templateName = ETemplates.DOCUMENT_REFUSED;
subject = "Document Refused";
subject = "Documents refusés";
}
this.mailchimpService.create({
@ -45,6 +46,40 @@ export default class EmailBuilder {
nbTrySend: null,
lastTrySendDate: null,
});
}
public async sendRecapEmails(usersToEmail: [{email: string, civility: string, last_name: string}]){
usersToEmail.forEach(user => {
const to = user.email;
const civility = this.getCivility(user.civility);
const templateVariables = {
civility: civility,
last_name: user.last_name,
link: this.variables.APP_HOST
};
const templateName = ETemplates.DOCUMENT_RECAP;
const subject = "Récapitulatif hebdomadaire";
this.mailchimpService.create({
templateName,
to,
subject,
templateVariables,
uid: "",
from: null,
cc: [],
cci: [],
sentAt: null,
nbTrySend: null,
lastTrySendDate: null,
});
});
}
public getCivility(civility: string){
if(civility === "MALE") return "Mr"
else return "Mme"
}
}

View File

@ -1,4 +1,5 @@
export const ETemplates = {
DOCUMENT_ASKED: "DOCUMENT_ASKED",
DOCUMENT_REFUSED: "DOCUMENT_REFUSED",
DOCUMENT_RECAP: "DOCUMENT_RECAP",
};

View File

@ -21,6 +21,7 @@ export default class DocumentsRepository extends BaseRepository {
* @description : Find many documents
*/
public async findMany(query: Prisma.DocumentsFindManyArgs) {
query.take = Math.min(query.take || this.defaultFetchRows, this.maxFetchRows);
return this.model.findMany(query);
}

View File

@ -1,17 +1,22 @@
import "module-alias/register";
import "reflect-metadata";
import { Container } from "typedi";
import { BackendVariables } from "@Common/config/variables/Variables";
import CronService from "@Services/common/CronService/CronService";
(async () => {
console.log("Cron started");
try {
const variables = await Container.get(BackendVariables).validate();
Container.get(CronService).archiveFiles();
await Container.get(CronService).updateUsers();
if(variables.ENV !== "dev"){
Container.get(CronService).sendMails();
Container.get(CronService).sendRecapMails();
}
} catch (e) {
console.error(e);
}

View File

@ -0,0 +1,122 @@
import BaseService from "@Services/BaseService";
import { Service } from "typedi";
import puppeteer from "puppeteer";
export interface AnchoringProofData {
rootHash: string;
anchoringTime: string;
txLink: string;
}
@Service()
export default class AnchoringProofService extends BaseService {
constructor() {
super();
}
private static svgTemplateDocument: string = `
<svg width="842" height="595" viewBox="0 0 842 595" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="842" height="595" fill="#FFFFFF"/>
<g filter="url(#filter0_d_4903_34411)">
<rect x="40" y="40" width="762" height="515" rx="8" fill="white"/>
<g clip-path="url(#clip0_4903_34411)">
<path d="M347.515 87.0484C347.531 86.6422 347.299 86.2272 346.8 86.0109L333.931 80.4455C332.896 79.9973 331.678 79.9973 330.641 80.4455L317.844 85.98C317.337 86.1985 317.098 86.618 317.112 87.033V112.454L319.988 113.82L321.707 112.99L329.847 116.379V118.103L332.341 119.286L334.858 118.072V116.396L342.986 113.012L344.696 113.82L347.522 112.456V87.0484H347.515Z" fill="#C5B2D4"/>
<path d="M332.339 119.409L329.736 118.175V116.455L321.707 113.112L319.985 113.943L317 112.523L317.004 86.9214C317.037 86.4733 317.335 86.0803 317.801 85.8772L330.6 80.3427C331.656 79.8858 332.918 79.8858 333.975 80.3427L346.844 85.9081C347.305 86.1068 347.594 86.4953 347.625 86.9369H347.627V112.525L344.694 113.94L342.981 113.132L334.968 116.47V118.141L332.341 119.409H332.339ZM329.955 118.033L332.339 119.164L334.747 118.002V116.322L334.815 116.294L342.986 112.892L344.692 113.697L347.408 112.386V87.1576H347.404V87.0428C347.421 86.641 347.179 86.2944 346.756 86.1112L333.887 80.5458C332.885 80.1131 331.687 80.1131 330.685 80.5458L317.886 86.0803C317.457 86.2657 317.208 86.619 317.219 87.0274V87.14V112.382L319.985 113.695L321.7 112.867L321.746 112.885L329.955 116.302V118.029V118.033Z" fill="#4E1480"/>
<path d="M329.574 114.592C329.191 114.592 328.804 114.515 328.439 114.358L320.079 110.766C319.01 110.307 318.319 109.252 318.319 108.08L318.312 92.2755C318.312 91.2887 318.8 90.3769 319.616 89.8338C320.432 89.2908 321.455 89.2003 322.354 89.5932L330.72 93.238C331.781 93.6994 332.468 94.7524 332.468 95.9202V111.672C332.468 112.654 331.982 113.566 331.171 114.109C330.689 114.431 330.134 114.594 329.576 114.594L329.574 114.592ZM328.697 113.749C329.39 114.047 330.18 113.974 330.808 113.555C331.435 113.135 331.811 112.431 331.811 111.669V95.918C331.811 95.0151 331.282 94.2027 330.46 93.8451L322.094 90.2003C321.401 89.8979 320.609 89.9685 319.977 90.388C319.345 90.8074 318.968 91.5138 318.968 92.2755L318.975 108.08C318.975 108.987 319.509 109.802 320.335 110.157L328.695 113.749H328.697Z" fill="white"/>
<path d="M332.601 98.7287V97.9008C332.601 97.8787 332.588 97.8611 332.568 97.8523L331.556 97.4107C331.521 97.3953 331.481 97.4218 331.481 97.4593V98.2872C331.481 98.3092 331.494 98.3269 331.514 98.3357L332.527 98.7772C332.562 98.7927 332.601 98.7662 332.601 98.7287Z" fill="white"/>
<path d="M332.549 99.1146C332.496 99.1146 332.446 99.1035 332.396 99.0815L331.385 98.6399C331.245 98.5803 331.155 98.4413 331.155 98.2867V97.4589C331.155 97.3286 331.219 97.2094 331.326 97.1366C331.433 97.0659 331.569 97.0549 331.687 97.1057L332.7 97.5472C332.84 97.6068 332.929 97.7459 332.929 97.9004V98.7282C332.929 98.8585 332.866 98.9777 332.756 99.0506C332.693 99.0925 332.621 99.1146 332.549 99.1146ZM331.812 98.1057L332.273 98.3066V98.0858L331.812 97.8849V98.1057Z" fill="white"/>
<path d="M332.638 111.686V110.858C332.638 110.836 332.625 110.818 332.605 110.809L331.593 110.368C331.558 110.352 331.518 110.379 331.518 110.416V111.244C331.518 111.266 331.532 111.284 331.551 111.293L332.564 111.734C332.599 111.75 332.638 111.723 332.638 111.686Z" fill="white"/>
<path d="M332.586 112.074C332.535 112.074 332.485 112.063 332.435 112.043L331.422 111.602C331.282 111.54 331.193 111.401 331.193 111.248V110.42C331.193 110.29 331.256 110.171 331.363 110.098C331.47 110.025 331.606 110.016 331.724 110.067L332.737 110.509C332.877 110.568 332.966 110.707 332.966 110.862V111.69C332.966 111.82 332.903 111.939 332.796 112.01C332.732 112.052 332.66 112.074 332.586 112.074ZM331.849 111.065L332.31 111.266V111.043L331.849 110.842V111.065Z" fill="white"/>
<path d="M322.914 97.0753C321.215 97.742 320.81 100.802 322.006 103.906C323.203 107.012 325.552 108.988 327.251 108.319C328.951 107.65 329.355 104.592 328.159 101.488C326.963 98.3845 324.613 96.4064 322.914 97.0753ZM325.781 102.76C325.762 102.687 325.738 102.614 325.709 102.541C325.652 102.391 325.58 102.254 325.501 102.133L325.908 99.0644C326.562 99.709 327.162 100.63 327.584 101.722C327.993 102.782 328.168 103.835 328.133 104.738L325.779 102.758L325.781 102.76ZM323.354 98.1637C323.925 97.9385 324.587 98.0864 325.237 98.5147L324.826 101.601C324.753 101.592 324.683 101.599 324.618 101.623C324.578 101.638 324.541 101.661 324.509 101.689L322.192 99.7399C322.38 98.9651 322.772 98.3911 323.351 98.1637H323.354ZM322.621 103.676C322.205 102.597 322.03 101.526 322.074 100.612L324.296 102.482C324.314 102.661 324.358 102.853 324.432 103.045C324.478 103.164 324.533 103.274 324.592 103.376L324.211 106.244C323.59 105.603 323.026 104.718 322.623 103.674L322.621 103.676ZM324.88 106.826L325.259 103.976C325.351 103.998 325.44 103.998 325.521 103.965C325.626 103.923 325.707 103.837 325.764 103.72L328.023 105.621C327.84 106.416 327.444 107.007 326.853 107.239C326.254 107.473 325.556 107.303 324.88 106.826Z" fill="white"/>
<path d="M325.329 102.461C325.639 102.967 325.637 103.534 325.342 103.715C325.047 103.896 324.544 103.631 324.268 103.106C323.975 102.547 323.968 102.044 324.242 101.867C324.561 101.664 325.009 101.945 325.329 102.461Z" fill="#3FA79E"/>
<path d="M427.367 94.3582C427.564 93.6076 427.892 92.8967 428.351 92.2234C428.81 91.5501 429.368 90.9607 430.024 90.4507C430.68 89.943 431.42 89.5456 432.238 89.2586C433.058 88.9716 433.928 88.8281 434.845 88.8281H439.635L438.979 91.5766H436.879C435.785 91.5766 434.878 91.8481 434.156 92.3868C433.434 92.9277 432.986 93.5855 432.811 94.356L432.122 97.1045H436.288L435.599 99.8529H431.433L428.054 113.662H422.608L427.365 94.356L427.367 94.3582Z" fill="#4E1480"/>
<path d="M439.932 94.3582C440.129 93.6076 440.457 92.8967 440.916 92.2234C441.376 91.5501 441.933 90.9607 442.59 90.4507C443.246 89.943 443.985 89.5456 444.803 89.2586C445.623 88.9716 446.494 88.8281 447.41 88.8281H452.2L451.544 91.5766H449.444C448.351 91.5766 447.443 91.8481 446.721 92.3868C445.999 92.9277 445.551 93.5855 445.376 94.356L444.687 97.1045H448.854L448.165 99.8529H443.998L440.619 113.662H435.173L439.93 94.356L439.932 94.3582Z" fill="#4E1480"/>
<path d="M463.882 94.3599L463.193 97.1084H461.126C460.032 97.1084 459.125 97.3799 458.403 97.9186C457.681 98.4594 457.222 99.1173 457.025 99.8877L453.646 113.663H448.167L451.546 99.9209C451.721 99.1923 452.032 98.4925 452.482 97.817C452.931 97.1437 453.484 96.5476 454.14 96.0288C454.796 95.51 455.54 95.1016 456.371 94.8036C457.202 94.5056 458.099 94.3555 459.061 94.3555H463.884L463.882 94.3599Z" fill="#4E1480"/>
<path d="M468.015 113.665C466.397 113.665 465.166 113.268 464.324 112.473C463.481 111.678 463.059 110.674 463.059 109.459C463.059 109.084 463.114 108.643 463.223 108.135L465.257 99.8563C465.454 99.1057 465.782 98.3949 466.242 97.7216C466.701 97.0482 467.259 96.4632 467.915 95.9665C468.571 95.4698 469.315 95.0791 470.146 94.7899C470.977 94.5029 471.852 94.3594 472.77 94.3594H476.904C478.523 94.3594 479.747 94.7523 480.579 95.536C481.41 96.3197 481.825 97.3198 481.825 98.534C481.825 98.9313 481.771 99.3839 481.661 99.8916L480.316 105.389H469.391L468.702 108.17C468.505 108.943 468.63 109.594 469.081 110.124C469.529 110.654 470.299 110.919 471.395 110.919H476.906L476.25 113.667H468.015V113.665ZM470.082 102.638H475.561L476.217 99.874C476.392 99.1057 476.283 98.4523 475.889 97.9158C475.496 97.3772 474.916 97.1101 474.15 97.1101C473.779 97.1101 473.407 97.1807 473.035 97.3242C472.663 97.4677 472.324 97.6642 472.018 97.9158C471.712 98.1675 471.445 98.4633 471.215 98.8033C470.986 99.1433 470.826 99.5009 470.741 99.874L470.085 102.638H470.082Z" fill="#4E1480"/>
<path d="M485.174 113.663V108.133H490.653V113.663H485.174Z" fill="#4E1480"/>
<path d="M498.819 94.3582H504.298L499.541 113.664H494.062L498.819 94.3582ZM500.165 88.8281H505.643L504.987 91.5766H499.508L500.165 88.8281Z" fill="#3FA79E"/>
<path d="M511.188 113.665C509.569 113.665 508.338 113.268 507.496 112.473C506.654 111.678 506.232 110.674 506.232 109.459C506.232 109.084 506.286 108.643 506.396 108.135L508.43 99.8563C508.627 99.1057 508.955 98.3949 509.414 97.7216C509.873 97.0482 510.431 96.4632 511.087 95.9665C511.743 95.4698 512.487 95.0791 513.318 94.7899C514.149 94.5029 515.024 94.3594 515.943 94.3594H520.077C521.695 94.3594 522.92 94.7567 523.751 95.5515C524.582 96.3462 524.998 97.3396 524.998 98.5318C524.998 98.9071 524.943 99.3486 524.834 99.8563L522.8 108.135C522.603 108.908 522.275 109.625 521.815 110.287C521.356 110.95 520.798 111.535 520.142 112.042C519.486 112.55 518.747 112.947 517.929 113.234C517.109 113.521 516.238 113.665 515.32 113.665H511.186H511.188ZM519.357 99.8894C519.554 99.1168 519.455 98.4611 519.062 97.9202C518.668 97.3794 518.088 97.1101 517.323 97.1101C516.557 97.1101 515.847 97.3816 515.19 97.9202C514.534 98.4611 514.108 99.119 513.911 99.8894L511.877 108.135C511.68 108.908 511.778 109.565 512.172 110.104C512.566 110.645 513.145 110.914 513.911 110.914C514.283 110.914 514.655 110.844 515.026 110.7C515.398 110.557 515.737 110.358 516.043 110.104C516.35 109.85 516.612 109.559 516.831 109.228C517.05 108.896 517.214 108.532 517.323 108.135L519.357 99.8894Z" fill="#3FA79E"/>
<path d="M416.906 96.1486C412.73 95.0691 408.376 98.0163 407.179 102.729C405.983 107.443 408.398 112.141 412.575 113.22C416.75 114.3 421.105 111.352 422.301 106.639C423.498 101.926 421.083 97.2281 416.906 96.1486ZM416.07 105.5C416.114 105.399 416.151 105.293 416.18 105.182C416.236 104.955 416.254 104.727 416.234 104.509L420.602 101.553C421.166 102.966 421.3 104.624 420.88 106.284C420.471 107.893 419.607 109.244 418.489 110.207L416.068 105.5H416.07ZM416.527 97.8198C417.931 98.1818 419.088 99.0538 419.891 100.222L415.497 103.195C415.364 103.107 415.217 103.041 415.055 102.999C414.957 102.972 414.858 102.959 414.76 102.955L412.378 98.3209C413.651 97.6652 415.101 97.4511 416.527 97.8198ZM408.678 103.131C409.093 101.493 409.981 100.122 411.127 99.1576L413.413 103.602C413.24 103.816 413.107 104.076 413.032 104.368C412.986 104.549 412.967 104.73 412.969 104.906L408.883 107.67C408.38 106.299 408.275 104.716 408.678 103.131ZM409.557 109.03L413.616 106.284C413.774 106.407 413.955 106.502 414.156 106.553C414.417 106.619 414.679 106.61 414.926 106.542L417.249 111.061C415.961 111.745 414.482 111.973 413.032 111.597C411.562 111.218 410.362 110.282 409.557 109.03Z" fill="#3FA79E"/>
<path d="M414.318 113.551C413.73 113.551 413.137 113.478 412.549 113.326C410.499 112.796 408.8 111.396 407.768 109.387C406.737 107.383 406.49 105.008 407.076 102.701C407.66 100.394 409.008 98.431 410.867 97.1727C412.73 95.9122 414.885 95.5104 416.936 96.0402C421.164 97.133 423.618 101.899 422.411 106.665C421.37 110.767 417.949 113.551 414.32 113.551H414.318ZM415.152 96.0336C413.715 96.0336 412.28 96.4839 410.989 97.3581C409.174 98.5856 407.859 100.504 407.289 102.758C406.718 105.012 406.956 107.33 407.962 109.288C408.966 111.242 410.615 112.599 412.603 113.114C416.713 114.178 421.018 111.259 422.196 106.612C423.375 101.965 420.991 97.3184 416.879 96.2565C416.309 96.1086 415.729 96.0358 415.149 96.0358L415.152 96.0336ZM414.434 111.884C413.953 111.884 413.474 111.825 413.006 111.703C411.569 111.332 410.311 110.403 409.465 109.089L409.406 108.999L413.62 106.147L413.684 106.195C413.837 106.314 414.003 106.398 414.185 106.445C414.419 106.504 414.657 106.502 414.898 106.434L414.983 106.409L417.398 111.105L417.301 111.156C416.394 111.637 415.412 111.882 414.434 111.882V111.884ZM409.708 109.061C410.523 110.279 411.709 111.14 413.061 111.491C414.408 111.84 415.803 111.674 417.102 111.014L414.869 106.672C414.62 106.727 414.373 106.725 414.13 106.663C413.946 106.617 413.774 106.535 413.614 106.42L409.71 109.063L409.708 109.061ZM418.459 110.381L415.95 105.504L415.972 105.456C416.015 105.354 416.05 105.255 416.077 105.155C416.129 104.948 416.147 104.734 416.129 104.52L416.123 104.456L420.657 101.387L420.707 101.513C421.297 102.994 421.398 104.698 420.989 106.312C420.587 107.895 419.749 109.273 418.563 110.29L418.459 110.381ZM416.193 105.495L418.526 110.032C419.622 109.052 420.399 107.749 420.777 106.257C421.164 104.734 421.083 103.129 420.554 101.72L416.35 104.564C416.361 104.782 416.341 104.999 416.287 105.208C416.263 105.303 416.232 105.398 416.193 105.493V105.495ZM408.828 107.84L408.78 107.71C408.249 106.257 408.177 104.665 408.57 103.105C408.973 101.515 409.856 100.082 411.055 99.0735L411.16 98.9851L413.542 103.615L413.496 103.67C413.325 103.882 413.205 104.124 413.137 104.394C413.096 104.562 413.074 104.732 413.078 104.902V104.961L408.831 107.838L408.828 107.84ZM408.677 103.131L408.782 103.158C408.411 104.628 408.463 106.125 408.938 107.5L412.857 104.849C412.857 104.679 412.881 104.509 412.923 104.343C412.993 104.067 413.113 103.815 413.279 103.592L411.09 99.3339C409.979 100.308 409.161 101.661 408.78 103.16L408.675 103.133L408.677 103.131ZM415.499 103.328L415.438 103.288C415.311 103.204 415.176 103.142 415.029 103.105C414.944 103.082 414.854 103.069 414.756 103.065H414.692L412.229 98.2743L412.328 98.2235C413.684 97.5259 415.145 97.3493 416.553 97.7136C417.942 98.0712 419.126 98.9189 419.981 100.16L420.044 100.252L415.497 103.33L415.499 103.328ZM414.83 102.848C414.92 102.855 415.003 102.871 415.084 102.89C415.228 102.928 415.366 102.985 415.495 103.063L419.736 100.193C418.918 99.0448 417.8 98.2633 416.499 97.9255C415.176 97.5833 413.804 97.7378 412.525 98.3692L414.828 102.848H414.83Z" fill="#3FA79E"/>
<path d="M358.639 88.8906H364.118L358.672 110.978H366.874L366.218 113.726H352.537L358.639 88.8906Z" fill="#4E1480"/>
<path d="M375.763 88.8906H389.443L388.787 91.6391H380.585L378.519 99.9507H385.999L385.343 102.699H377.862L375.796 110.978H383.997L383.341 113.726H369.661L375.763 88.8906Z" fill="#4E1480"/>
<path d="M395.644 108.196C395.447 108.968 395.546 109.626 395.939 110.165C396.333 110.706 396.913 110.975 397.678 110.975C399.275 110.975 400.423 110.048 401.123 108.193H403.846C403.277 110.048 402.402 111.434 401.221 112.35C400.04 113.267 398.422 113.724 396.366 113.724H394.955C393.337 113.724 392.105 113.326 391.263 112.531C390.421 111.737 389.999 110.732 389.999 109.518C389.999 109.143 390.054 108.701 390.163 108.193L392.197 99.9149C392.394 99.1643 392.722 98.4535 393.181 97.7802C393.641 97.1068 394.198 96.5218 394.855 96.0251C395.511 95.5284 396.254 95.1377 397.085 94.8485C397.917 94.5615 398.791 94.418 399.71 94.418H401.121C402.892 94.418 404.161 94.7337 404.926 95.3628C405.692 95.992 406.075 96.9346 406.075 98.1952C406.075 98.725 406.009 99.299 405.878 99.9171H403.155C403.395 98.0848 402.706 97.1686 401.088 97.1686C400.322 97.1686 399.612 97.4402 398.955 97.9788C398.299 98.5197 397.873 99.1776 397.676 99.948L395.642 108.193L395.644 108.196Z" fill="#4E1480"/>
<path d="M478.256 125.411C477.917 125.411 477.484 125.301 477.28 125.054V125.283H476.705V119.402H477.296V121.714C477.58 121.285 477.98 120.959 478.54 120.959C479.485 120.959 480.082 121.879 480.082 123.096C480.082 124.312 479.461 125.407 478.256 125.407V125.411ZM478.343 121.526C477.926 121.526 477.659 121.756 477.477 121.994C477.328 122.193 477.296 122.281 477.296 122.495V124.323C477.296 124.665 477.595 124.928 478.162 124.928C479.028 124.928 479.467 124.164 479.467 123.228C479.467 122.292 479.098 121.528 478.341 121.528L478.343 121.526Z" fill="#320756"/>
<path d="M482.54 125.579C482.304 126.285 481.911 126.921 480.872 127.001L480.824 126.469C481.469 126.46 481.871 126.047 482.044 125.42L480.524 121.082H481.169L482.005 123.641C482.162 124.117 482.296 124.57 482.344 124.722H482.359C482.414 124.499 482.54 124.087 482.683 123.619L483.455 121.084H484.015L482.543 125.581L482.54 125.579Z" fill="#320756"/>
<path d="M489.682 125.284V120.568C489.682 119.588 489.117 119.019 488.107 119.019C487.464 119.019 486.9 119.31 486.506 119.827C486.257 120.131 486.217 120.277 486.217 120.674V125.284H485.233V118.277H486.152V119.389C486.676 118.608 487.411 118.078 488.422 118.078C489.747 118.078 490.666 118.899 490.666 120.409V125.284H489.682Z" fill="#3FA79E"/>
<path d="M495.377 125.536C493.212 125.536 492.306 123.655 492.306 121.761C492.306 119.867 493.303 118.039 495.429 118.039C497.555 118.039 498.5 119.867 498.5 121.774C498.5 123.682 497.503 125.536 495.377 125.536ZM495.429 118.9C493.868 118.9 493.33 120.476 493.33 121.761C493.33 123.046 493.789 124.662 495.377 124.662C496.965 124.662 497.477 123.019 497.477 121.774C497.477 120.529 497.017 118.9 495.429 118.9Z" fill="#3FA79E"/>
<path d="M502.135 125.509C500.902 125.509 500.364 124.648 500.364 123.602V119.244H499.196V118.41H500.364V116.873L501.348 116.516V118.41H503.238V119.244H501.348V123.483C501.348 124.251 501.729 124.648 502.45 124.648C502.752 124.648 503.015 124.556 503.211 124.45L503.395 125.271C503.08 125.403 502.595 125.509 502.135 125.509Z" fill="#3FA79E"/>
<path d="M505.469 125.365C505.062 125.365 504.786 125.074 504.786 124.663C504.786 124.252 505.049 123.961 505.455 123.961C505.862 123.961 506.138 124.252 506.138 124.663C506.138 125.074 505.875 125.365 505.469 125.365Z" fill="#4E1480"/>
<path d="M507.568 125.285V115.934H508.644V125.285H507.568Z" fill="#4E1480"/>
<path d="M513.198 116.927V125.285H512.109V116.927H509.051V115.934H516.295V116.927H513.198Z" fill="#4E1480"/>
</g>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="12" letter-spacing="0.5px"><tspan x="333" y="187.364">[[ANCHORING_TIME]]</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="21" font-weight="600" letter-spacing="0em"><tspan x="258" y="163.136">Certificat de d&#xe9;p&#xf4;t international</tspan></text>
<text fill="#320756" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" font-weight="600" letter-spacing="0.5px"><tspan x="119" y="262">Hash :</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" letter-spacing="0.5px"><tspan x="267" y="261.5">b834ce9229ee2c2283c837685772a473</tspan></text>
<path d="M119 290H723" stroke="#E7E7E7"/>
<text fill="#320756" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="14" font-weight="600" letter-spacing="0.5px"><tspan x="119" y="327.091">D&#xe9;posant(s)</tspan></text>
<text fill="#320756" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" font-weight="600" letter-spacing="0.5px"><tspan x="119" y="356">Auteur :</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" letter-spacing="0.5px"><tspan x="267" y="356">Not.IT</tspan></text>
<text fill="#320756" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" font-weight="600" letter-spacing="0.5px"><tspan x="119" y="378">Partenaire technique :</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" letter-spacing="0.5px"><tspan x="267" y="377.5">Smart-Chain</tspan></text>
<path d="M119 406H723" stroke="#E7E7E7"/>
<text fill="#320756" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="14" font-weight="600" letter-spacing="0.5px"><tspan x="119" y="443.091">Explorateur blockchain</tspan></text>
<text fill="black" xml:space="preserve" style="white-space: pre" font-family="Inter" font-size="11" letter-spacing="0.5px" text-decoration="underline"><tspan x="119" y="472"><a href="https://tzstats.com/opYWLHH96gbV8HPajRqmoRx3UBVbr6iXz43kuHqm8ey4LLPWqeC">https://tzstats.com/opYWLHH96gbV8HPajRqmoRx3UBVbr6iXz43kuHqm8ey4LLPWqeC</a></tspan></text>
</g>
</svg>
`;
/**
* @description : Generate a PDF file from a SVG template from anchoring proof data
*/
public async generate(data: AnchoringProofData): Promise<Buffer> {
const browser = await puppeteer.launch();
const page = await browser.newPage();
var htmlContent = `
<html>
<body>
${AnchoringProofService.svgTemplateDocument}
</body>
</html>
`;
htmlContent = htmlContent.replace("[[ANCHORING_TIME]]", data.anchoringTime);
await page.setContent(htmlContent);
await page.addStyleTag({
content: `
@page {
size: A4 landscape;
margin: 0;
}
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
svg {
width: 100%;
height: 100%;
}
`,
});
const buffer = await page.pdf({
landscape: true,
printBackground: false,
format: "A4",
});
await browser.close();
return buffer;
}
}

View File

@ -84,6 +84,9 @@ export default class AuthService extends BaseService {
};
}
public generateAccessToken(user: any): string {
console.log("date now", Date.now());
console.log("date local", new Date().toLocaleString())
console.log("date iso",new Date().toISOString());
return jwt.sign({ ...user}, this.variables.ACCESS_TOKEN_SECRET, { expiresIn: "15m" });
}

View File

@ -10,7 +10,7 @@ export default class CronService {
constructor(private mailchimpService: MailchimpService, private filesService: FilesService, private idNotService: IdNotService) {}
public async sendMails() {
const cronJob = new CronJob("*/15 * * * *", async () => { // Every 15 minutes
const cronJob = new CronJob("*/15 * * * * *", async () => { // Every 15 seconds
try {
await this.mailchimpService.sendEmails();
} catch (e) {
@ -24,6 +24,21 @@ export default class CronService {
}
}
public async sendRecapMails() {
const cronJob = new CronJob("0 20 * * FRI", async () => { // Every friday at 20:00
try {
await this.mailchimpService.sendRecapEmails();
} catch (e) {
console.error(e);
}
});
// Start job
if (!cronJob.running) {
cronJob.start();
}
}
public async archiveFiles() {
const cronJob = new CronJob("0 0 * * MON", async () => { // Every monday at midnight
try {

View File

@ -114,9 +114,10 @@ export default class IdNotService extends BaseService {
code: code,
grant_type: "authorization_code",
});
console.log(query)
const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" });
const decodedToken = (await token.json()) as IIdNotToken;
console.log(decodedToken)
const decodedIdToken = jwt.decode(decodedToken.id_token) as IdNotJwtPayload;
return decodedIdToken;

View File

@ -1,9 +1,10 @@
import EmailRepository from "@Repositories/EmailRepository";
import BaseService from "@Services/BaseService";
import { Emails } from "@prisma/client";
import { Emails, PrismaClient } from "@prisma/client";
import { Service } from "typedi";
import MailchimpClient from "@mailchimp/mailchimp_transactional";
import { BackendVariables } from "@Common/config/variables/Variables";
// import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
@Service()
export default class MailchimpService extends BaseService {
@ -84,7 +85,11 @@ export default class MailchimpService extends BaseService {
}
private async sendEmail(email: Emails) {
console.log("sendEmail");
const apiKey = this.variables.MAILCHIMP_API_KEY;
console.log(apiKey);
const mailchimpApiClient = MailchimpClient(apiKey!);
await mailchimpApiClient.messages.sendTemplate({
@ -113,4 +118,17 @@ export default class MailchimpService extends BaseService {
};
});
}
public async sendRecapEmails() {
const prisma = new PrismaClient();
const usersToEmail = await prisma.$queryRaw
`SELECT DISTINCT c.email, c.civility, c.last_name
FROM Contacts c
JOIN Users u ON c.uid = u.contact_uid
JOIN office_folders of ON u.office_uid = of.office_uid
JOIN Documents d ON of.uid = d.folder_uid
WHERE d.document_status = 'DEPOSITED';`
console.log(usersToEmail);
}
}

View File

@ -1,10 +1,12 @@
import BaseService from "@Services/BaseService";
import { Service } from "typedi";
import { BackendVariables } from "@Common/config/variables/Variables";
import AnchoringProofService from "@Services/common/AnchoringProofService/AnchoringProofService";
import EAnchoringStatus from "le-coffre-resources/dist/Notary/EAnchoringStatus";
@Service()
export default class SecureService extends BaseService {
constructor(protected variables: BackendVariables) {
constructor(protected variables: BackendVariables, protected anchoringProofService: AnchoringProofService) {
super();
}
@ -56,4 +58,31 @@ export default class SecureService extends BaseService {
return await response.json();
}
/**
* @description : Download the anchoring proof document
* @throws {Error} If transaction is not verified on chain
*/
public async download(hash_sources: string[]) {
const anchor = await this.verify(hash_sources);
if (anchor.transactions.length === 0) {
throw new Error("No anchor found");
}
const transaction = anchor.transactions[0];
if (transaction.status !== EAnchoringStatus.VERIFIED_ON_CHAIN) {
throw new Error(`Transaction not verified on chain: ${transaction.status}`);
}
return this.anchoringProofService.generate({
rootHash: anchor.root_hash,
txLink: transaction.tx_link,
anchoringTime: new Date(transaction.anchoring_timestamp).toLocaleString("fr-FR", {
timeZone: "Europe/Paris",
timeZoneName: "short",
}),
});
}
}