Skip to content

Commit 69fa31e

Browse files
committed
Merge branch 'dev' of github.com:haniffalab/strapi-api into dev
2 parents b79ebbd + 6650cab commit 69fa31e

21 files changed

Lines changed: 257 additions & 64 deletions

File tree

.github/workflows/deploy-appengine-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
GCS_PUBLIC_FILES: ${{ secrets.GCS_PUBLIC_FILES }}
3131
GCS_UNIFORM: ${{ secrets.GCS_UNIFORM }}
3232
GCS_SERVICE_ACCOUNT: ${{ secrets.GCP_SA_KEY }}
33+
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
3334

3435
steps:
3536
- uses: actions/checkout@v3

.github/workflows/deploy-appengine.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
GCS_PUBLIC_FILES: ${{ secrets.GCS_PUBLIC_FILES }}
3131
GCS_UNIFORM: ${{ secrets.GCS_UNIFORM }}
3232
GCS_SERVICE_ACCOUNT: ${{ secrets.GCP_SA_KEY }}
33+
SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
3334

3435
steps:
3536
- uses: actions/checkout@v3

create_yaml.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env_variables:
2222
GCS_PUBLIC_FILES: $GCS_PUBLIC_FILES
2323
GCS_UNIFORM: $GCS_UNIFORM
2424
GCS_SERVICE_ACCOUNT: '$GCS_SERVICE_ACCOUNT'
25+
SENDGRID_API_KEY: $SENDGRID_API_KEY
2526
automatic_scaling:
2627
min_instances: $MIN_INSTANCES
2728
max_instances: $MAX_INSTANCES
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
async beforeCreate(event) {
3+
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
4+
.generateUIDField({
5+
contentTypeUID: 'api::collection.collection',
6+
field: 'uid',
7+
data: event.params.data
8+
});
9+
},
10+
async beforeUpdate(event) {
11+
const { data, where } = event.params;
12+
13+
const isPublishAction = 'publishedAt' in data;
14+
15+
if (!isPublishAction){
16+
const entry = await strapi.entityService.findOne('api::collection.collection', where.id);
17+
18+
if ('name' in data && data.name !== entry.name){
19+
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
20+
.generateUIDField({
21+
contentTypeUID: 'api::collection.collection',
22+
field: 'uid',
23+
data: data
24+
});
25+
}
26+
}
27+
},
28+
29+
};

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
},
2828
"name": {
2929
"type": "string",
30-
"unique": true
30+
"unique": true,
31+
"required": true
32+
},
33+
"uid": {
34+
"type": "uid",
35+
"targetField": "name",
36+
"required": true
3137
}
3238
}
3339
}

src/api/collection/services/collection.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,24 @@
66

77
const { createCoreService } = require('@strapi/strapi').factories;
88

9-
module.exports = createCoreService('api::collection.collection');
9+
module.exports = createCoreService('api::collection.collection', ({strapi}) => ({
10+
async findByUid(ctx){
11+
const ctUid = 'api::collection.collection';
12+
const attrs = strapi.contentTypes[ctUid].__schema__.attributes;
13+
const uidTarget =attrs['uid'].targetField;
14+
const { [uidTarget]: uidTargetValue } = ctx.params;
15+
16+
const populateParams = strapi.config.functions.getPopulateParams(attrs);
17+
18+
let entity = await strapi.db.query(ctUid).findOne({
19+
where: { [uidTarget]: uidTargetValue },
20+
populate: populateParams
21+
});
22+
23+
if (entity){
24+
entity = strapi.config.functions.reduceComponentData(attrs, entity);
25+
}
26+
27+
return entity;
28+
}
29+
}));
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
module.exports = {
22
async beforeCreate(event) {
3-
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
3+
const { data } = event.params;
4+
5+
const uid = await strapi.service('plugin::content-manager.uid')
46
.generateUIDField({
57
contentTypeUID: 'api::dataset.dataset',
68
field: 'uid',
7-
data: event.params.data
9+
data: event.params.data.name
810
});
11+
12+
event.params.data.uid = uid;
13+
event.params.data.dataset_id = (data.study?.connect?.[0]?.id || null) + ':' + uid;
914
},
1015
async beforeUpdate(event) {
1116
const { data, where } = event.params;
1217

1318
const isPublishAction = 'publishedAt' in data;
1419

1520
if (!isPublishAction){
16-
const entry = await strapi.entityService.findOne('api::dataset.dataset', where.id);
17-
21+
const entry = await strapi.entityService.findOne('api::dataset.dataset', where.id,
22+
{populate: {study: {fields: ['id']}}}
23+
);
24+
1825
if ('name' in data && data.name !== entry.name){
1926
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
2027
.generateUIDField({
2128
contentTypeUID: 'api::dataset.dataset',
2229
field: 'uid',
23-
data: data
30+
data: data.name
2431
});
2532
}
33+
34+
event.params.data.dataset_id = (data.study?.connect?.[0] || entry.study?.id || null) + ':' + (event.params.data.uid || entry.uid);
2635
}
2736
},
2837
};

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"name": {
2424
"type": "string",
2525
"required": true,
26-
"unique": true
26+
"unique": false
2727
},
2828
"description": {
2929
"type": "text"
@@ -59,7 +59,7 @@
5959
},
6060
"uid": {
6161
"type": "uid",
62-
"targetField": "name",
62+
"targetField": "dataset_id",
6363
"required": true
6464
},
6565
"metadata": {
@@ -120,6 +120,15 @@
120120
"ontology": "hsapdv"
121121
},
122122
"customField": "plugin::ebi-ols.ontology-term"
123+
},
124+
"resources": {
125+
"type": "component",
126+
"repeatable": true,
127+
"component": "data.resource"
128+
},
129+
"dataset_id": {
130+
"type": "string",
131+
"unique": true
123132
}
124133
}
125134
}

src/api/dataset/controllers/dataset.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ module.exports = createCoreController('api::dataset.dataset', ({ strapi }) => ({
4141
fields: ['name', 'slug'],
4242
},
4343
data: {
44-
fields: ['format', 'file_type']
44+
fields: ['type']
4545
},
46+
resources: {
47+
fields: ['name', 'description', 'type', 'category', 'is_primary_data']
48+
}
4649
}
4750
};
4851
return await super.find(ctx);
@@ -60,6 +63,7 @@ module.exports = createCoreController('api::dataset.dataset', ({ strapi }) => ({
6063
fields: ['name', 'slug'],
6164
},
6265
data: true,
66+
resources: true,
6367
}
6468
};
6569
const dataset = await super.findOne(ctx);

src/api/dataset/services/dataset.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ module.exports = createCoreService('api::dataset.dataset', ({strapi}) => ({
1010
async findByUid(ctx){
1111
const ctUid = 'api::dataset.dataset';
1212
const attrs = strapi.contentTypes[ctUid].__schema__.attributes;
13-
const uidTarget =attrs['uid'].targetField;
14-
const { [uidTarget]: uidTargetValue } = ctx.params;
15-
13+
const { dataset_id, name, study_id } = ctx.params;
14+
15+
let where;
16+
if (dataset_id){
17+
where = { dataset_id: dataset_id };
18+
}
19+
else {
20+
const studyEntry = await strapi.service('api::study.study').findByUid({params: {study_id: study_id}});
21+
where = { study: studyEntry?.id || null, name: name };
22+
}
23+
1624
const populateParams = strapi.config.functions.getPopulateParams(attrs);
17-
25+
1826
let entity = await strapi.db.query(ctUid).findOne({
19-
where: { [uidTarget]: uidTargetValue },
27+
where: where,
2028
populate: populateParams
2129
});
2230

0 commit comments

Comments
 (0)