11import { assertRequestBody , defineRoute , Structure } from "gruber" ;
22
33import {
4+ AssetRecord ,
5+ AssetTable ,
46 LabelRecord ,
57 LabelTable ,
68 PersonRecord ,
@@ -21,12 +23,12 @@ import {
2123 useStore ,
2224} from "../lib/mod.ts" ;
2325import {
26+ _assertConferenceData ,
2427 _diffRelationship ,
2528 _diffResource ,
2629 _getRelated ,
2730 _performDiff ,
2831 _totalDiffs ,
29- _assertConferenceData ,
3032} from "./admin-lib.ts" ;
3133
3234// The shape of the accepted HTTP request body
@@ -47,13 +49,8 @@ const _Request = Structure.object({
4749 people : Structure . array (
4850 Structure . object ( {
4951 id : Structure . string ( ) ,
50- ...PersonTable . fields ( [
51- "avatar_id" ,
52- "bio" ,
53- "name" ,
54- "subtitle" ,
55- "metadata" ,
56- ] ) ,
52+ avatar_id : Structure . union ( [ Structure . null ( ) , Structure . string ( ) ] ) ,
53+ ...PersonTable . fields ( [ "bio" , "name" , "subtitle" , "metadata" ] ) ,
5754 } ) ,
5855 ) ,
5956 sessions : Structure . array (
@@ -94,6 +91,12 @@ const _Request = Structure.object({
9491 ...SessionLinkTable . fields ( [ "title" , "url" , "metadata" ] ) ,
9592 } ) ,
9693 ) ,
94+ assets : Structure . array (
95+ Structure . object ( {
96+ id : Structure . string ( ) ,
97+ ...AssetTable . fields ( [ "title" , "url" , "metadata" ] ) ,
98+ } ) ,
99+ ) ,
97100} ) ;
98101
99102export const upsertScheduleRoute = defineRoute ( {
@@ -133,6 +136,8 @@ export const upsertScheduleRoute = defineRoute({
133136 [ "label_id" , "session_id" ] ,
134137 [ data . labels , data . sessions ] ,
135138 ) ,
139+
140+ assets : _diffResource ( body . assets , "id" , data . assets ) ,
136141 } ;
137142
138143 // Exit early & output information if the dry run flag was passed in the URL
@@ -188,19 +193,27 @@ export const upsertScheduleRoute = defineRoute({
188193 } ) ,
189194 ) ;
190195
196+ const assets = await _performDiff (
197+ trx ,
198+ diff . assets ,
199+ AssetTable ,
200+ ( value ) : Partial < AssetRecord > => ( {
201+ ...pickProperties ( value , [ "title" , "url" , "metadata" ] ) ,
202+ conference_id : data . conference . id ,
203+ } ) ,
204+ { delete : false } ,
205+ ) ;
206+
191207 const people = await _performDiff (
192208 trx ,
193209 diff . people ,
194210 PersonTable ,
195211 ( value ) : Partial < PersonRecord > => ( {
196- ...pickProperties ( value , [
197- "avatar_id" ,
198- "bio" ,
199- "name" ,
200- "subtitle" ,
201- "metadata" ,
202- ] ) ,
212+ ...pickProperties ( value , [ "bio" , "name" , "subtitle" , "metadata" ] ) ,
203213 conference_id : data . conference . id ,
214+ avatar_id : value . avatar_id
215+ ? _getRelated ( assets . lookup , value . avatar_id )
216+ : null ,
204217 } ) ,
205218 ) ;
206219
0 commit comments