Skip to content

Commit

Permalink
Merge pull request #139 from Vizzuality/CCSA-130-collaborator-csv-val…
Browse files Browse the repository at this point in the history
…idation

Add validation for type column in Collaborators csv import
  • Loading branch information
yulia-bel authored Sep 18, 2024
2 parents 4f36362 + 8c42452 commit dda3a6b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cms/src/api/collaborator/services/collaborator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default factories.createCoreService('api::collaborator.collaborator', {
const fileContent = fs.readFileSync(file.path, 'utf8');

const allowedColumns = ['name', 'link', 'type'];
const allowedTypes = ['donor', 'collaborator'];

const records: any[] = csv.parse(fileContent, {
columns: true,
Expand All @@ -36,9 +37,13 @@ export default factories.createCoreService('api::collaborator.collaborator', {
}

// Process each row
const updatedRecords = records.map((row: any) => {
const updatedRecords = records.map((row: any, index: number) => {
const publishedAt = new Date().toISOString();

if (!allowedTypes.includes(row.type)) {
throw new Error(`Invalid type "${row.type}" in row ${index + 2}. Allowed values are "donor" or "collaborator".`);
}

const updatedRow: any = {
...row,
publishedAt,
Expand Down

0 comments on commit dda3a6b

Please sign in to comment.