Can send shipping notifications to non-registered users

main
Ashelyn Dawn 3 years ago
parent f739d7a5fb
commit 9a07cbb4d6

@ -195,9 +195,8 @@ router.post('/:uuid/ship/tracking', ensureAdmin, parseJSON, async (req, res) =>
const user = await db.order.getUser(order.uuid)
// TODO: Handle sending email notifications to non-registered users
if(user)
await email.sendShippingNotification(user, order)
const emailAddress = user?.email || await db.order.getRecipient(order)
await email.sendShippingNotification(emailAddress, order)
res.json(order)
})
@ -231,9 +230,8 @@ router.post('/:uuid/ship/easypost', ensureAdmin, parseJSON, async (req, res) =>
const user = await db.order.getUser(order.uuid)
// TODO: Handle sending email notifications to non-registered users
if(user)
await email.sendShippingNotification(user, updatedOrder)
const emailAddress = user?.email || await db.order.getRecipient(order)
await email.sendShippingNotification(emailAddress, updatedOrder)
res.json(updatedOrder)
})

@ -382,4 +382,24 @@ order.shipEasyPost = async ( uuid, length, width, height, weight, items ) => {
returnType: 'order',
single: true
})
}
order.getRecipient = async (order) => {
const query = {
text: 'select * from sos.v_order_recipient where order_uuid = $1',
values: [order.uuid]
}
debug(query);
const {rows} = await pg.query(query)
if(rows.length < 1)
return null;
if(rows.length > 1)
throw new Error("Got more than one email for order")
const [row] = rows;
return row.order_recipient_email;
}

@ -56,7 +56,7 @@ create or replace view sos.v_category as
"child_category".category_name as child_category_name,
"child_category".category_urlslug as child_category_urlslug,
"child_category".category_description as child_category_description,
coalesce("child_item_counts".category_item_count, 0)::int4 as child_category_item_count,
coalesce("child_item_counts".category_item_count, 0)::int4 as child_category_item_count,
"parent_category".category_uuid as parent_category_uuid,
"parent_category".category_name as parent_category_name,
"parent_category".category_urlslug as parent_category_urlslug,
@ -70,7 +70,7 @@ create or replace view sos.v_category as
category_item_category_uuid as category_uuid,
count(category_item_item_uuid) as category_item_count
from sos."category_item"
group by category_uuid
group by category_uuid
) child_item_counts on "child_category".category_uuid = "child_item_counts".category_uuid
left join sos."category" "parent_category" on "parent_category_link".category_category_parent_uuid = "parent_category".category_uuid
left join sos."category_item" on "category".category_uuid = "category_item".category_item_category_uuid
@ -199,4 +199,13 @@ create or replace view sos.v_user as
from sos."session"
where session_cart is not null
order by session_user_uuid, session_time_last_active desc
) "last_cart" on "user".user_uuid = "last_cart".session_user_uuid;
) "last_cart" on "user".user_uuid = "last_cart".session_user_uuid;
create or replace view sos.v_order_recipient as
select distinct on (order_uuid)
order_uuid,
payment_recipient_email as order_recipient_email
from
sos.v_order
where payment_time is not null
order by order_uuid, payment_time desc;

@ -61,9 +61,9 @@ email.sendNoSuchAccount = async email => {
await sendgrid.send(msg)
}
email.sendShippingNotification = async (user, order) => {
email.sendShippingNotification = async (emailAddress, order) => {
const msg = {
to: user.email,
to: emailAddress,
from: {email: 'notifications@email.societyofsocks.us', name: 'Society of Socks'},
templateId: 'd-dde1867d5a80426bb08b9e9a078643ff',
dynamic_template_data: {

Loading…
Cancel
Save