Skip to content

fix seed metadata script #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Microservice to manage CRUD operations for all things Projects.
```bash
NODE_ENV=development npm run sync:db
```
This command will crate tables in `postgres` db.
This command will crate tables in `postgres` db.

*NOTE: this will drop tables if they already exist.*
*NOTE: this will drop tables if they already exist.*

* Sync ES indices
```bash
Expand All @@ -72,9 +72,11 @@ Microservice to manage CRUD operations for all things Projects.

### Import sample metadata
```bash
node migrations/seedMetadata.js
CONNECT_USER_TOKEN=<connect user token> node migrations/seedMetadata.js
```
To create sample metadata entries (duplicate what is currently in development environment).
This command will create sample metadata entries in the DB (duplicate what is currently in development environment).

To retrieve data from DEV env we need to provide a valid user token. You may login to http://connect.topcoder-dev.com and find the Bearer token in the request headers using browser dev tools.

### Run Connect App with Project Service locally

Expand Down
20 changes: 15 additions & 5 deletions migrations/seedMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ const _ = require('lodash')
const axios = require('axios');
const Promise = require('bluebird');

if (!process.env.CONNECT_USER_TOKEN) {
console.error('This script requires environment variable CONNECT_USER_TOKEN to be defined. Login to http://connect.topcoder-dev.com and get your user token from the requests headers.')
exit(1);
}

// we need to know any logged in Connect user token to retrieve data from DEV
const CONNECT_USER_TOKEN = process.env.CONNECT_USER_TOKEN;

var url = 'https://api.topcoder-dev.com/v4/projects/metadata';
var targetUrl = 'http://localhost:8001/v4/';
var destUrl = targetUrl + 'projects/';
var destTimelines = targetUrl;

axios.get(url)
axios.get(url, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${CONNECT_USER_TOKEN}`
}
})
.then(async function (response) {
let data = response.data;

var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw'
}


Expand Down Expand Up @@ -62,11 +74,9 @@ axios.get(url)
.catch(e=>resolve()); //ignore the error
})
});



// handle success
console.log('Done');
}).catch(err=>{
console.log(err);
console.log(err && err.response ? err.response.data : err);
});