Skip to content

Commit

Permalink
Merge pull request #176 from Vizzuality/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
mluena authored Nov 13, 2024
2 parents 25bb0ef + 698154c commit e329837
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 57 deletions.
24 changes: 12 additions & 12 deletions cms/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,7 @@
"highlight",
"account",
"amount",
"status",
"funding",
"source_country",
"organization_type",
"objective",
"info",
"review_status",
Expand All @@ -860,7 +857,10 @@
"sdgs",
"project",
"review_decision_details",
"reviewed_by"
"reviewed_by",
"source_country",
"organization_type",
"status"
]
},
"conditions": []
Expand Down Expand Up @@ -889,10 +889,7 @@
"highlight",
"account",
"amount",
"status",
"funding",
"source_country",
"organization_type",
"objective",
"info",
"review_status",
Expand All @@ -902,7 +899,10 @@
"sdgs",
"project",
"review_decision_details",
"reviewed_by"
"reviewed_by",
"source_country",
"organization_type",
"status"
]
},
"conditions": []
Expand All @@ -917,10 +917,7 @@
"highlight",
"account",
"amount",
"status",
"funding",
"source_country",
"organization_type",
"objective",
"info",
"review_status",
Expand All @@ -930,7 +927,10 @@
"sdgs",
"project",
"review_decision_details",
"reviewed_by"
"reviewed_by",
"source_country",
"organization_type",
"status"
]
},
"conditions": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@
"sortable": true
}
},
"status": {
"edit": {
"label": "status",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "status",
"searchable": true,
"sortable": true
}
},
"funding": {
"edit": {
"label": "funding",
Expand All @@ -105,34 +91,6 @@
"sortable": true
}
},
"source_country": {
"edit": {
"label": "source_country",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "source_country",
"searchable": true,
"sortable": true
}
},
"organization_type": {
"edit": {
"label": "organization_type",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "organization_type",
"searchable": true,
"sortable": true
}
},
"objective": {
"edit": {
"label": "objective",
Expand Down Expand Up @@ -279,6 +237,51 @@
"sortable": true
}
},
"source_country": {
"edit": {
"label": "source_country",
"description": "",
"placeholder": "",
"visible": true,
"editable": true,
"mainField": "code"
},
"list": {
"label": "source_country",
"searchable": true,
"sortable": true
}
},
"organization_type": {
"edit": {
"label": "organization_type",
"description": "",
"placeholder": "",
"visible": true,
"editable": true,
"mainField": "name"
},
"list": {
"label": "organization_type",
"searchable": true,
"sortable": true
}
},
"status": {
"edit": {
"label": "status",
"description": "",
"placeholder": "",
"visible": true,
"editable": true,
"mainField": "name"
},
"list": {
"label": "status",
"searchable": true,
"sortable": true
}
},
"createdAt": {
"edit": {
"label": "createdAt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default factories.createCoreController(
importData,
{
headers: {
Authorization: `${ctx.req.rawHeaders[1] || ''}`,
Authorization: `${ctx.request.header.authorization || ''}`,
'Content-Type': 'application/json',
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default factories.createCoreController(
importData,
{
headers: {
Authorization: `${ctx.req.rawHeaders[1] || ''}`,
Authorization: `${ctx.request.header.authorization || ''}`,
'Content-Type': 'application/json',
},
}
Expand Down
77 changes: 77 additions & 0 deletions cms/src/api/project/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,73 @@ interface ProjectRow {
[key: string]: any;
}

async function findProjectStatusIdByName(name: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::project-status.project-status', {
filters: { name },
fields: ['id'],
});

if (result.length === 0) {
throw new Error(`No project status found with the name "${name}"`);
}

return result[0].id;
}

async function findObjectiveIdByType(type: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::objective.objective', {
filters: { type },
fields: ['id'],
});

if (result.length === 0) {
throw new Error(`No objective found with the name "${type}"`);
}

return result[0].id;
}

async function findOrganizationTypeIdByName(name: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::organization-type.organization-type', {
filters: { name },
fields: ['id'],
});

if (result.length === 0) {
throw new Error(`No organization type found with the name "${name}"`);
}

return result[0].id;
}

async function findFundingIdByName(name: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::organization-type.organization-type', {
filters: { name },
fields: ['id'],
});

if (result.length === 0) {
throw new Error(`No funding found with the name "${name}"`);
}

return result[0].id;
}

async function findWorldCountryIdByName(name: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::world-country.world-country', {
filters: { name },
fields: ['id'],
});

if (result.length === 0) {
throw new Error(`No world country found with the name "${name}"`);
}

return result[0].id;
}



async function findCountryIdByName(name: string): Promise<number> {
const result: any = await strapi.entityService.findMany('api::country.country', {
filters: { name },
Expand Down Expand Up @@ -86,6 +153,11 @@ export default factories.createCoreService('api::project.project', {
const countryNames = row.countries.split(';').map(name => name.trim());
const sdgNames = row.sdgs.split(';').map(name => name.trim());
const pillarNames = row.pillar.split(';').map(name => name.trim());
const status = row.status ? [await findProjectStatusIdByName(row.status)] : [];
const sourceCountry = row.source_country ? [await findWorldCountryIdByName(row.source_country)] : [];
const objective = row.objective ? [await findObjectiveIdByType(row.objective)] : [];
const organizationType = row.organization_type ? [await findOrganizationTypeIdByName(row.organization_type)] : []
const funding = row.funding ? [await findFundingIdByName(row.funding)]: [];

const countryIds = await Promise.all(countryNames.map(name => findCountryIdByName(name)));
const sdgIds = await Promise.all(sdgNames.map(name => findSdgIdByName(name)));
Expand All @@ -97,6 +169,11 @@ export default factories.createCoreService('api::project.project', {
countries: countryIds,
sdgs: sdgIds,
pillar: pillarIds,
status,
source_country: sourceCountry,
objective,
organization_type: organizationType,
funding,
publishedAt,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default factories.createCoreController(
importData,
{
headers: {
Authorization: `${ctx.req.rawHeaders[1] || ''}`,
Authorization: `${ctx.request.header.authorization || ''}`,
'Content-Type': 'application/json',
},
}
Expand Down

0 comments on commit e329837

Please sign in to comment.