Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
data managment
Browse files Browse the repository at this point in the history
  • Loading branch information
slmyers committed Mar 18, 2018
1 parent cc787a6 commit 148a62d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
FROM node:9.8.0
RUN apt-get install git
COPY . /usr/api-server

COPY . /usr/api-server
WORKDIR /usr/api-server

RUN npm install
RUN npm install pm2 -g
RUN npm run prestart:prod

EXPOSE 3000

CMD ["pm2-runtime", "index.js", "--name", "api-server"]
CMD ["pm2-runtime", "dist/server.js", "--name", "api-server"]
8 changes: 8 additions & 0 deletions src/modules/data/data.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export class DataController {
return this.backupService.execute()
}

@Get('/has-been-initialized')
async hasBeenInitialized(): Promise<any> {
const hasBeenInitialized = await this.initService.hasBeenInitialized();
return Promise.resolve({
hasBeenInitialized
})
}

@Post('/init')
init(@Body() body): Promise<any> {
return this.initService.initialize(body.force)
Expand Down
11 changes: 10 additions & 1 deletion src/modules/data/init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ export class InitService {
this.client = this.clientService.client
}

async hasBeenInitialized(): Promise<boolean> {
const masterScreenerExists = await this.client.indices.exists({ index: 'master_screener'});
const questionsExists = await this.client.indices.exists({ index: 'questions'});
const programsExists = await this.client.indices.exists({ index: 'programs'});

return masterScreenerExists && questionsExists && programsExists;
}


async initialize(force = false): Promise<any> {
const masterScreenerExists = await this.client.indices.exists({ index: 'master_screener'});
const questionsExists = await this.client.indices.exists({ index: 'questions'});
const programsExists = await this.client.indices.exists({ index: 'programs'});

const hasBeenInitialized = masterScreenerExists || questionsExists || programsExists;
const hasBeenInitialized = masterScreenerExists && questionsExists && programsExists;


if (hasBeenInitialized && !force) {
throw new Error("Database has already been initialized.");
Expand Down
1 change: 1 addition & 0 deletions src/modules/data/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class UploadService {
body: { properties: { ...normalizedMapping } }
})
} else {
console.dir(Object.keys(data));
throw new Error("No queryMappings")
}
if (data.queries) {
Expand Down
17 changes: 5 additions & 12 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ const bodyParser = require('body-parser');
const instance = express();

async function bootstrap() {
const app = await NestFactory.create(ApplicationModule, instance);
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());

instance.use(bodyParser.urlencoded({
extended: true
}));
instance.use(bodyParser.json());


instance.use(bodyParser.urlencoded( {extended: true} ));
instance.use(bodyParser.json( {limit: '50mb'} ));
const app = await NestFactory.create(ApplicationModule, instance);
app.use(bodyParser.urlencoded( {extended: true} ));
app.use(bodyParser.json( {limit: '50mb'} ));
await app.listen(3000);
}
bootstrap();
Expand Down

0 comments on commit 148a62d

Please sign in to comment.