Skip to content

Feature/send summary as email #995

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

Open
wants to merge 19 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,45 @@ msgstr ""
msgid "Scheduler"
msgstr ""

msgid "Sending"
msgstr ""

msgid "Share error information"
msgstr ""

msgid "Discard"
msgstr ""

msgid "Send"
msgstr ""

msgid "To"
msgstr ""

msgid "Message"
msgstr ""

msgid "I have read and accept the "
msgstr ""

msgid "EyeSeeTea S.L. Privacy Policy"
msgstr ""

msgid " paying special attention to the section about "
msgstr ""

msgid "share sesitive data"
msgstr ""

msgid "Email"
msgstr ""

msgid "Email sent successfully"
msgstr ""

msgid "Message sent successfully"
msgstr ""

msgid "The token is empty"
msgstr ""

Expand Down Expand Up @@ -1110,9 +1149,6 @@ msgstr ""
msgid "Property"
msgstr ""

msgid "Message"
msgstr ""

msgid "Program Indicators / Program Data Elements"
msgstr ""

Expand Down
44 changes: 40 additions & 4 deletions i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2025-06-02T07:06:35.778Z\n"
"POT-Creation-Date: 2025-06-20T05:31:37.220Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -1001,6 +1001,45 @@ msgstr ""
msgid "Scheduler"
msgstr ""

msgid "Sending"
msgstr ""

msgid "Share error information"
msgstr ""

msgid "Discard"
msgstr ""

msgid "Send"
msgstr ""

msgid "To"
msgstr ""

msgid "Message"
msgstr ""

msgid "I have read and accept the "
msgstr ""

msgid "EyeSeeTea S.L. Privacy Policy"
msgstr ""

msgid " paying special attention to the section about "
msgstr ""

msgid "share sesitive data"
msgstr ""

msgid "Email"
msgstr ""

msgid "Email sent successfully"
msgstr ""

msgid "Message sent successfully"
msgstr ""

msgid "The token is empty"
msgstr ""

Expand Down Expand Up @@ -1113,9 +1152,6 @@ msgstr ""
msgid "Property"
msgstr ""

msgid "Message"
msgstr ""

msgid "Program Indicators / Program Data Elements"
msgstr ""

Expand Down
44 changes: 40 additions & 4 deletions i18n/fr.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2025-06-02T07:06:35.778Z\n"
"POT-Creation-Date: 2025-06-20T05:31:37.220Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -1001,6 +1001,45 @@ msgstr ""
msgid "Scheduler"
msgstr ""

msgid "Sending"
msgstr ""

msgid "Share error information"
msgstr ""

msgid "Discard"
msgstr ""

msgid "Send"
msgstr ""

msgid "To"
msgstr ""

msgid "Message"
msgstr ""

msgid "I have read and accept the "
msgstr ""

msgid "EyeSeeTea S.L. Privacy Policy"
msgstr ""

msgid " paying special attention to the section about "
msgstr ""

msgid "share sesitive data"
msgstr ""

msgid "Email"
msgstr ""

msgid "Email sent successfully"
msgstr ""

msgid "Message sent successfully"
msgstr ""

msgid "The token is empty"
msgstr ""

Expand Down Expand Up @@ -1113,9 +1152,6 @@ msgstr ""
msgid "Property"
msgstr ""

msgid "Message"
msgstr ""

msgid "Program Indicators / Program Data Elements"
msgstr ""

Expand Down
44 changes: 40 additions & 4 deletions i18n/pt.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2025-06-02T07:06:35.778Z\n"
"POT-Creation-Date: 2025-06-20T05:31:37.220Z\n"
"PO-Revision-Date: 2020-07-10T06:53:30.625Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -1001,6 +1001,45 @@ msgstr ""
msgid "Scheduler"
msgstr ""

msgid "Sending"
msgstr ""

msgid "Share error information"
msgstr ""

msgid "Discard"
msgstr ""

msgid "Send"
msgstr ""

msgid "To"
msgstr ""

msgid "Message"
msgstr ""

msgid "I have read and accept the "
msgstr ""

msgid "EyeSeeTea S.L. Privacy Policy"
msgstr ""

