-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:OpenPathfinder/visionBoard into owa…
…sp-table
- Loading branch information
Showing
12 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { logger } = require('../utils') | ||
const { validateBulkImport } = require('../schemas') | ||
const { initializeStore } = require('../store') | ||
const { simplifyObject } = require('@ulisesgascon/simplify-object') | ||
const fs = require('fs') | ||
|
||
const bulkImport = async (knex, filePath) => { | ||
logger.info('Bulk importing data...') | ||
const { upsertSoftwareDesignTraining } = initializeStore(knex) | ||
|
||
if (!fs.existsSync(filePath)) { | ||
logger.error(`File not found: ${filePath}`) | ||
throw new Error('File not found') | ||
} | ||
// Try to read the file | ||
let data | ||
try { | ||
data = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
} catch (error) { | ||
logger.info('Check the documentation for the expected file format in https://openpathfinder.com/docs/visionBoard/importers') | ||
logger.error(`Error reading file: ${error.message}`) | ||
throw error | ||
} | ||
|
||
// Validate the data | ||
try { | ||
validateBulkImport(data) | ||
} catch (error) { | ||
logger.info('Check the data schema in https://github.com/OpenPathfinder/visionBoard/blob/main/src/schemas/bulkImport.json') | ||
logger.error('Error validating the data') | ||
throw error | ||
} | ||
|
||
validateBulkImport(data) | ||
|
||
// Update de database | ||
for await (const item of data) { | ||
if (item.type === 'softwareDesignTraining') { | ||
logger.info('Upserting software design training data...') | ||
await upsertSoftwareDesignTraining(simplifyObject(item, { | ||
exclude: ['type'] | ||
})) | ||
} | ||
} | ||
|
||
logger.info('Bulk importing completed') | ||
} | ||
|
||
module.exports = { | ||
bulkImport | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": ["softwareDesignTraining"] | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"project_id": { | ||
"type": "integer" | ||
}, | ||
"implementation_status": { | ||
"type": "string", | ||
"enum": ["unknown", "pending", "completed"] | ||
}, | ||
"training_date": { | ||
"type": "string", | ||
"format": "date", | ||
"nullable": true | ||
} | ||
}, | ||
"required": ["type", "description", "project_id", "implementation_status"], | ||
"additionalProperties": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters