···6161 }
62626363 "-- Update an user's information as admin
6464-UPDATE public.user_account AS u
6565-SET
6464+update public.user_account as u
6565+set
6666 full_name = $2,
6767 email = $3,
6868 user_role = $4,
6969 registration = $5,
7070 is_active = $6,
7171- updated_at = CURRENT_TIMESTAMP
7272-WHERE u.id = $1
7373-RETURNING
7171+ updated_at = current_timestamp
7272+where u.id = $1
7373+returning
7474 u.id,
7575 u.full_name,
7676 u.email,
···114114 }
115115116116 "-- Count the total number of users in our system
117117-SELECT COUNT(u.id) AS total
118118-FROM public.user_account AS u;
117117+select count(u.id) as total
118118+from public.user_account as u;
119119"
120120 |> pog.query
121121 |> pog.returning(decoder)
+36-36
src/app/domain/brigade/sql.gleam
···3636 }
37373838 "-- Assign a list of members to a brigade
3939-SELECT b.inserted_user_id
4040-FROM public.assign_brigade_members($1, $2) AS b;
3939+select b.inserted_user_id
4040+from public.assign_brigade_members($1, $2) as b;
4141"
4242 |> pog.query
4343 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···7474 }
75757676 "-- Remove a brigade from the DataBase
7777-DELETE FROM public.brigade AS b
7878-WHERE b.id = $1
7979-RETURNING
7777+delete from public.brigade as b
7878+where b.id = $1
7979+returning
8080 b.id,
8181 b.brigade_name;
8282"
···115115 }
116116117117 "-- Register a new brigade into the database
118118-INSERT INTO public.brigade AS b (
118118+insert into public.brigade as b (
119119 leader_id,
120120 brigade_name,
121121 vehicle_code,
122122 is_active
123123-) VALUES (
123123+) values (
124124 $1,
125125 $2,
126126 $3,
127127 $4
128128-) RETURNING
128128+) returning
129129 b.id,
130130 b.created_at;
131131"
···175175 }
176176177177 "-- Find all registered brigades
178178-SELECT
178178+select
179179 b.id,
180180 b.brigade_name,
181181- u.full_name AS leader_name,
181181+ u.full_name as leader_name,
182182 b.is_active
183183-FROM public.brigade AS b
184184-LEFT JOIN public.user_account AS u
185185- ON b.leader_id = u.id;
183183+from public.brigade as b
184184+left join public.user_account as u
185185+ on b.leader_id = u.id;
186186"
187187 |> pog.query
188188 |> pog.returning(decoder)
···227227 }
228228229229 "-- Find details about a specific brigade
230230-SELECT
230230+select
231231 b.id,
232232 b.brigade_name,
233233- u.id AS leader_name,
233233+ u.id as leader_name,
234234 b.is_active
235235-FROM public.brigade AS b
236236-INNER JOIN public.user_account AS u
237237- ON b.leader_id = u.id
238238-WHERE b.id = $1;
235235+from public.brigade as b
236236+inner join public.user_account as u
237237+ on b.leader_id = u.id
238238+where b.id = $1;
239239"
240240 |> pog.query
241241 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···268268 }
269269270270 "-- Find the id of all members assigned a specific brigade
271271-SELECT u.id
272272-FROM public.user_account AS u
273273-INNER JOIN public.brigade_membership AS bm
274274- ON u.id = bm.user_id
275275-WHERE bm.brigade_id = $1;
271271+select u.id
272272+from public.user_account as u
273273+inner join public.brigade_membership as bm
274274+ on u.id = bm.user_id
275275+where bm.brigade_id = $1;
276276"
277277 |> pog.query
278278 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···307307 }
308308309309 "-- Find all members of a brigade
310310-SELECT
310310+select
311311 u.id,
312312 u.full_name,
313313 u.user_role
314314-FROM public.user_account AS u
315315-INNER JOIN public.brigade_membership AS bm
316316- ON u.id = bm.user_id
317317-WHERE bm.brigade_id = $1;
314314+from public.user_account as u
315315+inner join public.brigade_membership as bm
316316+ on u.id = bm.user_id
317317+where bm.brigade_id = $1;
318318"
319319 |> pog.query
320320 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···348348 }
349349350350 "-- Replace all brigade members
351351-SELECT b.inserted_user_id
352352-FROM public.replace_brigade_members($1, $2) AS b;
351351+select b.inserted_user_id
352352+from public.replace_brigade_members($1, $2) as b;
353353"
354354 |> pog.query
355355 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···388388 }
389389390390 "-- Set the brigade is_active status to ON or OFF
391391-UPDATE public.brigade AS b
392392-SET
391391+update public.brigade as b
392392+set
393393 is_active = $2,
394394- updated_at = CURRENT_TIMESTAMP
395395-WHERE b.id = $1
396396-RETURNING
394394+ updated_at = current_timestamp
395395+where b.id = $1
396396+returning
397397 b.id,
398398 b.is_active,
399399 b.updated_at;
+9-9
src/app/domain/dashboard/sql.gleam
···4444 }
45454646 "-- Retrieve stats for the Dashboard page
4747-SELECT
4848- (SELECT count FROM public.vw_count_active_brigades)
4949- AS active_brigades_count,
5050- (SELECT count FROM public.vw_count_total_occurrences)
5151- AS total_occurrences_count,
5252- (SELECT count FROM public.vw_count_active_occurrences)
5353- AS active_occurrences_count,
5454- (SELECT count FROM public.vw_count_recent_occurrences)
5555- AS recent_occurrences_count;
4747+select
4848+ (select count from public.vw_count_active_brigades)
4949+ as active_brigades_count,
5050+ (select count from public.vw_count_total_occurrences)
5151+ as total_occurrences_count,
5252+ (select count from public.vw_count_active_occurrences)
5353+ as active_occurrences_count,
5454+ (select count from public.vw_count_recent_occurrences)
5555+ as recent_occurrences_count;
5656"
5757 |> pog.query
5858 |> pog.returning(decoder)
+13-13
src/app/domain/notification/sql.gleam
···3333 }
34343535 "-- Find the active notifications from an user
3636-SELECT np.notification_type
3737-FROM public.user_notification_preference AS np
3838-WHERE
3636+select np.notification_type
3737+from public.user_notification_preference as np
3838+where
3939 np.user_id = $1
4040- AND np.enabled = TRUE;
4040+ and np.enabled = true;
4141"
4242 |> pog.query
4343 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···7474 }
75757676 "-- Find the notification preferences for an user
7777-SELECT
7777+select
7878 np.notification_type,
7979 np.enabled
8080-FROM public.user_notification_preference AS np
8181-WHERE np.user_id = $1;
8080+from public.user_notification_preference as np
8181+where np.user_id = $1;
8282"
8383 |> pog.query
8484 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···120120 }
121121122122 "-- Update user notification preference
123123-UPDATE public.user_notification_preference AS np
124124-SET
123123+update public.user_notification_preference as np
124124+set
125125 enabled = $3,
126126- updated_at = CURRENT_TIMESTAMP
127127-WHERE
126126+ updated_at = current_timestamp
127127+where
128128 np.user_id = $1
129129- AND np.notification_type = $2
130130-RETURNING
129129+ and np.notification_type = $2
130130+returning
131131 new.notification_type,
132132 new.enabled;
133133"
+47-47
src/app/domain/occurrence/sql.gleam
···3636 }
37373838 "-- Assign as list of brigades as participants of a occurrence
3939-SELECT ob.inserted_brigade_id
4040-FROM public.assign_occurrence_brigades($1, $2) AS ob;
3939+select ob.inserted_brigade_id
4040+from public.assign_occurrence_brigades($1, $2) as ob;
4141"
4242 |> pog.query
4343 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···7373 }
74747575 "-- Remove an occurrence from the database
7676-DELETE FROM public.occurrence AS o
7777-WHERE o.id = $1
7878-RETURNING o.id;
7676+delete from public.occurrence as o
7777+where o.id = $1
7878+returning o.id;
7979"
8080 |> pog.query
8181 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···133133 }
134134135135 "-- Inserts a new occurrence into the database
136136-INSERT INTO public.occurrence AS o (
136136+insert into public.occurrence as o (
137137 applicant_id,
138138 occurrence_category,
139139 occurrence_subcategory,
···141141 description,
142142 occurrence_location,
143143 reference_point
144144-) VALUES (
144144+) values (
145145 $1,
146146 $2,
147147 $3,
···150150 $6,
151151 $7
152152)
153153-RETURNING
153153+returning
154154 o.id,
155155 o.occurrence_category,
156156 o.priority,
···239239240240 "-- Retrieves all occurrences associated with a user,
241241-- including detailed category information and resolution status.
242242-SELECT
242242+select
243243 o.id,
244244 o.resolved_at,
245245 o.priority,
246246 o.occurrence_category,
247247 o.occurrence_location,
248248- o.description AS details,
249249- u.full_name AS applicant_name,
248248+ o.description as details,
249249+ u.full_name as applicant_name,
250250 o.created_at,
251251 o.arrived_at,
252252- u.registration AS applicant_registration,
252252+ u.registration as applicant_registration,
253253 o.applicant_id,
254254255255 (
256256- SELECT JSON_AGG(JSON_BUILD_OBJECT(
256256+ select json_agg(json_build_object(
257257 'id', b.id,
258258 'brigade_name', b.brigade_name,
259259 'leader_full_name', leader_u.full_name,
260260 'vehicle_code', b.vehicle_code
261261- )) FROM public.occurrence_brigade AS ob
262262- INNER JOIN public.brigade AS b
263263- ON ob.brigade_id = b.id
264264- INNER JOIN public.user_account AS leader_u
265265- ON b.leader_id = leader_u.id
266266- WHERE ob.occurrence_id = o.id
267267- ) AS brigade_list
261261+ )) from public.occurrence_brigade as ob
262262+ inner join public.brigade as b
263263+ on ob.brigade_id = b.id
264264+ inner join public.user_account as leader_u
265265+ on b.leader_id = leader_u.id
266266+ where ob.occurrence_id = o.id
267267+ ) as brigade_list
268268269269-FROM public.occurrence AS o
270270-INNER JOIN public.user_account AS u
271271- ON o.applicant_id = u.id
272272-WHERE o.applicant_id = $1;
269269+from public.occurrence as o
270270+inner join public.user_account as u
271271+ on o.applicant_id = u.id
272272+where o.applicant_id = $1;
273273"
274274 |> pog.query
275275 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···302302 }
303303304304 "-- Find all users that participated in a occurrence
305305-SELECT DISTINCT participant.user_id
306306-FROM public.brigade_membership AS participant
307307-INNER JOIN public.occurrence_brigade AS ob
308308- ON participant.brigade_id = ob.brigade_id
309309-WHERE ob.occurrence_id = $1
310310-ORDER BY participant.user_id;
305305+select distinct participant.user_id
306306+from public.brigade_membership as participant
307307+inner join public.occurrence_brigade as ob
308308+ on participant.brigade_id = ob.brigade_id
309309+where ob.occurrence_id = $1
310310+order by participant.user_id;
311311"
312312 |> pog.query
313313 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···370370 }
371371372372 "-- Find all occurrences from the last 24 hours
373373-SELECT
373373+select
374374 o.id,
375375 o.created_at,
376376 o.description,
···378378 o.occurrence_subcategory,
379379 o.occurrence_location,
380380 o.reference_point
381381-FROM public.occurrence AS o
382382-WHERE o.created_at >= (NOW() - '1 day'::INTERVAL);
381381+from public.occurrence as o
382382+where o.created_at >= (now() - '1 day'::interval);
383383"
384384 |> pog.query
385385 |> pog.returning(decoder)
···417417 }
418418419419 "-- Mark a occurrence as unresolved
420420-UPDATE public.occurrence
421421-SET
422422- resolved_at = NULL,
423423- updated_at = CURRENT_TIMESTAMP
424424-WHERE id = $1
425425-RETURNING
420420+update public.occurrence
421421+set
422422+ resolved_at = null,
423423+ updated_at = current_timestamp
424424+where id = $1
425425+returning
426426 id,
427427 resolved_at,
428428 updated_at;
···459459 }
460460461461 "-- Replace all assigned brigades
462462-SELECT o.inserted_brigade_id
463463-FROM public.assign_occurrence_brigades($1, $2) AS o;
462462+select o.inserted_brigade_id
463463+from public.assign_occurrence_brigades($1, $2) as o;
464464"
465465 |> pog.query
466466 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···502502 }
503503504504 "-- Mark a occurrence as resolved
505505-UPDATE public.occurrence
506506-SET
507507- resolved_at = CURRENT_TIMESTAMP,
508508- updated_at = CURRENT_TIMESTAMP
509509-WHERE id = $1
510510-RETURNING
505505+update public.occurrence
506506+set
507507+ resolved_at = current_timestamp,
508508+ updated_at = current_timestamp
509509+where id = $1
510510+returning
511511 id,
512512 resolved_at,
513513 updated_at;
+1-1
src/app/domain/role/sql.gleam
···3131 }
32323333 "-- Find all available user roles
3434-SELECT UNNEST(ENUM_RANGE(NULL::public.USER_ROLE_ENUM)) AS available_role;
3434+select unnest(enum_range(null::public.user_role_enum)) as available_role;
3535"
3636 |> pog.query
3737 |> pog.returning(decoder)
+53-53
src/app/domain/user/sql.gleam
···3535 }
36363737 "-- Remove and user from the database
3838-DELETE FROM public.user_account AS u
3939-WHERE u.id = $1
4040-RETURNING u.id, u.full_name;
3838+delete from public.user_account as u
3939+where u.id = $1
4040+returning u.id, u.full_name;
4141"
4242 |> pog.query
4343 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···8888 }
89899090 "-- Find all users on the database
9191-SELECT
9191+select
9292 u.id,
9393 u.full_name,
9494 u.registration,
9595 u.email,
9696 u.user_role,
9797 u.is_active
9898-FROM public.user_account AS u;
9898+from public.user_account as u;
9999"
100100 |> pog.query
101101 |> pog.returning(decoder)
···132132 }
133133134134 "-- Inserts a new user into the database
135135-INSERT INTO public.user_account AS u
135135+insert into public.user_account as u
136136(
137137 full_name,
138138 registration,
···141141 password_hash,
142142 user_role
143143)
144144-VALUES ($1, $2, $3, $4, $5, $6)
145145-RETURNING u.id;
144144+values ($1, $2, $3, $4, $5, $6)
145145+returning u.id;
146146"
147147 |> pog.query
148148 |> pog.parameter(pog.text(arg_1))
···190190191191 "-- Retrieves detailed information about fellow brigade members
192192-- for a given user, including their names and role details.
193193-SELECT
193193+select
194194 u.id,
195195 u.full_name,
196196 u.user_role,
197197 crew.brigade_id
198198-FROM public.query_crew_members($1) AS crew
199199-INNER JOIN public.user_account AS u
200200- ON crew.member_id = u.id;
198198+from public.query_crew_members($1) as crew
199199+inner join public.user_account as u
200200+ on crew.member_id = u.id;
201201"
202202 |> pog.query
203203 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···234234235235 "-- Retrieves a user's ID and password hash from their registration
236236-- number for authentication purposes.
237237-SELECT
237237+select
238238 u.id,
239239 u.password_hash,
240240 u.user_role
241241-FROM public.user_account AS u
242242-WHERE u.registration = $1;
241241+from public.user_account as u
242242+where u.registration = $1;
243243"
244244 |> pog.query
245245 |> pog.parameter(pog.text(arg_1))
···272272 }
273273274274 "-- Find all occurrences a user participated in
275275-SELECT u.id
276276-FROM public.user_account AS u
277277-INNER JOIN public.brigade_membership AS bm
278278- ON u.id = bm.user_id
279279-INNER JOIN public.occurrence_brigade AS ob
280280- ON bm.brigade_id = ob.brigade_id
281281-WHERE ob.occurrence_id = $1;
275275+select u.id
276276+from public.user_account as u
277277+inner join public.brigade_membership as bm
278278+ on u.id = bm.user_id
279279+inner join public.occurrence_brigade as ob
280280+ on bm.brigade_id = ob.brigade_id
281281+where ob.occurrence_id = $1;
282282"
283283 |> pog.query
284284 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···311311 }
312312313313 "-- Find all brigades an user is assigned to
314314-SELECT bm.brigade_id
315315-FROM public.brigade_membership AS bm
316316-WHERE bm.user_id = $1;
314314+select bm.brigade_id
315315+from public.brigade_membership as bm
316316+where bm.user_id = $1;
317317"
318318 |> pog.query
319319 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···346346 }
347347348348 "-- Retrieves a user's ID from their registration number.
349349-SELECT u.id
350350-FROM public.user_account AS u
351351-WHERE u.registration = $1;
349349+select u.id
350350+from public.user_account as u
351351+where u.registration = $1;
352352"
353353 |> pog.query
354354 |> pog.parameter(pog.text(arg_1))
···381381 }
382382383383 "-- Retrieves a user's full name by their user ID.
384384-SELECT u.full_name
385385-FROM public.user_account AS u
386386-WHERE u.id = $1;
384384+select u.full_name
385385+from public.user_account as u
386386+where u.id = $1;
387387"
388388 |> pog.query
389389 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···416416 }
417417418418 "-- Find the password hash from an user
419419-SELECT u.password_hash
420420-FROM public.user_account AS u
421421-WHERE u.id = $1;
419419+select u.password_hash
420420+from public.user_account as u
421421+where u.id = $1;
422422"
423423 |> pog.query
424424 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···470470 }
471471472472 "-- Find basic information about an user account
473473-SELECT
473473+select
474474 u.id,
475475 u.full_name,
476476 u.registration,
477477 u.user_role,
478478 u.email,
479479 u.phone
480480-FROM public.user_account AS u
481481-WHERE u.id = $1;
480480+from public.user_account as u
481481+where u.id = $1;
482482"
483483 |> pog.query
484484 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···511511 }
512512513513 "-- Find user access level
514514-SELECT u.user_role
515515-FROM
516516- public.user_account AS u
517517-WHERE u.id = $1;
514514+select u.user_role
515515+from
516516+ public.user_account as u
517517+where u.id = $1;
518518"
519519 |> pog.query
520520 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···535535 let decoder = decode.map(decode.dynamic, fn(_) { Nil })
536536537537 "-- Set an new value to the password of an user
538538-UPDATE public.user_account
539539-SET
538538+update public.user_account
539539+set
540540 password_hash = $2,
541541- updated_at = CURRENT_TIMESTAMP
542542-WHERE id = $1;
541541+ updated_at = current_timestamp
542542+where id = $1;
543543"
544544 |> pog.query
545545 |> pog.parameter(pog.text(uuid.to_string(arg_1)))
···578578 }
579579580580 "-- Update an authenticated user profile
581581-UPDATE public.user_account AS u SET
581581+update public.user_account as u set
582582 full_name = $2,
583583 email = $3,
584584 phone = $4
585585-WHERE u.id = $1
586586-RETURNING
585585+where u.id = $1
586586+returning
587587 u.full_name,
588588 u.email,
589589 u.phone;
···624624 }
625625626626 "-- Update an user `is_active` field
627627-UPDATE public.user_account AS u
628628-SET
627627+update public.user_account as u
628628+set
629629 is_active = $2,
630630- updated_at = CURRENT_TIMESTAMP
631631-WHERE u.id = $1
632632-RETURNING u.id, u.is_active;
630630+ updated_at = current_timestamp
631631+where u.id = $1
632632+returning u.id, u.is_active;
633633"
634634 |> pog.query
635635 |> pog.parameter(pog.text(uuid.to_string(arg_1)))