create-fff-app 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- module App.Server.Workflows.Employees
2
-
3
- open FffStack.Server
4
- open Fable.Core
5
- open Fable.Core.JsInterop
6
- open App.Server.Domain.Employees
7
-
8
- [<Emit("crypto.randomUUID()")>]
9
- let private newId () : string = jsNative
10
-
11
- let getAll (db: ID1Database) : JS.Promise<Employee list> =
12
- queryAll<Employee> db
13
- "SELECT id, name, email, department, role, status, joined_at as joinedAt \
14
- FROM employees ORDER BY name ASC"
15
- [||]
16
-
17
- let getById (db: ID1Database) (id: string) : JS.Promise<Employee option> =
18
- queryOne<Employee> db
19
- "SELECT id, name, email, department, role, status, joined_at as joinedAt \
20
- FROM employees WHERE id = ?"
21
- [| id |]
22
-
23
- let create
24
- (db: ID1Database)
25
- (rawName: string)
26
- (rawEmail: string)
27
- (department: string)
28
- (role: string)
29
- (status: string)
30
- : JS.Promise<Result<Employee, string>> =
31
- promise {
32
- match EmployeeName.create rawName, WorkEmail.create rawEmail with
33
- | Error e, _ -> return Error e
34
- | _, Error e -> return Error e
35
- | Ok name, Ok email ->
36
- let id = newId ()
37
- let n = EmployeeName.value name
38
- let em = WorkEmail.value email
39
- let dep = department.Trim()
40
- let rol = role.Trim()
41
- let st = if status = "inactive" then "inactive" else "active"
42
- do! execute db
43
- "INSERT INTO employees (id, name, email, department, role, status, joined_at) \
44
- VALUES (?, ?, ?, ?, ?, ?, date('now'))"
45
- [| id; n; em; dep; rol; st |]
46
- |> Promise.map ignore
47
- return Ok { id = id; name = n; email = em; department = dep
48
- role = rol; status = st; joinedAt = "" }
49
- }
50
-
51
- let update
52
- (db: ID1Database)
53
- (id: string)
54
- (rawName: string)
55
- (rawEmail: string)
56
- (department: string)
57
- (role: string)
58
- (status: string)
59
- : JS.Promise<Result<Employee, string>> =
60
- promise {
61
- match EmployeeName.create rawName, WorkEmail.create rawEmail with
62
- | Error e, _ -> return Error e
63
- | _, Error e -> return Error e
64
- | Ok name, Ok email ->
65
- let n = EmployeeName.value name
66
- let em = WorkEmail.value email
67
- let dep = department.Trim()
68
- let rol = role.Trim()
69
- let st = if status = "inactive" then "inactive" else "active"
70
- do! execute db
71
- "UPDATE employees SET name = ?, email = ?, department = ?, role = ?, status = ? WHERE id = ?"
72
- [| n; em; dep; rol; st; id |]
73
- |> Promise.map ignore
74
- return Ok { id = id; name = n; email = em; department = dep
75
- role = rol; status = st; joinedAt = "" }
76
- }
77
-
78
- let delete (db: ID1Database) (id: string) : JS.Promise<bool> =
79
- promise {
80
- match! getById db id with
81
- | None -> return false
82
- | Some _ ->
83
- do! execute db "DELETE FROM employees WHERE id = ?" [| id |]
84
- |> Promise.map ignore
85
- return true
86
- }