Skip to content

Commit 4f0d869

Browse files
authored
Merge pull request #67 from haniffalab/feat/study-header
Update study fields to support improved study header in the client
2 parents a5f8d35 + 91aa35d commit 4f0d869

2 files changed

Lines changed: 81 additions & 32 deletions

File tree

src/api/study/content-types/study/schema.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@
6363
"repeatable": true,
6464
"component": "contributions.team"
6565
},
66-
"subtitle": {
67-
"type": "text"
66+
"lay_summary": {
67+
"type": "text",
68+
"maxLength": 400
6869
},
6970
"password": {
7071
"type": "customField",
@@ -84,6 +85,10 @@
8485
"type": "relation",
8586
"relation": "oneToOne",
8687
"target": "api::dataset.dataset"
88+
},
89+
"cover_video": {
90+
"type": "string",
91+
"regex": "^https"
8792
}
8893
}
8994
}

src/api/study/controllers/study.js

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ const { NotFoundError } = require('@strapi/utils').errors;
99

1010
module.exports = createCoreController('api::study.study', ({ strapi }) => ({
1111
async find(ctx) {
12-
1312
ctx.query.filters = {
1413
...ctx.query.filters,
1514
is_listed: true,
1615
};
1716

1817
ctx.query = {
1918
...ctx.query,
20-
fields: [
21-
'name',
22-
'slug',
23-
'subtitle',
24-
'createdAt',
25-
'updatedAt',
26-
],
19+
fields: ['name', 'slug', 'lay_summary', 'createdAt', 'updatedAt'],
2720
populate: {
2821
cover_image: true,
2922
publications: {
30-
fields: ['title', 'doi', 'url', 'abstract', 'date', 'is_published', 'is_preprint'],
23+
fields: [
24+
'title',
25+
'doi',
26+
'url',
27+
'abstract',
28+
'date',
29+
'is_published',
30+
'is_preprint',
31+
],
3132
populate: {
3233
journal: {
3334
fields: ['name'],
@@ -56,32 +57,52 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
5657
},
5758
},
5859
datasets: {
59-
fields: ['name', 'description', 'tissues', 'organisms', 'assays', 'diseases', 'celltypes', 'human_developmental_stages', 'count', 'unit'],
60+
fields: [
61+
'name',
62+
'description',
63+
'tissues',
64+
'organisms',
65+
'assays',
66+
'diseases',
67+
'celltypes',
68+
'human_developmental_stages',
69+
'count',
70+
'unit',
71+
],
6072
populate: ['media'],
6173
},
6274
resources: {
63-
fields: ['name', 'description', 'type', 'category' ]
75+
fields: ['name', 'description', 'type', 'category'],
6476
},
6577
cover_dataset: {
6678
fields: [false],
6779
populate: ['media'],
68-
}
80+
},
6981
},
7082
};
7183

7284
// Check if 'collection' query parameter is present
7385
// Add to query filters last to avoid spreading the ids array into an object
7486
const { collection } = ctx.query;
7587
if (collection) {
76-
const collectionEntry = await strapi.db.query('api::collection.collection').findOne({
77-
where: { name: collection },
78-
populate: { studies: { select: ['id'] } },
79-
});
88+
const collectionEntry = await strapi.db
89+
.query('api::collection.collection')
90+
.findOne({
91+
where: { name: collection },
92+
populate: { studies: { select: ['id'] } },
93+
});
8094

8195
const ids = collectionEntry?.studies.map(({ id }) => id) || [];
82-
if (!ids?.length) { return this.transformResponse([], {
83-
pagination: { page: 1, total: 0, pageCount: 0, pageSize: ctx.query.pagination?.pageSize || 10 }
84-
}); }
96+
if (!ids?.length) {
97+
return this.transformResponse([], {
98+
pagination: {
99+
page: 1,
100+
total: 0,
101+
pageCount: 0,
102+
pageSize: ctx.query.pagination?.pageSize || 10,
103+
},
104+
});
105+
}
85106

86107
ctx.query.filters = {
87108
...ctx.query.filters,
@@ -92,7 +113,6 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
92113
return await super.find(ctx);
93114
},
94115
async findOne(ctx) {
95-
96116
const { slug } = ctx.params;
97117

98118
const query = {
@@ -101,14 +121,24 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
101121
fields: [
102122
'name',
103123
'slug',
104-
'subtitle',
124+
'lay_summary',
125+
'cover_video',
105126
'createdAt',
106127
'updatedAt',
107128
],
108129
populate: {
109130
cover_image: true,
131+
cover_video: true,
110132
publications: {
111-
fields: ['title', 'doi', 'url', 'abstract', 'date', 'is_published', 'is_preprint'],
133+
fields: [
134+
'title',
135+
'doi',
136+
'url',
137+
'abstract',
138+
'date',
139+
'is_published',
140+
'is_preprint',
141+
],
112142
populate: {
113143
journal: {
114144
fields: ['name'],
@@ -137,14 +167,26 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
137167
},
138168
},
139169
datasets: {
140-
fields: ['name', 'description', 'tissues', 'organisms', 'assays', 'diseases', 'celltypes', 'human_developmental_stages', 'count', 'unit'],
170+
fields: [
171+
'name',
172+
'description',
173+
'tissues',
174+
'organisms',
175+
'assays',
176+
'diseases',
177+
'celltypes',
178+
'human_developmental_stages',
179+
'count',
180+
'is_featured',
181+
'unit',
182+
],
141183
populate: ['media', 'data', 'resources'],
142184
},
143185
resources: true,
144186
cover_dataset: {
145187
fields: [],
146188
populate: ['media'],
147-
}
189+
},
148190
},
149191
};
150192

@@ -156,17 +198,19 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
156198
// Check if 'collection' query parameter is present
157199
const { collection } = ctx.query;
158200
if (collection) {
159-
const collectionEntry = await strapi.db.query('api::collection.collection').findOne({
160-
where: { name: collection },
161-
populate: { studies: { select: ['id'] } },
162-
});
201+
const collectionEntry = await strapi.db
202+
.query('api::collection.collection')
203+
.findOne({
204+
where: { name: collection },
205+
populate: { studies: { select: ['id'] } },
206+
});
163207

164208
const ids = collectionEntry?.studies.map(({ id }) => id) || [];
165-
if (!ids.length || !ids.includes(study.id)){
209+
if (!ids.length || !ids.includes(study.id)) {
166210
throw new NotFoundError('Study not found in collection');
167211
}
168212
}
169213

170214
return this.transformResponse(study);
171215
},
172-
}));
216+
}));

0 commit comments

Comments
 (0)