Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-appengine-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
GCS_UNIFORM: ${{ secrets.GCS_UNIFORM }}
GCS_SERVICE_ACCOUNT: ${{ secrets.GCP_SA_KEY }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
TRANSFER_TOKEN_SALT: ${{ secrets.TRANSFER_TOKEN_SALT }}

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-appengine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
GCS_UNIFORM: ${{ secrets.GCS_UNIFORM }}
GCS_SERVICE_ACCOUNT: ${{ secrets.GCP_SA_KEY }}
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
TRANSFER_TOKEN_SALT: ${{ secrets.TRANSFER_TOKEN_SALT }}

steps:
- uses: actions/checkout@v3
Expand Down
22 changes: 19 additions & 3 deletions config/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = {
if (authType === 'Basic') {
const base64Credentials = authHeader.split(' ')[1];
const decodedCredentials = Buffer.from(base64Credentials, 'base64').toString('ascii');
const [_username, password] = decodedCredentials.split(':');
const [, password] = decodedCredentials.split(':');

if (!password) {
return 'Password is required';
Expand Down Expand Up @@ -199,5 +199,21 @@ module.exports = {
}, {}));

return terms;
}
};
},

paginate(results, { page = 1, pageSize = 25 }) {
const paginatedResults = results.slice(
(page - 1) * pageSize,
page * pageSize
);
const meta = {
pagination: {
page: page,
total: results.length,
pageCount: Math.ceil(results.length / pageSize),
pageSize: pageSize,
}
};
return { results: paginatedResults, meta };
},
};
3 changes: 3 additions & 0 deletions src/api/study/content-types/study/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"type": "component",
"repeatable": true,
"component": "data.media"
},
"landing_page": {
"type": "richtext"
}
}
}
35 changes: 31 additions & 4 deletions src/api/study/controllers/study.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ const { NotFoundError } = require('@strapi/utils').errors;

module.exports = createCoreController('api::study.study', ({ strapi }) => ({
async find(ctx) {

// If not providing a dataset id, return only studies that are listed
if (!ctx.query.filters?.datasets?.id?.$eq){
if (!ctx.query.filters?.datasets?.id?.$eq) {
ctx.query.filters = {
...ctx.query.filters,
is_listed: true,
Expand Down Expand Up @@ -79,7 +78,7 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
fields: ['name', 'description', 'type', 'category'],
},
cover_dataset: {
fields: [false],
fields: ['id'],
populate: ['media'],
},
},
Expand Down Expand Up @@ -114,6 +113,33 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
};
}

// If sorting by publication date, get studies and manually sort
// as nested sorting returns duplicates (https://github.com/strapi/strapi/issues/11892)
const [sort, order = 'asc'] = ctx.query.sort?.split(':') || [];
if (sort === 'publications.date') {
const studies = await strapi.entityService.findMany(
'api::study.study',
ctx.query
);

studies.sort((a, b) => {
const aLatest = Math.max(
...(a.publications || []).map((p) => new Date(p.date)),
0
);
const bLatest = Math.max(
...(b.publications || []).map((p) => new Date(p.date)),
0
);
return order === 'asc' ? aLatest - bLatest : bLatest - aLatest;
});

const { results: paginatedStudies, meta } =
strapi.config.functions.paginate(studies, ctx.query.pagination || {});

return this.transformResponse(paginatedStudies, meta);
}

return await super.find(ctx);
},
async findOne(ctx) {
Expand All @@ -127,6 +153,7 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
'slug',
'lay_summary',
'cover_video',
'landing_page',
'createdAt',
'updatedAt',
],
Expand Down Expand Up @@ -199,7 +226,7 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
populate: ['media', 'data', 'resources'],
},
resources: true,
media: { fields: ['title', 'type'], populate: ['file']},
media: { fields: ['title', 'type'], populate: ['file'] },
cover_dataset: {
fields: [],
populate: ['media'],
Expand Down