diff --git a/api/orders.js b/api/orders.js
index a3c67b1..30ba988 100644
--- a/api/orders.js
+++ b/api/orders.js
@@ -162,3 +162,8 @@ router.post('/:uuid/ship/tracking', ensureAdmin, parseJSON, async (req, res) =>
const order = await db.order.setTracking(req.params.uuid, req.body.code, req.body.date || null)
res.json(order)
})
+
+router.post('/:uuid/ship/delivery', ensureAdmin, parseJSON, async (req, res) => {
+ const order = await db.order.setDelivery(req.params.uuid, req.body.description, req.body.date || null)
+ res.json(order)
+})
diff --git a/db/models/order.js b/db/models/order.js
index bdaaa9f..5cfbd16 100644
--- a/db/models/order.js
+++ b/db/models/order.js
@@ -250,3 +250,11 @@ order.setTracking = (uuid, trackingCode, shipDate) =>
returnType: 'order',
single: true
})
+
+ order.setDelivery = (uuid, description, deliveryDate) =>
+ dbUtil.executeFunction({
+ name: 'set_delivery_by_hand',
+ params: [uuid, description, deliveryDate],
+ returnType: 'order',
+ single: true
+ })
diff --git a/db/sql/3-functions.sql b/db/sql/3-functions.sql
index 25cb61e..b9ee927 100644
--- a/db/sql/3-functions.sql
+++ b/db/sql/3-functions.sql
@@ -943,3 +943,50 @@ begin
return query select * from sos.v_order where order_uuid = _order_uuid;
end; $function$;
+
+create or replace function sos.set_delivery_by_hand(_order_uuid uuid, _description text, _date_delivered timestamptz)
+ returns setof sos.v_order
+ language plpgsql
+as $function$
+declare
+ _delivery_uuid uuid;
+begin
+ -- Ensure order has no delivery
+ select order_delivery_uuid into _delivery_uuid
+ from sos."order" where order_uuid = _order_uuid;
+ if _delivery_uuid is not null then
+ raise 'Order already has a delivery record';
+ end if;
+
+ -- Create delivery
+ insert into sos."delivery" (
+ delivery_type
+ ) values (
+ 'hand_delivered'
+ ) returning delivery_uuid into _delivery_uuid;
+
+ -- Default date
+ if _date_delivered is null then
+ _date_delivered := now();
+ end if;
+
+ -- Create delivery subtype record
+ insert into sos."delivery_hand_delivered" (
+ delivery_uuid,
+ delivery_type,
+ delivery_description,
+ delivery_date_delivered
+ ) values (
+ _delivery_uuid,
+ 'hand_delivered',
+ _description,
+ _date_delivered
+ );
+
+ -- Update order
+ update sos."order" set
+ order_delivery_uuid = _delivery_uuid
+ where order_uuid = _order_uuid;
+
+ return query select * from sos.v_order where order_uuid = _order_uuid;
+end; $function$;
diff --git a/pages/admin/orders/[id]/index.js b/pages/admin/orders/[id]/index.js
index 27df8a8..c546d9b 100644
--- a/pages/admin/orders/[id]/index.js
+++ b/pages/admin/orders/[id]/index.js
@@ -15,10 +15,10 @@ export default function Order({order}){
return (
<>
-
Use this to enter delivery information for packages delivered in-person or at a con.
+In case we ever have future corespondence with this person, please be sure to describe where, when, and to who you gave the package.
+Use this to enter tracking information for packages shipped by-hand (via USPS)
val.length > 0} type="text" name="code" hint="Please enter the USPS Tracking code" />