Skip to content

Commit

Permalink
feat: add template email for offboarding that keeps forwarded emails (#…
Browse files Browse the repository at this point in the history
…762)

* fix: correct migrate file view project cost and rev

* feat: add template email for offboarding that keeps forwarded emails
  • Loading branch information
lmquang authored Nov 21, 2024
1 parent 2d124a5 commit bae4a98
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

-- +migrate Up
-- Drop dependent objects first
DROP VIEW IF EXISTS "public"."vw_project_cost_and_revenue";
DROP TABLE IF EXISTS "public"."cost_projections";

-- Now drop and recreate the types
DROP TYPE IF EXISTS "public"."cost_types";
CREATE TYPE "public"."cost_types" AS ENUM ('individual', 'sum');
DROP TYPE IF EXISTS "public"."amount_types";
CREATE TYPE "public"."amount_types" AS ENUM ('percentage', 'flat');

-- Table Definition
-- Recreate the table with the new type
CREATE TABLE "public"."cost_projections" (
"id" uuid NOT NULL DEFAULT uuid(),
"name" varchar(255) NOT NULL,
Expand All @@ -15,6 +19,7 @@ CREATE TABLE "public"."cost_projections" (
PRIMARY KEY ("id")
);

-- Recreate the view
CREATE OR REPLACE VIEW vw_project_cost_and_revenue AS
WITH project_data AS (
-- Summarize project salary and charge rate
Expand Down Expand Up @@ -88,7 +93,8 @@ SELECT
FROM project_data pd
LEFT JOIN cost_projection_calculations cpc ON cpc.project_id = pd.project_id;


-- +migrate Down
DROP VIEW IF EXISTS "vw_project_cost_and_revenue";
DROP TABLE IF EXISTS "cost_projections";
DROP VIEW IF EXISTS "public"."vw_project_cost_and_revenue";
DROP TABLE IF EXISTS "public"."cost_projections";
DROP TYPE IF EXISTS "public"."cost_types";
DROP TYPE IF EXISTS "public"."amount_types";
17 changes: 17 additions & 0 deletions pkg/controller/employee/update_employee_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

"gorm.io/gorm"
Expand Down Expand Up @@ -61,6 +62,22 @@ func (r *controller) UpdateEmployeeStatus(employeeID string, body UpdateWorkingS

// Do Off-boarding process
r.processOffBoardingEmployee(l, e)
if e.IsKeepFwdEmail {
name := e.FullName
if e.DisplayName != "" {
name = strings.Split(e.DisplayName, " ")[0]
}
offboardingEmail := model.OffboardingEmail{
Name: name,
TeamEmail: e.TeamEmail,
PersonalEmail: e.PersonalEmail,
}

if err := r.service.GoogleMail.SendOffboardingMail(&offboardingEmail); err != nil {
l.Errorf(err, "failed to send offboard mail", "employeeID", e.ID.String())
return nil, done(err)
}
}
}

return e, err
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/employees.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ func (e Employees) ToTeamEmailIDMap() map[string]UUID {

return rs
}

type OffboardingEmail struct {
Name string `json:"name"`
PersonalEmail string `json:"personalEmail"`
TeamEmail string `json:"teamEmail"`
}
26 changes: 26 additions & 0 deletions pkg/service/googlemail/google_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,29 @@ func (g *googleService) SendInvitationMail(invitation *model.InvitationEmail) (e
_, err = g.sendEmail(encodedEmail, id)
return err
}

// SendOffboardingMail ...
func (g *googleService) SendOffboardingMail(offboarding *model.OffboardingEmail) (err error) {
if err := g.ensureToken(g.appConfig.Google.TeamGoogleRefreshToken); err != nil {
return err
}

if err := g.prepareService(); err != nil {
return err
}

encodedEmail, err := composeMailContent(g.appConfig,
&MailParseInfo{
teamEmail,
"offboarding_keep_fwd_email.tpl",
&offboarding,
map[string]interface{}{},
})
if err != nil {
return err
}
id := g.appConfig.Google.TeamEmailID

_, err = g.sendEmail(encodedEmail, id)
return err
}
1 change: 1 addition & 0 deletions pkg/service/googlemail/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ type IService interface {
SendInvoiceOverdueMail(invoice *model.Invoice) (err error)
SendInvoiceThankYouMail(invoice *model.Invoice) (err error)
SendPayrollPaidMail(p *model.Payroll) (err error)
SendOffboardingMail(offboarding *model.OffboardingEmail) (err error)
}
36 changes: 36 additions & 0 deletions pkg/templates/offboarding_keep_fwd_email.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Mime-Version: 1.0
From: "Team @ Dwarves Foundation" <team@d.foundation>
To: {{.PersonalEmail}}
Subject: Continue Using Your DF Email
Content-Type: multipart/mixed; boundary=main

--main
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">
<div>Hi <b>{{.Name}}</b>,<div>
<div dir=3D"ltr">
<div><br></div>
<div>
We appreciate the efforts you put into your role at Dwarves Foundation.
While your journey with DF has concluded, we'd like to offer a small way to stay connected: you can retain your DF email alias {{.TeamEmail}}.
</div>
<div><br></div>
<div><br></div>
<div>
This alias will forward incoming messages to your personal email {{.PersonalEmail}},
ensuring continuity and a professional touch for your correspondence.</div><br>
<div><br></div>
</div>
<div>If you have any questions, please feel free to get in touch.</div>
<div><br></div>
<div>Wishing you all the best,</div>
</div>
</div>
</div>
<div><br></div>-- <br>
{{ template "signature.tpl" }}
</div>

--main--

0 comments on commit bae4a98

Please sign in to comment.