@plusscommunities/pluss-maintenance-aws 2.0.3-beta.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createJob.js +57 -54
- package/db/maintenance/addMaintenanceJob.js +34 -3
- package/deleteJob.js +3 -3
- package/editJob.js +45 -50
- package/editJobStatus.js +16 -9
- package/editNote.js +6 -6
- package/feature.config.js +245 -1
- package/getData.js +41 -0
- package/getJob.js +10 -4
- package/getJobTypes.js +17 -3
- package/getJobs.js +1 -1
- package/package-lock.json +6201 -1649
- package/package.json +24 -16
- package/requests/assignRequest.js +100 -0
- package/requests/getAssignees.js +39 -0
- package/requests/getRequests.js +99 -0
- package/requests/helper/hasRequestPermission.js +24 -0
- package/requests/helper/isValidAssignee.js +18 -0
- package/sendJobEmail.js +41 -27
- package/updateData.js +33 -0
- package/watchJobs.js +180 -0
- package/serverless.yml +0 -390
package/createJob.js
CHANGED
|
@@ -5,10 +5,10 @@ const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
|
5
5
|
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
6
6
|
const addMaintenanceJob = require("./db/maintenance/addMaintenanceJob");
|
|
7
7
|
const validateSiteAccess = require("@plusscommunities/pluss-core-aws/helper/auth/validateSiteAccess");
|
|
8
|
-
const
|
|
8
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
9
9
|
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
10
|
-
const getUser = require("@plusscommunities/pluss-core-aws/db/users/getUser");
|
|
11
10
|
const sendJobEmail = require("./sendJobEmail");
|
|
11
|
+
const logAnalyticsActivity = require("@plusscommunities/pluss-core-aws/db/analytics/logAnalyticsActivity");
|
|
12
12
|
|
|
13
13
|
module.exports.createJob = (event, context, callback) => {
|
|
14
14
|
init(config);
|
|
@@ -19,7 +19,7 @@ module.exports.createJob = (event, context, callback) => {
|
|
|
19
19
|
if (!authorised) {
|
|
20
20
|
return callback(
|
|
21
21
|
null,
|
|
22
|
-
generateJsonResponse(
|
|
22
|
+
generateJsonResponse(403, { fail: true, error: "not authorised" })
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
if (
|
|
@@ -28,18 +28,18 @@ module.exports.createJob = (event, context, callback) => {
|
|
|
28
28
|
_.isUndefined(data.room) ||
|
|
29
29
|
_.isUndefined(data.description)
|
|
30
30
|
) {
|
|
31
|
-
console.error("insufficient input
|
|
31
|
+
console.error("insufficient input", data.userID);
|
|
32
32
|
return callback(
|
|
33
33
|
null,
|
|
34
34
|
generateJsonResponse(422, { error: "Insufficient input" })
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
|
-
const
|
|
37
|
+
const user = await getUserPreviewFromReq(event);
|
|
38
38
|
|
|
39
39
|
addMaintenanceJob(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
user.id,
|
|
41
|
+
user.displayName,
|
|
42
|
+
user,
|
|
43
43
|
data.phone,
|
|
44
44
|
data.room,
|
|
45
45
|
data.title,
|
|
@@ -50,55 +50,58 @@ module.exports.createJob = (event, context, callback) => {
|
|
|
50
50
|
data.images || data.image,
|
|
51
51
|
data.location,
|
|
52
52
|
data.audience
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
getUserPreviewFromHeader(event.headers.authkey).then((user) => {
|
|
73
|
-
publishActivity("AddMaintenanceJob", data.location, id, user, {
|
|
74
|
-
title: data.title,
|
|
75
|
-
description: data.description,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
53
|
+
).then((id) => {
|
|
54
|
+
sendJobEmail({
|
|
55
|
+
userID: user.id,
|
|
56
|
+
userName: user.displayName,
|
|
57
|
+
phone: data.phone,
|
|
58
|
+
room: data.room,
|
|
59
|
+
title: data.title,
|
|
60
|
+
description: data.description,
|
|
61
|
+
type: data.type,
|
|
62
|
+
isHome: data.isHome,
|
|
63
|
+
homeText: data.homeText,
|
|
64
|
+
image: data.image,
|
|
65
|
+
images: data.images,
|
|
66
|
+
site: data.location,
|
|
67
|
+
audience: data.audience,
|
|
68
|
+
id,
|
|
69
|
+
});
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
success: true,
|
|
83
|
-
searchResult: id,
|
|
84
|
-
})
|
|
85
|
-
);
|
|
86
|
-
})
|
|
87
|
-
.catch((error) => {
|
|
88
|
-
console.error(
|
|
89
|
-
"Failed to save maintenance node --> email successful",
|
|
90
|
-
data.userID
|
|
91
|
-
);
|
|
92
|
-
console.log(error);
|
|
93
|
-
return callback(
|
|
94
|
-
null,
|
|
95
|
-
generateJsonResponse(422, {
|
|
96
|
-
error,
|
|
97
|
-
})
|
|
98
|
-
);
|
|
71
|
+
publishActivity("AddMaintenanceJob", data.location, id, user, {
|
|
72
|
+
title: data.title,
|
|
73
|
+
description: data.description,
|
|
99
74
|
});
|
|
75
|
+
|
|
76
|
+
logAnalyticsActivity(
|
|
77
|
+
`Request`,
|
|
78
|
+
"maintenancerequest",
|
|
79
|
+
data.location,
|
|
80
|
+
user,
|
|
81
|
+
id
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return callback(
|
|
85
|
+
null,
|
|
86
|
+
generateJsonResponse(200, {
|
|
87
|
+
success: true,
|
|
88
|
+
id,
|
|
89
|
+
searchResult: id,
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
});
|
|
100
93
|
})
|
|
101
94
|
.catch((error) => {
|
|
102
|
-
|
|
95
|
+
console.error(
|
|
96
|
+
"Failed to save maintenance node --> email successful",
|
|
97
|
+
data.userID
|
|
98
|
+
);
|
|
99
|
+
console.log(error);
|
|
100
|
+
return callback(
|
|
101
|
+
null,
|
|
102
|
+
generateJsonResponse(422, {
|
|
103
|
+
error,
|
|
104
|
+
})
|
|
105
|
+
);
|
|
103
106
|
});
|
|
104
107
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const moment = require("moment");
|
|
2
2
|
const _ = require("lodash");
|
|
3
3
|
const uuid = require("uuid");
|
|
4
|
-
const
|
|
4
|
+
const indexQuery = require("@plusscommunities/pluss-core-aws/db/common/indexQuery");
|
|
5
5
|
const updateRef = require("@plusscommunities/pluss-core-aws/db/common/updateRef");
|
|
6
6
|
const { getConfig } = require("@plusscommunities/pluss-core-aws/config");
|
|
7
7
|
|
|
@@ -63,8 +63,39 @@ module.exports = async (
|
|
|
63
63
|
requestToSave.id = uuid.v1();
|
|
64
64
|
requestToSave.createdTime = moment.utc().toISOString();
|
|
65
65
|
requestToSave.createdUnix = moment.utc().valueOf();
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
if (!requestToSave.jobId) {
|
|
67
|
+
const jobNoQ = {
|
|
68
|
+
IndexName: "MaintenanceSiteJobNoIndex",
|
|
69
|
+
KeyConditionExpression: "site = :site",
|
|
70
|
+
ExpressionAttributeValues: {
|
|
71
|
+
":site": requestToSave.site,
|
|
72
|
+
},
|
|
73
|
+
Limit: 1,
|
|
74
|
+
ScanIndexForward: false,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const queryRes = await indexQuery("maintenance", jobNoQ);
|
|
78
|
+
|
|
79
|
+
if (!_.isEmpty(queryRes.Items)) {
|
|
80
|
+
requestToSave.jobNo = queryRes.Items[0].jobNo + 1;
|
|
81
|
+
} else {
|
|
82
|
+
const query = {
|
|
83
|
+
IndexName: "MaintenanceSiteJobIdIndex",
|
|
84
|
+
KeyConditionExpression: "site = :site",
|
|
85
|
+
ExpressionAttributeValues: {
|
|
86
|
+
":site": requestToSave.site,
|
|
87
|
+
},
|
|
88
|
+
Limit: 1,
|
|
89
|
+
ScanIndexForward: false,
|
|
90
|
+
};
|
|
91
|
+
const { Items } = await indexQuery("maintenance", query);
|
|
92
|
+
requestToSave.jobNo =
|
|
93
|
+
!_.isEmpty(Items) && Items[0].jobId
|
|
94
|
+
? Number.parseInt(Items[0].jobId) + 1
|
|
95
|
+
: 0;
|
|
96
|
+
}
|
|
97
|
+
requestToSave.jobId = (requestToSave.jobNo || 0) + "";
|
|
98
|
+
}
|
|
68
99
|
|
|
69
100
|
await updateRef("maintenance", requestToSave);
|
|
70
101
|
return requestToSave.id;
|
package/deleteJob.js
CHANGED
|
@@ -5,8 +5,8 @@ const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/ge
|
|
|
5
5
|
const deleteRef = require("@plusscommunities/pluss-core-aws/db/common/deleteRef");
|
|
6
6
|
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
7
7
|
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
8
|
-
const getUserPreviewFromHeader = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromHeader");
|
|
9
8
|
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
9
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
10
10
|
|
|
11
11
|
module.exports.deleteJob = (event, context, callback) => {
|
|
12
12
|
init(config);
|
|
@@ -25,7 +25,7 @@ module.exports.deleteJob = (event, context, callback) => {
|
|
|
25
25
|
console.error("Authorization not valid");
|
|
26
26
|
callback(
|
|
27
27
|
null,
|
|
28
|
-
generateJsonResponse(
|
|
28
|
+
generateJsonResponse(403, {
|
|
29
29
|
error: {
|
|
30
30
|
message: "Authorization not valid.",
|
|
31
31
|
},
|
|
@@ -47,7 +47,7 @@ module.exports.deleteJob = (event, context, callback) => {
|
|
|
47
47
|
}
|
|
48
48
|
deleteRef("maintenance", "id", data.id)
|
|
49
49
|
.then(() => {
|
|
50
|
-
|
|
50
|
+
getUserPreviewFromReq(event).then((user) => {
|
|
51
51
|
publishActivity("DeleteMaintenanceJob", data.site, data.id, user, {
|
|
52
52
|
title: result.title,
|
|
53
53
|
description: result.description,
|
package/editJob.js
CHANGED
|
@@ -2,14 +2,14 @@ const _ = require("lodash");
|
|
|
2
2
|
const config = require("./config.json");
|
|
3
3
|
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
4
4
|
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
5
|
-
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
6
5
|
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
7
6
|
const sendJobEmail = require("./sendJobEmail");
|
|
8
7
|
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
9
8
|
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
10
|
-
const getUserPreviewFromHeader = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromHeader");
|
|
11
9
|
const editMaintenanceJob = require("./db/maintenance/editMaintenanceJob");
|
|
12
10
|
const { getConfig } = require("@plusscommunities/pluss-core-aws/config");
|
|
11
|
+
const hasRequestPermission = require("./requests/helper/hasRequestPermission");
|
|
12
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
13
13
|
|
|
14
14
|
module.exports.editJob = (event, context, callback) => {
|
|
15
15
|
init(config);
|
|
@@ -24,55 +24,50 @@ module.exports.editJob = (event, context, callback) => {
|
|
|
24
24
|
|
|
25
25
|
getRef("maintenance", "id", data.job.id)
|
|
26
26
|
.then((prevData) => {
|
|
27
|
-
|
|
28
|
-
(authorised)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
getUserPreviewFromHeader(event.headers.authkey).then((user) => {
|
|
39
|
-
editMaintenanceJob(data.job)
|
|
40
|
-
.then((result) => {
|
|
41
|
-
if (!getConfig().maintenanceInstantComplete) {
|
|
42
|
-
sendJobEmail(data.job, true);
|
|
43
|
-
publishActivity(
|
|
44
|
-
"EditMaintenanceJob",
|
|
45
|
-
data.site,
|
|
46
|
-
data.job.id,
|
|
47
|
-
user,
|
|
48
|
-
{ title: result.title, description: result.description }
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return callback(
|
|
53
|
-
null,
|
|
54
|
-
generateJsonResponse(200, {
|
|
55
|
-
success: true,
|
|
56
|
-
job: result,
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
})
|
|
60
|
-
.catch((error) => {
|
|
61
|
-
console.log(error);
|
|
62
|
-
console.error(
|
|
63
|
-
"Failed to edit maintenance node -->",
|
|
64
|
-
data.job.id
|
|
65
|
-
);
|
|
66
|
-
return callback(
|
|
67
|
-
null,
|
|
68
|
-
generateJsonResponse(422, {
|
|
69
|
-
error,
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
27
|
+
hasRequestPermission(event, prevData).then((authorised) => {
|
|
28
|
+
if (!authorised) {
|
|
29
|
+
console.error("Authorization not valid");
|
|
30
|
+
return callback(
|
|
31
|
+
null,
|
|
32
|
+
generateJsonResponse(422, {
|
|
33
|
+
error: { message: "not authorized." },
|
|
34
|
+
})
|
|
35
|
+
);
|
|
74
36
|
}
|
|
75
|
-
|
|
37
|
+
getUserPreviewFromReq(event).then((user) => {
|
|
38
|
+
editMaintenanceJob(data.job)
|
|
39
|
+
.then((result) => {
|
|
40
|
+
if (!getConfig().maintenanceInstantComplete) {
|
|
41
|
+
sendJobEmail(data.job, true);
|
|
42
|
+
publishActivity(
|
|
43
|
+
"EditMaintenanceJob",
|
|
44
|
+
data.site,
|
|
45
|
+
data.job.id,
|
|
46
|
+
user,
|
|
47
|
+
{ title: result.title, description: result.description }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return callback(
|
|
52
|
+
null,
|
|
53
|
+
generateJsonResponse(200, {
|
|
54
|
+
success: true,
|
|
55
|
+
job: result,
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
console.log(error);
|
|
61
|
+
console.error("Failed to edit maintenance node -->", data.job.id);
|
|
62
|
+
return callback(
|
|
63
|
+
null,
|
|
64
|
+
generateJsonResponse(422, {
|
|
65
|
+
error,
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
76
71
|
})
|
|
77
72
|
.catch((error) => {
|
|
78
73
|
console.log("Fail on edit job authentication");
|
package/editJobStatus.js
CHANGED
|
@@ -5,11 +5,12 @@ const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
|
5
5
|
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
6
6
|
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
7
7
|
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
8
|
-
const
|
|
9
|
-
const getUserPreviewFromHeader = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromHeader");
|
|
8
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
10
9
|
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
11
10
|
const publishNotifications = require("@plusscommunities/pluss-core-aws/db/notifications/publishNotifications");
|
|
12
11
|
const editMaintenanceJob = require("./db/maintenance/editMaintenanceJob");
|
|
12
|
+
const logAnalyticsActivity = require("@plusscommunities/pluss-core-aws/db/analytics/logAnalyticsActivity");
|
|
13
|
+
const hasRequestPermission = require("./requests/helper/hasRequestPermission");
|
|
13
14
|
|
|
14
15
|
module.exports.editJobStatus = async (event, context, callback) => {
|
|
15
16
|
init(config);
|
|
@@ -17,16 +18,12 @@ module.exports.editJobStatus = async (event, context, callback) => {
|
|
|
17
18
|
|
|
18
19
|
try {
|
|
19
20
|
const job = await getRef("maintenance", "id", data.id);
|
|
20
|
-
const authorised = await
|
|
21
|
-
event,
|
|
22
|
-
"maintenanceTracking",
|
|
23
|
-
job.site || job.location
|
|
24
|
-
);
|
|
21
|
+
const authorised = await hasRequestPermission(event, job);
|
|
25
22
|
if (!authorised) {
|
|
26
23
|
console.error("Authorization not valid");
|
|
27
24
|
return callback(
|
|
28
25
|
null,
|
|
29
|
-
generateJsonResponse(
|
|
26
|
+
generateJsonResponse(403, {
|
|
30
27
|
error: {
|
|
31
28
|
message: "Authorization not valid.",
|
|
32
29
|
},
|
|
@@ -34,7 +31,7 @@ module.exports.editJobStatus = async (event, context, callback) => {
|
|
|
34
31
|
);
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
const user = await
|
|
34
|
+
const user = await getUserPreviewFromReq(event);
|
|
38
35
|
|
|
39
36
|
// Update history
|
|
40
37
|
if (!job.history) job.history = [];
|
|
@@ -55,6 +52,16 @@ module.exports.editJobStatus = async (event, context, callback) => {
|
|
|
55
52
|
{ title: result.title, status: result.status }
|
|
56
53
|
);
|
|
57
54
|
|
|
55
|
+
if (job.status === "Completed") {
|
|
56
|
+
logAnalyticsActivity(
|
|
57
|
+
`RequestCompleted`,
|
|
58
|
+
"maintenancerequest",
|
|
59
|
+
result.site,
|
|
60
|
+
user,
|
|
61
|
+
result.id
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
if (result.userID) {
|
|
59
66
|
publishNotifications(
|
|
60
67
|
[result.userID],
|
package/editNote.js
CHANGED
|
@@ -4,12 +4,12 @@ const moment = require("moment");
|
|
|
4
4
|
const config = require("./config.json");
|
|
5
5
|
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
6
6
|
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
7
|
-
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
8
7
|
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
9
8
|
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
10
9
|
const updateRef = require("@plusscommunities/pluss-core-aws/db/common/updateRef");
|
|
11
10
|
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
12
|
-
const
|
|
11
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
12
|
+
const hasRequestPermission = require("./requests/helper/hasRequestPermission");
|
|
13
13
|
|
|
14
14
|
module.exports.editNote = (event, context, callback) => {
|
|
15
15
|
init(config);
|
|
@@ -51,18 +51,18 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
getRef("maintenance", "id", data.id).then((job) => {
|
|
54
|
-
|
|
54
|
+
hasRequestPermission(event, job)
|
|
55
55
|
.then((authorised) => {
|
|
56
56
|
if (!authorised) {
|
|
57
57
|
console.error("Authorization not valid");
|
|
58
58
|
return callback(
|
|
59
59
|
null,
|
|
60
|
-
generateJsonResponse(
|
|
60
|
+
generateJsonResponse(403, {
|
|
61
61
|
error: { message: "not authorized." },
|
|
62
62
|
})
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
getUserPreviewFromReq(event).then((user) => {
|
|
66
66
|
let activityAction = "";
|
|
67
67
|
switch (data.action) {
|
|
68
68
|
case "AddNote":
|
|
@@ -91,7 +91,7 @@ module.exports.editNote = (event, context, callback) => {
|
|
|
91
91
|
if (!note) {
|
|
92
92
|
return callback(
|
|
93
93
|
null,
|
|
94
|
-
generateJsonResponse(
|
|
94
|
+
generateJsonResponse(404, {
|
|
95
95
|
error: { message: "Note not found" },
|
|
96
96
|
})
|
|
97
97
|
);
|