diff --git a/cms/config/sync/admin-role.strapi-super-admin.json b/cms/config/sync/admin-role.strapi-super-admin.json index 3cb46125..dc2cc545 100644 --- a/cms/config/sync/admin-role.strapi-super-admin.json +++ b/cms/config/sync/admin-role.strapi-super-admin.json @@ -847,10 +847,7 @@ "highlight", "account", "amount", - "status", "funding", - "source_country", - "organization_type", "objective", "info", "review_status", @@ -860,7 +857,10 @@ "sdgs", "project", "review_decision_details", - "reviewed_by" + "reviewed_by", + "source_country", + "organization_type", + "status" ] }, "conditions": [] @@ -889,10 +889,7 @@ "highlight", "account", "amount", - "status", "funding", - "source_country", - "organization_type", "objective", "info", "review_status", @@ -902,7 +899,10 @@ "sdgs", "project", "review_decision_details", - "reviewed_by" + "reviewed_by", + "source_country", + "organization_type", + "status" ] }, "conditions": [] @@ -917,10 +917,7 @@ "highlight", "account", "amount", - "status", "funding", - "source_country", - "organization_type", "objective", "info", "review_status", @@ -930,7 +927,10 @@ "sdgs", "project", "review_decision_details", - "reviewed_by" + "reviewed_by", + "source_country", + "organization_type", + "status" ] }, "conditions": [] diff --git a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##project-edit-suggestion.project-edit-suggestion.json b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##project-edit-suggestion.project-edit-suggestion.json index 81128c06..957dd83b 100644 --- a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##project-edit-suggestion.project-edit-suggestion.json +++ b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##project-edit-suggestion.project-edit-suggestion.json @@ -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", @@ -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", @@ -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", diff --git a/cms/src/api/collaborator-edit-suggestion/controllers/collaborator-edit-suggestion.ts b/cms/src/api/collaborator-edit-suggestion/controllers/collaborator-edit-suggestion.ts index e70bf8a8..12fa0b31 100644 --- a/cms/src/api/collaborator-edit-suggestion/controllers/collaborator-edit-suggestion.ts +++ b/cms/src/api/collaborator-edit-suggestion/controllers/collaborator-edit-suggestion.ts @@ -170,7 +170,7 @@ export default factories.createCoreController( importData, { headers: { - Authorization: `${ctx.req.rawHeaders[1] || ''}`, + Authorization: `${ctx.request.header.authorization || ''}`, 'Content-Type': 'application/json', }, } diff --git a/cms/src/api/project-edit-suggestion/controllers/project-edit-suggestion.ts b/cms/src/api/project-edit-suggestion/controllers/project-edit-suggestion.ts index 8ab6d2b9..6ea1891b 100644 --- a/cms/src/api/project-edit-suggestion/controllers/project-edit-suggestion.ts +++ b/cms/src/api/project-edit-suggestion/controllers/project-edit-suggestion.ts @@ -166,7 +166,7 @@ export default factories.createCoreController( importData, { headers: { - Authorization: `${ctx.req.rawHeaders[1] || ''}`, + Authorization: `${ctx.request.header.authorization || ''}`, 'Content-Type': 'application/json', }, } diff --git a/cms/src/api/project/services/project.ts b/cms/src/api/project/services/project.ts index 67b63d08..80334b48 100644 --- a/cms/src/api/project/services/project.ts +++ b/cms/src/api/project/services/project.ts @@ -14,6 +14,73 @@ interface ProjectRow { [key: string]: any; } +async function findProjectStatusIdByName(name: string): Promise { + 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 { + 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 { + 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 { + 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 { + 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 { const result: any = await strapi.entityService.findMany('api::country.country', { filters: { name }, @@ -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))); @@ -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, }; diff --git a/cms/src/api/tool-edit-suggestion/controllers/tool-edit-suggestion.ts b/cms/src/api/tool-edit-suggestion/controllers/tool-edit-suggestion.ts index 3637bba1..3212c92c 100644 --- a/cms/src/api/tool-edit-suggestion/controllers/tool-edit-suggestion.ts +++ b/cms/src/api/tool-edit-suggestion/controllers/tool-edit-suggestion.ts @@ -168,7 +168,7 @@ export default factories.createCoreController( importData, { headers: { - Authorization: `${ctx.req.rawHeaders[1] || ''}`, + Authorization: `${ctx.request.header.authorization || ''}`, 'Content-Type': 'application/json', }, }