Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
4949c01d
Commit
4949c01d
authored
Jul 14, 2022
by
Yoon, Daeki
😅
Browse files
Merge branch 'main' into file-upload
parents
6a24c10c
80a2b663
Changes
45
Show whitespace changes
Inline
Side-by-side
src/db/survey.db.ts
View file @
4949c01d
import
{
Survey
,
ISurvey
}
from
"
../models
"
;
import
{
Survey
,
ISurvey
}
from
"
../models
"
;
export
const
findUserBySurveyId
=
async
(
surveyId
:
string
)
=>
{
const
survey
=
await
Survey
.
findById
(
surveyId
).
populate
(
"
user
"
);
console
.
log
(
survey
);
if
(
survey
!==
null
)
{
console
.
log
(
survey
.
user
);
return
survey
.
user
;
}
return
null
;
};
export
const
createSurvey
=
async
(
survey
:
ISurvey
)
=>
{
export
const
createSurvey
=
async
(
survey
:
ISurvey
)
=>
{
const
newSurvey
=
await
Survey
.
create
(
survey
);
const
newSurvey
=
await
Survey
.
create
(
survey
);
return
newSurvey
;
return
newSurvey
;
};
};
export
const
getSurveyById
=
async
(
surveyId
:
string
)
=>
{
console
.
log
(
"
survey id
"
,
surveyId
);
const
survey
=
await
Survey
.
findById
(
surveyId
).
populate
(
"
questions
"
);
return
survey
;
};
export
const
updateSurvey
=
async
(
survey
:
ISurvey
)
=>
{
const
newSurvey
=
await
Survey
.
findOneAndUpdate
({
_id
:
survey
.
_id
},
survey
);
return
newSurvey
;
};
src/models/question.model.ts
View file @
4949c01d
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
import
{
model
,
ObjectId
,
Schema
,
Types
}
from
"
mongoose
"
;
export
interface
IQuestion
{
export
interface
IQuestion
{
_id
?:
Types
.
ObjectId
;
user
?:
Types
.
ObjectId
;
type
:
string
;
type
:
string
;
// id: string;
title
?:
string
;
title
?:
string
;
isRequired
:
boolean
;
isRequired
:
boolean
;
comment
?:
string
;
comment
?:
string
;
content
?:
any
;
content
?:
any
;
}
}
const
schema
=
new
Schema
<
IQuestion
>
({
type
:{
type
:
String
},
title
:
{
type
:
String
},
isRequired
:
{
type
:
Boolean
},
comment
:{
type
:
String
},
content
:{
type
:
Object
},
},
{
toJSON
:
{
versionKey
:
false
}});
export
default
model
<
IQuestion
>
(
"
Question
"
,
schema
);
const
schema
=
new
Schema
<
IQuestion
>
(
{
user
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
User
"
},
type
:
{
type
:
String
},
title
:
{
type
:
String
},
isRequired
:
{
type
:
Boolean
},
comment
:
{
type
:
String
},
content
:
{
type
:
Object
},
},
{
toJSON
:
{
versionKey
:
false
,
},
}
);
export
default
model
<
IQuestion
>
(
"
Question
"
,
schema
);
src/models/survey.model.ts
View file @
4949c01d
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
export
interface
ISurvey
{
export
interface
ISurvey
{
title
:
string
;
_id
?:
Types
.
ObjectId
;
comment
:
string
;
title
?:
string
;
questions
:
Types
.
ObjectId
[]
comment
?:
string
;
}
user
:
Types
.
ObjectId
;
questions
:
Types
.
ObjectId
[];
}
const
schema
=
new
Schema
<
ISurvey
>
({
const
schema
=
new
Schema
<
ISurvey
>
({
title
:
{
type
:
String
},
title
:
{
type
:
String
},
comment
:
{
type
:
String
},
comment
:
{
type
:
String
},
questions
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'
Question
'
}],
user
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
User
"
},
});
questions
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
Question
"
}],
});
export
default
model
<
ISurvey
>
(
"
Survey
"
,
schema
);
export
default
model
<
ISurvey
>
(
"
Survey
"
,
schema
);
src/routes/question.route.ts
View file @
4949c01d
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
{
questionCtrl
}
from
"
../controllers
"
;
import
{
authCtrl
,
questionCtrl
}
from
"
../controllers
"
;
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
router
.
route
(
"
/create
"
)
.
route
(
"
/create
"
)
.
post
(
questionCtrl
.
createQuestion
);
.
post
(
authCtrl
.
requireLogin
,
questionCtrl
.
createQuestion
);
router
.
route
(
"
/update/:questionId
"
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
questionCtrl
.
updateQuestion
);
router
.
route
(
"
/delete/:questionId
"
)
.
delete
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
questionCtrl
.
deleteQuestionById
);
router
.
param
(
"
questionId
"
,
questionCtrl
.
userByQuestionId
);
export
default
router
;
export
default
router
;
src/routes/survey.route.ts
View file @
4949c01d
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
{
surveyCtrl
}
from
"
../controllers
"
;
import
{
authCtrl
,
surveyCtrl
}
from
"
../controllers
"
;
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/create
"
).
post
(
authCtrl
.
requireLogin
,
surveyCtrl
.
createSurvey
);
router
router
.
route
(
"
/create
"
)
.
route
(
"
/edit/:surveyId
"
)
.
post
(
surveyCtrl
.
createSurvey
);
.
get
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
surveyCtrl
.
getSurveyById
)
.
put
(
authCtrl
.
requireLogin
,
authCtrl
.
authenticate
,
surveyCtrl
.
updateSurvey
);
router
.
param
(
"
surveyId
"
,
surveyCtrl
.
userBySurveyId
);
export
default
router
;
export
default
router
;
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment