File tree 8 files changed +70
-40
lines changed
8 files changed +70
-40
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ var http = require('http');
12
12
* Get port from environment and store in Express.
13
13
*/
14
14
15
- var port = normalizePort ( process . env . PORT || '3000 ' ) ;
15
+ var port = normalizePort ( process . env . PORT || '3001 ' ) ;
16
16
app . set ( 'port' , port ) ;
17
17
18
18
/**
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ var bodyParser = require('body-parser');
7
7
import mongoose from 'mongoose' ;
8
8
9
9
import index from './routes/index' ;
10
- import users from './routes/users ' ;
10
+ import users from './routes/survey ' ;
11
11
import dummyData from './dummyData' ;
12
12
import serverConfig from './config' ;
13
13
Original file line number Diff line number Diff line change 1
- import User from '../models/user ' ;
1
+ import Survey from '../models/survey ' ;
2
2
import cuid from 'cuid' ;
3
3
import sanitizeHtml from 'sanitize-html' ;
4
4
5
- /**
6
- * Get all posts
7
- * @param req
8
- * @param res
9
- * @returns void
10
- */
11
- export function getUsers ( req , res ) {
12
- User . find ( ) . exec ( ( err , users ) => {
5
+
6
+ export function getSurvey ( req , res ) {
7
+ Survey . find ( ) . exec ( ( err , survey ) => {
13
8
if ( err ) {
14
9
res . status ( 500 ) . send ( err ) ;
15
10
}
16
- res . json ( { users } ) ;
11
+ res . json ( { survey } ) ;
17
12
} ) ;
18
13
}
19
14
@@ -28,7 +23,7 @@ export function addUser(req, res) {
28
23
res . status ( 403 ) . end ( ) ;
29
24
}
30
25
31
- const newUser = new User ( req . body . user ) ;
26
+ const newUser = new Survey ( req . body . user ) ;
32
27
33
28
// Let's sanitize inputs
34
29
newUser . id = sanitizeHtml ( newUser . id ) ;
Original file line number Diff line number Diff line change 1
- import User from './models/user ' ;
1
+ import Survey from './models/survey ' ;
2
2
3
3
export default ( ) => {
4
- User . count ( ) . exec ( ( err , count ) => {
4
+ Survey . count ( ) . exec ( ( err , count ) => {
5
5
if ( count > 0 ) {
6
6
return ;
7
7
}
8
8
9
- const user1 = new User ( {
10
- name : 'Admin'
11
- } ) ;
12
- const user2 = new User ( {
13
- name : 'Admin'
14
- } ) ;
9
+ const data = {
10
+ name : 'Apklausa' ,
11
+ description : 'Apie save patį' ,
12
+ questions : [ {
13
+ title : 'Kokia mano lytis?' ,
14
+ type : 1 ,
15
+ optionIds : [ ]
16
+ } , {
17
+ title : 'Kiek man metų?' ,
18
+ type : 3 ,
19
+ options : [ {
20
+ title : '2 metai'
21
+ } , {
22
+ title : '3 metai'
23
+ } ] ,
24
+ answer : {
25
+ text : 'Vyras'
26
+ }
27
+ } ]
28
+ } ;
15
29
16
- User . create ( [ user1 , user2 ] , ( error ) => {
30
+ Survey . create ( data , ( error ) => {
31
+ console . log ( 'error' , error ) ;
17
32
if ( ! error ) {
18
33
console . log ( 'ready to go....' ) ;
19
34
}
Original file line number Diff line number Diff line change
1
+ import mongoose from 'mongoose' ;
2
+
3
+ const Schema = mongoose . Schema ;
4
+
5
+ const survey = new Schema ( {
6
+ name : { type : 'String' , required : true } ,
7
+ description : { type : 'String' , required : true } ,
8
+ questions : [
9
+ {
10
+ title : { type : 'String' , required : true } ,
11
+ type : { type : 'Number' , required : true } ,
12
+ options : [
13
+ {
14
+ title : { type : 'String' , required : false }
15
+ }
16
+ ] ,
17
+ answer : {
18
+ type : {
19
+ text : { type : 'String' , required : true }
20
+ } ,
21
+ required : false
22
+ }
23
+ }
24
+ ]
25
+ } ) ;
26
+
27
+ export default mongoose . model ( 'Survey' , survey ) ;
28
+
29
+
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { Router } from 'express' ;
2
+ import * as SurveyController from '../controllers/survey.controller' ;
3
+
4
+ const router = new Router ( ) ;
5
+
6
+ /* GET users listing. */
7
+ router . route ( '/survey' ) . get ( SurveyController . getSurvey ) ;
8
+
9
+ export default router ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments