1
-
2
- const user = require ( '../schema/user.js' ) ;
3
- const proj = require ( '../schema/project.js' ) ;
4
-
5
- module . exports = {
6
- search : function ( req , res ) {
7
- console . log ( req . body ) ;
8
- } ,
9
- check : function ( req , res ) {
10
- console . log ( req . body ) ;
11
- } ,
12
- profileId : function ( req , res ) {
13
- user . findOne ( { Eid : req . user . Eid } ) . then ( function ( us ) {
14
- req . params . id = us . Eid ;
15
- res . redirect ( '/profile/profileview/' + req . params . id ) ;
16
- } )
17
- } ,
18
- profileViewSd : function ( req , res ) {
19
- proj . find ( { pid : req . params . sd } ) . then ( function ( ques ) {
20
- user . findOne ( { Eid : req . params . sd } ) . then ( function ( use ) {
21
- res . render ( 'other-landing' , { use : use , ques : ques , sign : req . user } ) ;
22
- } )
23
-
24
-
25
- } ) ;
26
- } ,
27
- publish : function ( req , res ) {
28
- new proj ( {
29
- "pname" : req . body . contentname , "pid" : req . user . Eid , "github" : req . body . git , "Lang" : req . body . genre , "content" : req . body . cont , "upvote" : '' , "downvote" : '' , "proid" : Math . floor ( Math . random ( ) * 100000 )
30
- } ) . save ( ) . then ( function ( ) {
31
- res . redirect ( '/profile/profileview/' + req . user . Eid ) ;
32
- } )
33
- } ,
34
- upDownVote : function ( req , res ) {
35
- proj . findOne ( { proid : req . body . project } ) . then ( ( pro ) => {
36
- if ( pro . upDownVote . get ( req . body . client ) ) {
37
- if ( pro . upDownVote . get ( req . body . client ) == "-1" ) {
38
- pro . upDownVote . set ( req . body . client , "+1" )
39
- return pro . save ( )
40
-
41
- } else {
42
- pro . upDownVote . set ( req . body . client , "-1" )
43
- return pro . save ( )
44
-
45
- }
46
- } else {
47
- pro . upDownVote . set ( req . body . client , req . body . vote )
48
- return pro . save ( )
49
- }
50
- } ) . catch ( ( err ) => {
51
- return err
52
- } )
53
- } ,
54
- ch2 : function ( req , res ) {
55
- res . render ( 'main-landing' , { sign : req . user } ) ;
56
- } ,
57
- up : function ( req , res ) {
58
- res . send ( "success" ) ;
59
- } ,
60
- dashBoard : function ( req , res ) {
61
- res . render ( "dashboard" , { user :req . user } ) ;
62
- } ,
63
- setting : function ( req , res )
64
- {
65
- res . render ( 'setting' , { user :req . user } ) ;
66
- } ,
67
- updatename : function ( req , res )
68
- {
69
- user . findOne ( { Eid :req . user . Eid } ) . then ( function ( data ) {
70
- data . fname = req . body . name ;
71
- data . save ( ) ;
72
- } )
73
- } ,
74
- updatebio : function ( req , res )
75
- {
76
- user . findOne ( { Eid :req . user . Eid } ) . then ( function ( data ) {
77
- data . fname = req . body . bio ;
78
- data . save ( ) ;
79
- } )
80
- }
81
- }
1
+ const user = require ( '../schema/user.js' ) ;
2
+ const proj = require ( '../schema/project.js' ) ;
3
+
4
+ module . exports = {
5
+ search : function ( req , res ) {
6
+ console . log ( req . body ) ;
7
+ } ,
8
+ check : function ( req , res ) {
9
+ console . log ( req . body ) ;
10
+ } ,
11
+ profileId : function ( req , res ) {
12
+ user . findOne ( { Eid : req . user . Eid } ) . then ( function ( us ) {
13
+ req . params . id = us . Eid ;
14
+ res . redirect ( '/profile/profileview/' + req . params . id ) ;
15
+ } ) ;
16
+ } ,
17
+ profileViewSd : function ( req , res ) {
18
+ proj . find ( { pid : req . params . sd } ) . then ( function ( ques ) {
19
+ user . findOne ( { Eid : req . params . sd } ) . then ( function ( use ) {
20
+ res . render ( 'other-landing' , { use : use , ques : ques , sign : req . user } ) ;
21
+ } ) ;
22
+ } ) ;
23
+ } ,
24
+ publish : function ( req , res ) {
25
+ new proj ( {
26
+ pname : req . body . contentname ,
27
+ pid : req . user . Eid ,
28
+ github : req . body . git ,
29
+ Lang : req . body . genre ,
30
+ content : req . body . cont ,
31
+ upvote : '' ,
32
+ downvote : '' ,
33
+ proid : Math . floor ( Math . random ( ) * 100000 )
34
+ } )
35
+ . save ( )
36
+ . then ( function ( ) {
37
+ res . redirect ( '/profile/profileview/' + req . user . Eid ) ;
38
+ } ) ;
39
+ } ,
40
+ upvote : function ( req , res ) {
41
+ var p = 0 ;
42
+
43
+ var check = 0 ;
44
+ var comment = ' ' ;
45
+ for ( q = 0 ; q < proj . downvote . length ; q ++ ) {
46
+ if ( req . body . client == proj . downvote [ q ] ) {
47
+ comment = 'Cannot upvote and downvote a post ' ;
48
+ check = 1 ;
49
+ break ;
50
+ }
51
+ }
52
+
53
+ if ( check == 1 ) {
54
+ res . send ( { proj, comment } ) ;
55
+ } else {
56
+ for ( v = 0 ; v < proj . upvote . length ; v ++ ) {
57
+ if ( req . body . client == proj . upvote [ v ] ) {
58
+ p = 1 ;
59
+ proj . upvote . pop ( req . body . client ) ;
60
+ proj . save ( ) ;
61
+ console . log ( 'already present' ) ;
62
+ break ;
63
+ }
64
+ }
65
+
66
+ if ( p == 0 ) {
67
+ proj . upvote . push ( req . body . client ) ;
68
+ proj . save ( ) ;
69
+ }
70
+
71
+ res . send ( { comment, proj } ) ;
72
+ }
73
+ } ,
74
+ downvote : function ( req , res ) {
75
+ proj . findOne ( { proid : req . body . project } ) . then ( function ( proj ) {
76
+ var p = 0 ;
77
+ var check = 0 ;
78
+ var comment = '' ;
79
+
80
+ for ( q = 0 ; q < proj . upvote . length ; q ++ ) {
81
+ if ( req . body . client == proj . upvote [ q ] ) {
82
+ comment = 'Cannot do upvote downvote at same post' ;
83
+ check = 1 ;
84
+ break ;
85
+ }
86
+ }
87
+
88
+ if ( check == 1 ) {
89
+ res . send ( { comment, proj } ) ;
90
+ } else {
91
+ for ( v = 0 ; v < proj . downvote . length ; v ++ ) {
92
+ if ( req . body . client == proj . downvote [ v ] ) {
93
+ p = 1 ;
94
+ proj . downvote . pop ( req . body . client ) ;
95
+ proj . save ( ) ;
96
+ console . log ( 'already present' ) ;
97
+ break ;
98
+ }
99
+ }
100
+
101
+ if ( p == 0 ) {
102
+ proj . downvote . push ( req . body . client ) ;
103
+ proj . save ( ) ;
104
+ }
105
+
106
+ res . send ( { comment, proj } ) ;
107
+ }
108
+ } ) ;
109
+ } ,
110
+ ch2 : function ( req , res ) {
111
+ res . render ( 'main-landing' , { sign : req . user } ) ;
112
+ } ,
113
+ up : function ( req , res ) {
114
+ res . send ( 'success' ) ;
115
+ } ,
116
+ dashBoard : function ( req , res ) {
117
+ res . render ( 'dashboard' , { user : req . user } ) ;
118
+ } ,
119
+ setting : function ( req , res ) {
120
+ res . render ( 'setting' , { user : req . user } ) ;
121
+ } ,
122
+ updateDetails : function ( req , res ) {
123
+ user . findOne ( { Eid : req . user . Eid } ) . then ( function ( data ) {
124
+ ( data . fname = req . body . fname ) ,
125
+ ( data . lname = req . body . lname ) ,
126
+ ( data . bio = req . body . bio ) ,
127
+ ( data . college = req . body . college ) ,
128
+ ( data . email = req . body . email ) ,
129
+ ( data . github = req . body . githubUrl ) ,
130
+ ( data . linkedin = req . body . linkedinUrl ) ,
131
+ ( data . city = req . body . city ) ,
132
+ ( data . country = req . body . country ) ,
133
+ ( data . lang = req . body . languages ) ,
134
+ ( data . facebook = req . body . facebookUrl ) ;
135
+ data . save ( ) ;
136
+ res . send ( 'success' ) ;
137
+ } ) ;
138
+ } ,
139
+ getDetails : function ( req , res ) {
140
+ user . findOne ( { Eid : req . user . Eid } ) . then ( function ( data ) {
141
+ res . send ( data ) ;
142
+ } ) ;
143
+ }
144
+
145
+ } ;
146
+
0 commit comments