@@ -15,8 +15,10 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
1515 }
1616
1717 buildRelationships ( model : ModelInstance < PreprintMirageModel > ) {
18- const relationships : SerializedRelationships < PreprintMirageModel > = {
19- provider : {
18+ const relationships : SerializedRelationships < PreprintMirageModel > = { } ;
19+
20+ if ( model . provider ) {
21+ relationships . provider = {
2022 data : {
2123 id : model . provider . id ,
2224 type : 'preprint-providers' ,
@@ -27,32 +29,44 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
2729 meta : { } ,
2830 } ,
2931 } ,
30- } ,
31- contributors : {
32+ } ;
33+ }
34+
35+ if ( model . contributors ) {
36+ relationships . contributors = {
3237 links : {
3338 related : {
3439 href : `${ apiUrl } /v2/preprints/${ model . id } /contributors` ,
3540 meta : this . buildRelatedLinkMeta ( model , 'contributors' ) ,
3641 } ,
3742 } ,
38- } ,
39- bibliographicContributors : {
43+ } ;
44+ }
45+
46+ if ( model . bibliographicContributors ) {
47+ relationships . bibliographicContributors = {
4048 links : {
4149 related : {
4250 href : `${ apiUrl } /v2/preprints/${ model . id } /bibliographic_contributors/` ,
4351 meta : this . buildRelatedLinkMeta ( model , 'bibliographicContributors' ) ,
4452 } ,
4553 } ,
46- } ,
47- files : {
54+ } ;
55+ }
56+
57+ if ( model . files ) {
58+ relationships . files = {
4859 links : {
4960 related : {
5061 href : `${ apiUrl } /v2/preprints/${ model . id } /files/` ,
5162 meta : this . buildRelatedLinkMeta ( model , 'files' ) ,
5263 } ,
5364 } ,
54- } ,
55- subjects : {
65+ } ;
66+ }
67+
68+ if ( model . subjects ) {
69+ relationships . subjects = {
5670 links : {
5771 self : {
5872 href : `${ apiUrl } /v2/preprints/${ model . id } /relationships/subjects/` ,
@@ -63,43 +77,55 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
6377 meta : this . buildRelatedLinkMeta ( model , 'subjects' ) ,
6478 } ,
6579 } ,
66- } ,
67- reviewActions : {
80+ } ;
81+ }
82+
83+ if ( model . reviewActions ) {
84+ relationships . reviewActions = {
6885 links : {
6986 related : {
7087 href : `${ apiUrl } /v2/preprints/${ model . id } /review_actions/` ,
7188 meta : this . buildRelatedLinkMeta ( model , 'reviewActions' ) ,
7289 } ,
7390 } ,
74- } ,
75- requests : {
91+ } ;
92+ }
93+
94+ if ( model . requests ) {
95+ relationships . requests = {
7696 links : {
7797 related : {
7898 href : `${ apiUrl } /v2/preprints/${ model . id } /requests/` ,
7999 meta : this . buildRelatedLinkMeta ( model , 'requests' ) ,
80100 } ,
81101 } ,
82- } ,
83- citation : {
102+ } ;
103+ }
104+
105+ if ( model . citation ) {
106+ relationships . citation = {
84107 links : {
85108 related : {
86109 href : `${ apiUrl } /v2/preprints/${ model . id } /citation/` ,
87110 meta : { } ,
88111 } ,
89112 } ,
90- } ,
91- identifiers : {
113+ } ;
114+ }
115+
116+ if ( model . identifiers ) {
117+ relationships . identifiers = {
92118 links : {
93119 related : {
94120 href : `${ apiUrl } /v2/preprints/${ model . id } /identifiers/` ,
95121 meta : this . buildRelatedLinkMeta ( model , 'identifiers' ) ,
96122 } ,
97123 } ,
98- } ,
99- } ;
124+ } ;
125+ }
100126
101127 if ( model . node ) {
102- relationships [ ' node' ] = {
128+ relationships . node = {
103129 links : {
104130 related : {
105131 href : `${ apiUrl } /v2/nodes/${ model . nodeId } ` ,
@@ -110,7 +136,7 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
110136 }
111137
112138 if ( model . primaryFile ) {
113- relationships [ ' primaryFile' ] = {
139+ relationships . primaryFile = {
114140 links : {
115141 related : {
116142 href : `${ apiUrl } /v2/files/${ model . primaryFile . id } /` ,
@@ -120,7 +146,7 @@ export default class PreprintSerializer extends ApplicationSerializer<PreprintMi
120146 } ;
121147 }
122148
123- if ( model . license !== null ) {
149+ if ( model . license ) {
124150 const { id } = model . license ;
125151 relationships . license = {
126152 data : {
0 commit comments