Skip to content

Commit 514d812

Browse files
committed
Ensure list don't have duplicates of flows
1 parent 57cc007 commit 514d812

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
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.5.8"
3+
version = "0.5.9"
44
author = "ThomasTJdev"
55
description = "Newsletter"
66
license = "AGPL v3"

src/routes/routes_lists.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ proc(request: Request) =
231231
if flowID == "":
232232
resp Http400, "Flow ID not found, ID: " & flowIDRaw
233233

234+
#
235+
# Check if flow is already in list
236+
#
237+
var flowInList: bool
238+
pg.withConnection conn:
239+
flowInList = getValue(conn, sqlSelect(
240+
table = "lists",
241+
select = ["id"],
242+
where = ["id = ?", "flow_ids @> ARRAY[?]::int[]"]), listID, flowID).len() > 0
243+
244+
if flowInList:
245+
resp Http400, "Flow already in list"
246+
247+
#
248+
# Add flow to list
249+
#
234250
var users: seq[seq[string]]
235251
pg.withConnection conn:
236252
exec(conn, sqlUpdate(

0 commit comments

Comments
 (0)