msgid " paying special attention to the section about "
msgstr ""

msgid "share sesitive data"
msgstr ""

msgid "Email"
msgstr ""

msgid "Email sent successfully"
msgstr ""

msgid "Message sent successfully"
msgstr ""

msgid "The token is empty"
msgstr ""

Expand Down Expand Up @@ -1113,9 +1152,6 @@ msgstr ""
msgid "Property"
msgstr ""

msgid "Message"
msgstr ""

msgid "Program Indicators / Program Data Elements"
msgstr ""

Expand Down
27 changes: 26 additions & 1 deletion src/data/common/utils/api-futures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Future, FutureData } from "../../../domain/common/entities/Future";
import { CancelableResponse } from "../../../types/d2-api";

type SpecificError = {
response: {
data: {
message: string;
};
};
};

/**
* @description This file is refactored
*/
Expand All @@ -9,13 +17,30 @@ export function apiToFuture<Data>(res: CancelableResponse<Data>): FutureData<Dat
res.getData()
.then(resolve)
.catch((err: unknown) => {
if (err instanceof Error) {
if (isSpecificError(err)) {
reject(new Error(err.response.data.message));
} else if (err instanceof Error) {
reject(err);
} else {
console.error("apiToFuture:uncatched", err);

reject(new Error("Unknown error"));
}
});
return res.cancel;
});
}

const isSpecificError = (err: unknown): err is SpecificError => {
if (!err || typeof err !== "object") return false;

const specificError = err as { response?: { data?: { message?: unknown } } };

return (
typeof specificError.response === "object" &&
specificError.response !== null &&
typeof specificError.response.data === "object" &&
specificError.response.data !== null &&
typeof specificError.response.data.message === "string"
);
};
33 changes: 33 additions & 0 deletions src/data/comunications/AttachedFileD2ApiRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Future, FutureData } from "../../domain/common/entities/Future";
import { AttachedFile, AttachedFileInput, ObjectSharing } from "../../domain/comunications/entities/AttachedFile";
import { AttachedFileRepository } from "../../domain/comunications/repositories/AttachedFileRepository";

import { D2Api } from "../../types/d2-api";
import { apiToFuture } from "../common/utils/api-futures";

export class AttachedFileD2ApiRepository implements AttachedFileRepository {
constructor(private api: D2Api) {}

create(file: AttachedFileInput): FutureData<AttachedFile> {
return apiToFuture(this.api.files.upload(file))
.flatMap(({ id }) => {
return Future.joinObj({
id: Future.success(id),
sharing: this.postSharing(id, file.sharing),
});
})
.map(({ id }) => {
const isDev = process.env.NODE_ENV === "development";
const baseUrl = isDev ? process.env.REACT_APP_DHIS2_BASE_URL : this.api.baseUrl;
return { id, name: file.name, url: `${baseUrl}/api/documents/${id}/data`, sharing: file.sharing };
});
}

updateSharing(file: AttachedFile): FutureData<void> {
return this.postSharing(file.id, file.sharing);
}

private postSharing(id: string, sharing: ObjectSharing) {
return apiToFuture(this.api.sharing.post({ id, type: "document" }, sharing)).map(() => undefined);
}
}
22 changes: 22 additions & 0 deletions src/data/comunications/EmailD2ApiRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Email } from "../../domain/comunications/entities/Email";
import { EmailRepository } from "../../domain/comunications/repositories/EmailRepository";
import { D2Api } from "../../types/d2-api";
import { FutureData } from "../../domain/common/entities/Future";
import { OutboundMessage } from "@eyeseetea/d2-api/api/email";
import { apiToFuture } from "../common/utils/api-futures";

export class EmailD2ApiRepository implements EmailRepository {
constructor(private readonly d2Api: D2Api) {}

send(message: Email): FutureData<void> {
return apiToFuture(this.d2Api.email.sendMessage(this.buildOutboundMessage(message)));
}

buildOutboundMessage(message: Email): OutboundMessage {
return {
subject: message.subject,
text: message.text,
recipients: message.recipients.map(recipient => recipient.value),
};
}
}
Loading