@tiledesk/tiledesk-server 2.9.4 → 2.9.5

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.9.5
9
+ - Added raw option in /users/availables
10
+
8
11
  # 2.9.4
9
12
  - Update tybot-connector to 0.2.86
10
13
  - Added time-slots management
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.9.4",
4
+ "version": "2.9.5",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/project.js CHANGED
@@ -886,52 +886,81 @@ router.get('/:projectid/isopen', function (req, res) {
886
886
  router.get('/:projectid/users/availables', function (req, res) {
887
887
  //winston.debug("PROJECT ROUTES FINDS AVAILABLES project_users: projectid", req.params.projectid);
888
888
 
889
- operatingHoursService.projectIsOpenNow(req.params.projectid, function (isOpen, err) {
890
- //winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PROJECT: ', isOpen);
891
-
892
- if (err) {
893
- winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PROJECT - EROR: ', err)
894
- // sendError(err, res);
895
- return res.status(500).send({ success: false, msg: err });
896
- } else if (isOpen) {
897
-
898
- Project_user.find({ id_project: req.params.projectid, user_available: true, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}}).
899
- populate('id_user').
900
- exec(function (err, project_users) {
901
- if (err) {
902
- winston.debug('PROJECT ROUTES - FINDS AVAILABLES project_users - ERROR: ', err);
903
- return res.status(500).send({ success: false, msg: 'Error getting object.' });
904
- }
905
- if (project_users) {
906
-
907
- user_available_array = [];
908
- project_users.forEach(project_user => {
909
- if (project_user.id_user) {
910
- // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER: ', project_user)
911
- user_available_array.push({ "id": project_user.id_user._id, "firstname": project_user.id_user.firstname });
912
- } else {
913
- // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER (else): ', project_user)
914
- }
915
- });
916
-
917
- //winston.debug('ARRAY OF THE AVAILABLE USER ', user_available_array);
918
-
919
- res.json(user_available_array);
920
- }
921
- });
922
-
889
+ if (req.query.raw && (req.query.raw === true || req.query.raw === 'true')) {
890
+ Project_user.find({ id_project: req.params.projectid, user_available: true, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}}).
891
+ populate('id_user').
892
+ exec(function (err, project_users) {
893
+ if (err) {
894
+ winston.debug('PROJECT ROUTES - FINDS AVAILABLES project_users - ERROR: ', err);
895
+ return res.status(500).send({ success: false, msg: 'Error getting object.' });
896
+ }
897
+ if (project_users) {
898
+
899
+ user_available_array = [];
900
+ project_users.forEach(project_user => {
901
+ if (project_user.id_user) {
902
+ // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER: ', project_user)
903
+ user_available_array.push({ "id": project_user.id_user._id, "firstname": project_user.id_user.firstname });
904
+ } else {
905
+ // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER (else): ', project_user)
906
+ }
907
+ });
908
+
909
+ //winston.debug('ARRAY OF THE AVAILABLE USER ', user_available_array);
910
+ res.json(user_available_array);
911
+ }
912
+ });
913
+ } else {
914
+ operatingHoursService.projectIsOpenNow(req.params.projectid, function (isOpen, err) {
915
+ //winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PROJECT: ', isOpen);
916
+
917
+ if (err) {
918
+ winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PROJECT - EROR: ', err)
919
+ // sendError(err, res);
920
+ return res.status(500).send({ success: false, msg: err });
921
+ } else if (isOpen) {
922
+
923
+ Project_user.find({ id_project: req.params.projectid, user_available: true, role: { $in : [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT]}}).
924
+ populate('id_user').
925
+ exec(function (err, project_users) {
926
+ if (err) {
927
+ winston.debug('PROJECT ROUTES - FINDS AVAILABLES project_users - ERROR: ', err);
928
+ return res.status(500).send({ success: false, msg: 'Error getting object.' });
929
+ }
930
+ if (project_users) {
931
+
932
+ user_available_array = [];
933
+ project_users.forEach(project_user => {
934
+ if (project_user.id_user) {
935
+ // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER: ', project_user)
936
+ user_available_array.push({ "id": project_user.id_user._id, "firstname": project_user.id_user.firstname });
937
+ } else {
938
+ // winston.debug('PROJECT ROUTES - AVAILABLES PROJECT-USER (else): ', project_user)
939
+ }
940
+ });
941
+
942
+ //winston.debug('ARRAY OF THE AVAILABLE USER ', user_available_array);
943
+
944
+ res.json(user_available_array);
945
+ }
946
+ });
947
+
948
+
949
+ } else {
950
+ // winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PRJCT: ', isOpen, ' -> AVAILABLE EMPTY');
951
+ // closed
952
+ user_available_array = [];
953
+ res.json(user_available_array);
954
+ }
955
+ });
956
+ }
923
957
 
924
- } else {
925
- // winston.debug('P ---> [ OHS ] -> [ PROJECT ROUTES ] -> IS OPEN THE PRJCT: ', isOpen, ' -> AVAILABLE EMPTY');
926
- // closed
927
- user_available_array = [];
928
- res.json(user_available_array);
929
- }
930
- });
958
+
931
959
 
932
960
  });
933
961
 
934
962
 
935
963
 
936
964
 
965
+
937
966
  module.exports = router;