1
1
import { Projects } from '../models/reactypeModels' ;
2
+ import { Request , Response , NextFunction } from 'express' ;
2
3
3
- const projectController = { } ;
4
+ interface ProjectController {
5
+ saveProject : ( req : Request , res : Response , next : NextFunction ) => void ;
6
+ getProjects : ( req : Request , res : Response , next : NextFunction ) => void ;
7
+ deleteProject : ( req : Request , res : Response , next : NextFunction ) => void ;
8
+ }
9
+
10
+ const projectController : ProjectController = {
4
11
5
12
// saveProject saves current workspace to database
6
- projectController . saveProject = ( req , res , next ) => {
13
+ saveProject : ( req , res , next ) => {
7
14
// pull project name and project itself from body
8
15
const { name, project, userId, username, comments } = req . body ;
9
16
// create createdBy field for the document
@@ -31,10 +38,10 @@ projectController.saveProject = (req, res, next) => {
31
38
return next ( ) ;
32
39
}
33
40
) ;
34
- } ;
41
+ } ,
35
42
36
43
// gets all of current user's projects
37
- projectController . getProjects = ( req , res , next ) => {
44
+ getProjects : ( req , res , next ) => {
38
45
const { userId } = req . body ;
39
46
Projects . find ( { userId } , ( err , projects ) => {
40
47
if ( err ) {
@@ -49,10 +56,10 @@ projectController.getProjects = (req, res, next) => {
49
56
res . locals . projects = projects . map ( ( elem ) => elem . project ) ;
50
57
return next ( ) ;
51
58
} ) ;
52
- } ;
59
+ } ,
53
60
54
61
// delete project from database **currently not integrated into app**
55
- projectController . deleteProject = ( req , res , next ) => {
62
+ deleteProject : ( req , res , next ) => {
56
63
// pull project name and userId from req.body
57
64
const { name, userId } = req . body ;
58
65
Projects . findOneAndDelete ( { name, userId } , ( err , deleted ) => {
@@ -67,6 +74,6 @@ projectController.deleteProject = (req, res, next) => {
67
74
res . locals . deleted = deleted ;
68
75
return next ( ) ;
69
76
} ) ;
70
- } ;
71
-
77
+ } ,
78
+ }
72
79
export default projectController ;
0 commit comments