Skip to content

Commit 22578e3

Browse files
authored
Merge pull request #4 from ThomasTJdev/bug/ttj/send-mail-to-list
Bug/ttj/send mail to list
2 parents c1942e4 + bdaabd2 commit 22578e3

File tree

4 files changed

+27
-39
lines changed

4 files changed

+27
-39
lines changed

nimletter.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.4.0"
3+
version = "0.4.1"
44
author = "ThomasTJdev"
55
description = "Newsletter"
66
license = "AGPL v3"

src/routes/routes_event.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,11 @@ proc(request: Request) =
8888
if userID == "":
8989
resp Http400, "User not found"
9090

91-
let mailID = getMailIDfromIdent(mail)
92-
if mailID == "":
93-
resp Http400, "Mail not found"
91+
let mailID = if mail == "": "" else: getMailIDfromIdent(mail)
9492

9593
pg.withConnection conn:
9694
# For a specific mailID
97-
if mail != "":
95+
if mailID != "":
9896
if getValue(conn, sqlSelect(
9997
table = "mails",
10098
select = [

src/routes/routes_mail.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,6 @@ proc(request: Request) =
466466
listID = @"listID"
467467
email = @"email"
468468

469-
echo email.isValidEmail()
470-
471469
var
472470
mailData: seq[string]
473471
contactData: seq[string]
@@ -526,4 +524,6 @@ proc(request: Request) =
526524
elif listExists:
527525
createPendingEmailToAllListContacts(listID, mailID)
528526

527+
resp Http200, "Mail sent to listID: " & listID
528+
529529
)

src/scheduling/schedule_mail.nim

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,44 +59,34 @@ proc createPendingEmail*(
5959
"NULL"
6060
)
6161

62-
let argsData = @[
63-
userID,
64-
listID,
65-
flowID,
66-
flowStepID,
67-
mailID,
68-
triggerType,
69-
status,
70-
scheduledFor
71-
]
72-
73-
var args = @[
74-
userID,
75-
listID,
76-
flowID,
77-
flowStepID,
78-
mailID,
79-
triggerType,
80-
status
81-
]
62+
var args = @[userID]
63+
var data = @["user_id"]
64+
if listID != "":
65+
data.add("list_id")
66+
args.add(listID)
67+
if flowID != "":
68+
data.add("flow_id")
69+
args.add(flowID)
70+
if flowStepID != "":
71+
data.add("flow_step_id")
72+
args.add(flowStepID)
73+
if mailID != "":
74+
data.add("mail_id")
75+
args.add(mailID)
76+
if triggerType != "":
77+
data.add("trigger_type")
78+
args.add(triggerType)
79+
if status != "":
80+
data.add("status")
81+
args.add(status)
8282
if scheduledFor != "NULL":
83+
data.add("scheduled_for")
8384
args.add(scheduledFor)
8485

8586
pg.withConnection conn:
86-
8787
exec(conn, sqlInsert(
8888
table = "pending_emails",
89-
data = [
90-
"user_id",
91-
"list_id",
92-
"flow_id",
93-
"flow_step_id",
94-
"mail_id",
95-
"trigger_type",
96-
"status",
97-
"scheduled_for",
98-
],
99-
args = argsData
89+
data = data,
10090
), args)
10191

10292

0 commit comments

Comments
 (0)