import { Injectable } from "@angular/core"; import { Api } from "./api"; import { Observable } from "rxjs"; import { Email, EmailTemplate, IRslt } from "../../public-api"; import { SendGridEmail } from "../../tff-models/src/models/emails/sendgrid.email"; @Injectable({ providedIn: 'root' }) export class EmailService{ get route(){ return this.api.base + 'emails/' } constructor(private api:Api){} setToken(token:string){ this.api.token = token; } post(email: Email): Observable> { return this.api.post(this.route + 'email', email) } postTemplate(template: EmailTemplate): Observable> { return this.api.post(this.route + 'template', template) } async postSendGridEmail(email:SendGridEmail): Promise { try { const options = { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(email) }; const response = await fetch('https://qxqd5q46ugkyq2es7wbrzr3lfi0jseof.lambda-url.us-east-1.on.aws/api/email/sendgrid', options).then(response => response.json()).then(response => { if (response.success) { return true } else { return false } }); return response } catch (e) { return false; } } }