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

Commit 148a62d

Browse files
author
Steven Myers
committed
data managment
1 parent cc787a6 commit 148a62d

5 files changed

Lines changed: 28 additions & 16 deletions

File tree

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
FROM node:9.8.0
2-
RUN apt-get install git
3-
COPY . /usr/api-server
42

3+
COPY . /usr/api-server
54
WORKDIR /usr/api-server
5+
66
RUN npm install
77
RUN npm install pm2 -g
8+
RUN npm run prestart:prod
89

910
EXPOSE 3000
1011

11-
CMD ["pm2-runtime", "index.js", "--name", "api-server"]
12+
CMD ["pm2-runtime", "dist/server.js", "--name", "api-server"]

src/modules/data/data.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export class DataController {
1616
return this.backupService.execute()
1717
}
1818

19+
@Get('/has-been-initialized')
20+
async hasBeenInitialized(): Promise<any> {
21+
const hasBeenInitialized = await this.initService.hasBeenInitialized();
22+
return Promise.resolve({
23+
hasBeenInitialized
24+
})
25+
}
26+
1927
@Post('/init')
2028
init(@Body() body): Promise<any> {
2129
return this.initService.initialize(body.force)

src/modules/data/init.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ export class InitService {
1010
this.client = this.clientService.client
1111
}
1212

13+
async hasBeenInitialized(): Promise<boolean> {
14+
const masterScreenerExists = await this.client.indices.exists({ index: 'master_screener'});
15+
const questionsExists = await this.client.indices.exists({ index: 'questions'});
16+
const programsExists = await this.client.indices.exists({ index: 'programs'});
17+
18+
return masterScreenerExists && questionsExists && programsExists;
19+
}
20+
1321

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

19-
const hasBeenInitialized = masterScreenerExists || questionsExists || programsExists;
27+
const hasBeenInitialized = masterScreenerExists && questionsExists && programsExists;
28+
2029

2130
if (hasBeenInitialized && !force) {
2231
throw new Error("Database has already been initialized.");

src/modules/data/upload.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class UploadService {
4040
body: { properties: { ...normalizedMapping } }
4141
})
4242
} else {
43+
console.dir(Object.keys(data));
4344
throw new Error("No queryMappings")
4445
}
4546
if (data.queries) {

src/server.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ const bodyParser = require('body-parser');
66
const instance = express();
77

88
async function bootstrap() {
9-
const app = await NestFactory.create(ApplicationModule, instance);
10-
app.use(bodyParser.urlencoded({
11-
extended: true
12-
}));
13-
app.use(bodyParser.json());
14-
15-
instance.use(bodyParser.urlencoded({
16-
extended: true
17-
}));
18-
instance.use(bodyParser.json());
19-
20-
9+
instance.use(bodyParser.urlencoded( {extended: true} ));
10+
instance.use(bodyParser.json( {limit: '50mb'} ));
11+
const app = await NestFactory.create(ApplicationModule, instance);
12+
app.use(bodyParser.urlencoded( {extended: true} ));
13+
app.use(bodyParser.json( {limit: '50mb'} ));
2114
await app.listen(3000);
2215
}
2316
bootstrap();

0 commit comments

Comments
 (0)