forked from OneCommunityGlobal/HGNRest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserProfileRouter.js
More file actions
173 lines (163 loc) · 7.03 KB
/
Copy pathuserProfileRouter.js
File metadata and controls
173 lines (163 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const { body, param } = require('express-validator');
const express = require('express');
const { ValidationError } = require('../utilities/errorHandling/customError');
const routes = function (userProfile, project) {
const controller = require('../controllers/userProfileController')(userProfile, project);
const userProfileRouter = express.Router();
// Skills radar route
userProfileRouter.get('/userProfile/:userId/skills-radar', async (req, res) => {
try {
if (typeof controller.getUserSkillRadarData === 'function') {
await controller.getUserSkillRadarData(req, res);
} else {
res.status(500).send('Controller function not found');
}
} catch (err) {
res.status(500).send({ error: err.message });
}
});
// Other routes (unchanged, just formatted for clarity)
userProfileRouter
.route('/userProfile')
.get(controller.getUserProfiles)
.post(
body('firstName').customSanitizer((value) => {
if (!value) throw new ValidationError('First Name is required');
return value.trim();
}),
body('lastName').customSanitizer((value) => {
if (!value) throw new ValidationError('Last Name is required');
return value.trim();
}),
controller.postUserProfile,
);
userProfileRouter
.route('/users/search')
.get(param('name').exists(), controller.searchUsersByName);
userProfileRouter.route('/userProfile/update').patch(controller.updateUserInformation);
userProfileRouter.route('/userProfile/basicInfo').get(controller.getUserProfileBasicInfo);
// Endpoint to retrieve basic user profile information after verifying access permission based on the request source.
userProfileRouter.route('/userProfile/basicInfo/:source').get(controller.getUserProfileBasicInfo);
userProfileRouter
.route('/userProfile/:userId')
.get(controller.getUserById)
.put(
body('firstName').customSanitizer((value) => {
if (!value) throw new ValidationError('First Name is required');
return value.trim();
}),
body('lastName').customSanitizer((value) => {
if (!value) throw new ValidationError('Last Name is required');
return value.trim();
}),
// body('personalLinks').customSanitizer((value) =>
// value.map((link) => {
// if (link.Name.replace(/\s/g, '') || link.Link.replace(/\s/g, '')) {
// return {
// ...link,
// Name: link.Name.trim(),
// Link: link.Link.replace(/\s/g, ''),
// };
// }
// throw new ValidationError('personalLinks not valid');
// }),
// ),
// body('adminLinks').customSanitizer((value) =>
// value.map((link) => {
// if (link.Name.replace(/\s/g, '') || link.Link.replace(/\s/g, '')) {
// return {
// ...link,
// Name: link.Name.trim(),
// Link: link.Link.replace(/\s/g, ''),
// };
// }
// throw new ValidationError('adminLinks not valid');
// }),
// ),
body('personalLinks')
.optional()
.customSanitizer((value) =>
value.map((link) => {
if (link.Name?.replace(/\s/g, '') || link.Link?.replace(/\s/g, '')) {
return {
...link,
Name: link.Name.trim(),
Link: link.Link.replace(/\s/g, ''),
};
}
throw new ValidationError('personalLinks not valid');
}),
),
body('adminLinks')
.optional()
.customSanitizer((value) =>
value.map((link) => {
if (link.Name?.replace(/\s/g, '') || link.Link?.replace(/\s/g, '')) {
return {
...link,
Name: link.Name.trim(),
Link: link.Link.replace(/\s/g, ''),
};
}
throw new ValidationError('adminLinks not valid');
}),
),
body('infringementCount')
.optional()
.isInt({ min: 0 })
.withMessage('InfringementCount must be a non-negative integer')
.toInt(),
controller.putUserProfile,
)
.delete(controller.deleteUserProfile)
.patch(controller.changeUserStatus);
userProfileRouter.route('/userProfile/name/:name').get(controller.getUserByName);
userProfileRouter.route('/userProfile/:userId/pause').patch(controller.pauseResumeUser);
userProfileRouter
.route('/userProfile/:userId/rehireable')
.patch(controller.changeUserRehireableStatus);
userProfileRouter
.route('/userProfile/:userId/toggleInvisibility')
.patch(controller.toggleInvisibility);
userProfileRouter
.route('/userProfile/singleName/:singleName')
.get(controller.getUserBySingleName);
userProfileRouter.route('/userProfile/fullName/:fullName').get(controller.getUserByFullName);
userProfileRouter.route('/refreshToken/:userId').get(controller.refreshToken);
userProfileRouter.route('/userProfile/reportees/:userId').get(controller.getreportees);
userProfileRouter.route('/userProfile/teammembers/:userId').get(controller.getTeamMembersofUser);
userProfileRouter.route('/userProfile/:userId/property').patch(controller.updateOneProperty);
userProfileRouter.route('/AllTeamCodeChanges').patch(controller.updateAllMembersTeamCode);
userProfileRouter.route('/userProfile/:userId/updatePassword').patch(controller.updatepassword);
userProfileRouter.route('/userProfile/:userId/resetPassword').patch(controller.resetPassword);
userProfileRouter.route('/userProfile/name/:userId').get(controller.getUserName);
userProfileRouter.route('/userProfile/project/:projectId').get(controller.getProjectMembers);
userProfileRouter
.route('/userProfile/socials/facebook')
.get(controller.getAllUsersWithFacebookLink);
userProfileRouter
.route('/userProfile/authorizeUser/weeeklySummaries')
.post(controller.authorizeUser);
userProfileRouter.route('/userProfile/:userId/addInfringement').post(controller.addInfringements);
userProfileRouter
.route('/userProfile/:userId/infringements/:blueSquareId')
.put(controller.editInfringements)
.delete(controller.deleteInfringements);
userProfileRouter.route('/userProfile/projects/:name').get(controller.getProjectsByPerson);
userProfileRouter.route('/userProfile/teamCode/list').get(controller.getAllTeamCode);
userProfileRouter.route('/userProfile/profileImage/remove').put(controller.removeProfileImage);
userProfileRouter
.route('/userProfile/profileImage/imagefromwebsite')
.put(controller.updateProfileImageFromWebsite);
userProfileRouter
.route('/userProfile/autocomplete/:searchText')
.get(controller.getUserByAutocomplete);
userProfileRouter.route('/userProfile/:userId/toggleBio').patch(controller.toggleUserBioPosted);
userProfileRouter.route('/userProfile/replaceTeamCode').post(controller.replaceTeamCodeForUsers);
userProfileRouter
.route('/userProfile/skills/:skill')
.get(controller.getAllMembersSkillsAndContact);
// Return the router
return userProfileRouter;
};
module.exports = routes;