diff --git a/src/lib/ae_posts/ae_posts__post.ts b/src/lib/ae_posts/ae_posts__post.ts index 2237fb94..4f62bb77 100644 --- a/src/lib/ae_posts/ae_posts__post.ts +++ b/src/lib/ae_posts/ae_posts__post.ts @@ -703,14 +703,14 @@ export function db_save_ae_obj_li__post( // post_comment_kv: obj.post_comment_kv, // post_comment_li: obj.post_comment_li, }); - // console.log(`Put obj with ID: ${obj.post_id_random} or ${id_random}`); + if (log_lvl) { + console.log(`Put obj with ID: ${obj.post_id_random} or ${id_random}`); + } } catch (error) { let status = `Failed to put ${obj.post_id_random}: ${error}`; console.log(status); + return false; } - - // const id_random = await db_posts.post.put(obj); - // console.log(`Put obj with ID: ${obj.post_id_random}`); }); return true; diff --git a/src/lib/ae_posts/ae_posts__post_comment.ts b/src/lib/ae_posts/ae_posts__post_comment.ts index 62c6ca6e..2131c9d3 100644 --- a/src/lib/ae_posts/ae_posts__post_comment.ts +++ b/src/lib/ae_posts/ae_posts__post_comment.ts @@ -41,7 +41,8 @@ export async function load_ae_obj_id__post_comment( // This is expecting a list db_save_ae_obj_li__post_comment({ obj_type: 'post_comment', - obj_li: [post_comment_obj_get_result] + obj_li: [post_comment_obj_get_result], + log_lvl: log_lvl }); } @@ -121,7 +122,9 @@ export async function load_ae_obj_li__post_comment( if (post_comment_obj_li_get_result) { if (try_cache) { db_save_ae_obj_li__post_comment({ - obj_type: 'post_comment', obj_li: post_comment_obj_li_get_result + obj_type: 'post_comment', + obj_li: post_comment_obj_li_get_result, + log_lvl: log_lvl }); } return post_comment_obj_li_get_result; @@ -181,7 +184,8 @@ export async function create_ae_obj__post_comment( db_save_ae_obj_li__post_comment( { obj_type: 'post_comment', - obj_li: [post_comment_obj_create_result] + obj_li: [post_comment_obj_create_result], + log_lvl: log_lvl }); } return post_comment_obj_create_result; @@ -288,7 +292,8 @@ export async function update_ae_obj__post_comment( if (post_comment_obj_update_result) { if (try_cache) { db_save_ae_obj_li__post_comment({ - obj_type: 'post_comment', obj_li: [post_comment_obj_update_result] + obj_type: 'post_comment', obj_li: [post_comment_obj_update_result], + log_lvl: log_lvl }); } return post_comment_obj_update_result; @@ -315,7 +320,7 @@ export function db_save_ae_obj_li__post_comment( { obj_type, obj_li, - log_lvl=0 + log_lvl = 0 }: { obj_type: string, obj_li: any, @@ -365,14 +370,14 @@ export function db_save_ae_obj_li__post_comment( // From SQL view }); - // console.log(`Put obj with ID: ${obj.post_comment_id_random} or ${id_random}`); + if (log_lvl) { + console.log(`Put obj with ID: ${obj.post_comment_id_random} or ${id_random}`); + } } catch (error) { let status = `Failed to put ${obj.post_comment_id_random}: ${error}`; console.log(status); + return false; } - - // const id_random = await db_posts.comment.put(obj); - // console.log(`Put obj with ID: ${obj.post_comment_id_random}`); }); return true; diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte index b3298619..ea64b79b 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte @@ -6,7 +6,7 @@ import { fade } from 'svelte/transition'; import type { key_val } from '$lib/ae_stores'; import { ae_util } from '$lib/ae_utils/ae_utils'; // import { core_func } from '$lib/ae_core/ae_core_functions'; -// import { api } from '$lib/api'; +import { api } from '$lib/api'; import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores'; import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores'; import { posts_func } from '$lib/ae_posts/ae_posts_functions'; @@ -21,8 +21,7 @@ let disable_submit_btn = false; async function handle_submit_form(event: any) { if (log_lvl > 1) { - console.log('*** handle_submit_form() ***'); - console.log(event.target); + console.log('*** handle_submit_form() ***', event.target); } disable_submit_btn = true; @@ -40,7 +39,7 @@ async function handle_submit_form(event: any) { let post_comment_do: key_val = {}; if (!$idaa_slct.post_comment_id) { - post_comment_do['post_id_random'] = $ae_loc.post_id; + post_comment_do['post_id_random'] = $idaa_slct.post_id; post_comment_do['enable'] = true; } @@ -60,6 +59,7 @@ async function handle_submit_form(event: any) { post_comment_do['external_person_id'] = post_comment_di.external_person_id; post_comment_do['full_name'] = post_comment_di.full_name; post_comment_do['email'] = post_comment_di.email; + post_comment_do['notify'] = post_comment_do.notify; post_comment_do['hide'] = post_comment_di.hide; post_comment_do['priority'] = post_comment_di.priority; @@ -97,7 +97,7 @@ async function handle_submit_form(event: any) { api_cfg: $ae_api, post_id: $idaa_slct.post_id, data_kv: post_comment_do, - log_lvl: log_lvl + log_lvl: 2 }) .then(function (post_comment_obj_create_result) { if (!post_comment_obj_create_result) { @@ -106,6 +106,7 @@ async function handle_submit_form(event: any) { } $idaa_slct.post_comment_id = post_comment_obj_create_result.obj_id_random; + $idaa_slct.post_comment_obj = post_comment_obj_create_result; return post_comment_obj_create_result; }) @@ -114,10 +115,17 @@ async function handle_submit_form(event: any) { console.log(error); return false; }) - .finally(() => { - $idaa_slct.post_comment_obj = $lq__post_comment_obj; + .finally(async () => { disable_submit_btn = false; $idaa_sess.bb.show__inline_edit__post_comment_id = false; + + if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) { + send_staff_notification_email(); + } + + if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) { + send_poster_notification_email(); + } }); return prom_api__post_comment_obj; @@ -126,7 +134,7 @@ async function handle_submit_form(event: any) { api_cfg: $ae_api, post_comment_id: $idaa_slct.post_comment_id, data_kv: post_comment_do, - log_lvl: log_lvl + log_lvl: 1 }) .then(function (post_comment_obj_update_result) { if (!post_comment_obj_update_result) { @@ -134,6 +142,8 @@ async function handle_submit_form(event: any) { return false; } + $idaa_slct.post_comment_obj = post_comment_obj_update_result; + return post_comment_obj_update_result; }) .catch(function (error) { @@ -146,6 +156,14 @@ async function handle_submit_form(event: any) { $idaa_slct.post_comment_obj = $lq__post_comment_obj; disable_submit_btn = false; $idaa_sess.bb.show__inline_edit__post_comment_id = false; + + if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) { + send_staff_notification_email(); + } + + if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) { + send_poster_notification_email(); + } }); return prom_api__post_comment_obj; @@ -188,6 +206,81 @@ async function handle_delete_post_comment_obj( return prom_api__post_comment_obj; } + +function send_staff_notification_email() { + if (log_lvl) { + console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`); + } + + let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`; + + let body_html = ` +
A BB post comment has been created or updated.
+Use this link to view the post.
+ Copy and paste link: ${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}
Your BB post has been commented on.
+Use this link to view the post.
+ Copy and paste link: ${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}