@plusscommunities/pluss-maintenance-aws-forms 2.1.7-beta.0
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 +136 -0
- package/createJobType.js +64 -0
- package/db/maintenance/addMaintenanceJob.js +105 -0
- package/db/maintenance/editMaintenanceJob.js +18 -0
- package/db/maintenance/getJobEmail.js +28 -0
- package/deleteJob.js +74 -0
- package/deleteJobType.js +54 -0
- package/editJob.js +83 -0
- package/editJobStatus.js +81 -0
- package/editJobType.js +76 -0
- package/editNote.js +134 -0
- package/feature.config.js +255 -0
- package/getData.js +49 -0
- package/getJob.js +14 -0
- package/getJobType.js +47 -0
- package/getJobTypes.js +70 -0
- package/getJobs.js +63 -0
- package/integration/IntegrationStrategy.js +35 -0
- package/integration/archibus/ArchibusStrategy.js +463 -0
- package/integration/index.js +23 -0
- package/jobChanged.js +73 -0
- package/package-lock.json +7653 -0
- package/package.json +64 -0
- package/requests/assignRequest.js +106 -0
- package/requests/getAssignees.js +40 -0
- package/requests/getRequest.js +89 -0
- package/requests/getRequests.js +100 -0
- package/requests/helper/hasRequestPermission.js +25 -0
- package/requests/helper/isValidAssignee.js +23 -0
- package/scheduleJobImport.js +81 -0
- package/sendJobEmail.js +153 -0
- package/updateData.js +33 -0
- package/values.config.a.js +26 -0
- package/values.config.b.js +26 -0
- package/values.config.c.js +26 -0
- package/values.config.d.js +26 -0
- package/values.config.default.js +28 -0
- package/values.config.forms.js +28 -0
- package/values.config.js +28 -0
- package/watchJobs.js +177 -0
package/editJobType.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const config = require("./config.json");
|
|
2
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
3
|
+
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
4
|
+
const validateMasterAuth = require("@plusscommunities/pluss-core-aws/helper/auth/validateMasterAuth");
|
|
5
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
6
|
+
const editRef = require("@plusscommunities/pluss-core-aws/db/common/editRef");
|
|
7
|
+
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
8
|
+
const { values } = require("./values.config");
|
|
9
|
+
|
|
10
|
+
module.exports.editJobType = (event, context, callback) => {
|
|
11
|
+
init(config);
|
|
12
|
+
const data = getBody(event);
|
|
13
|
+
|
|
14
|
+
if (!data.site || !data.name || !data.email || !data.description) {
|
|
15
|
+
return callback(
|
|
16
|
+
null,
|
|
17
|
+
generateJsonResponse(422, { error: "No site, type or email attached" })
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
validateMasterAuth(event, values.permissionMaintenanceTypes).then(
|
|
22
|
+
(authorised) => {
|
|
23
|
+
if (!authorised) {
|
|
24
|
+
console.error("Authorization not valid");
|
|
25
|
+
return callback(
|
|
26
|
+
null,
|
|
27
|
+
generateJsonResponse(422, {
|
|
28
|
+
error: { message: "Admin - Create User - not authorized." },
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const jobType = {
|
|
34
|
+
id: data.id,
|
|
35
|
+
email: data.email,
|
|
36
|
+
typeName: data.name,
|
|
37
|
+
description: data.description,
|
|
38
|
+
level: data.level,
|
|
39
|
+
site: data.site,
|
|
40
|
+
hasCustomFields: data.hasCustomFields ?? false,
|
|
41
|
+
customFields: data.customFields ?? [],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
getRef(values.tableNameJobTypes, "id", data.id).then((result) => {
|
|
45
|
+
if (result.site !== data.site) {
|
|
46
|
+
return callback(
|
|
47
|
+
null,
|
|
48
|
+
generateJsonResponse(422, {
|
|
49
|
+
error: {
|
|
50
|
+
message: "Incorrect site.",
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
editRef(values.tableNameJobTypes, "id", data.id, jobType)
|
|
56
|
+
.then((result) => {
|
|
57
|
+
return callback(
|
|
58
|
+
null,
|
|
59
|
+
generateJsonResponse(200, {
|
|
60
|
+
success: true,
|
|
61
|
+
jobType: result,
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
})
|
|
65
|
+
.catch((error) => {
|
|
66
|
+
return callback(
|
|
67
|
+
null,
|
|
68
|
+
generateJsonResponse(422, {
|
|
69
|
+
error,
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
};
|
package/editNote.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const uuid = require("uuid");
|
|
3
|
+
const moment = require("moment");
|
|
4
|
+
const config = require("./config.json");
|
|
5
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
6
|
+
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
7
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
8
|
+
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
9
|
+
const updateRef = require("@plusscommunities/pluss-core-aws/db/common/updateRef");
|
|
10
|
+
const publishActivity = require("@plusscommunities/pluss-core-aws/db/activity/publishActivity");
|
|
11
|
+
const getUserPreviewFromReq = require("@plusscommunities/pluss-core-aws/helper/getUserPreviewFromReq");
|
|
12
|
+
const hasRequestPermission = require("./requests/helper/hasRequestPermission");
|
|
13
|
+
const { values } = require("./values.config");
|
|
14
|
+
|
|
15
|
+
module.exports.editNote = (event, context, callback) => {
|
|
16
|
+
init(config);
|
|
17
|
+
const data = getBody(event);
|
|
18
|
+
|
|
19
|
+
if (!data.action || !data.id) {
|
|
20
|
+
return callback(
|
|
21
|
+
null,
|
|
22
|
+
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
switch (data.action) {
|
|
26
|
+
case "AddNote":
|
|
27
|
+
if (!data.note && !data.attachments) {
|
|
28
|
+
return callback(
|
|
29
|
+
null,
|
|
30
|
+
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "DeleteNote":
|
|
35
|
+
if (!data.noteId) {
|
|
36
|
+
return callback(
|
|
37
|
+
null,
|
|
38
|
+
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case "EditNote":
|
|
43
|
+
if ((!data.note && !data.attachments) || !data.noteId) {
|
|
44
|
+
return callback(
|
|
45
|
+
null,
|
|
46
|
+
generateJsonResponse(422, { error: { message: "Incomplete data" } })
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getRef(values.tableNameMaintenance, "id", data.id).then((job) => {
|
|
55
|
+
hasRequestPermission(event, job)
|
|
56
|
+
.then((authorised) => {
|
|
57
|
+
if (!authorised) {
|
|
58
|
+
console.error("Authorization not valid");
|
|
59
|
+
return callback(
|
|
60
|
+
null,
|
|
61
|
+
generateJsonResponse(403, {
|
|
62
|
+
error: { message: "not authorized." },
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
getUserPreviewFromReq(event).then((user) => {
|
|
67
|
+
let activityAction = "";
|
|
68
|
+
switch (data.action) {
|
|
69
|
+
case "AddNote":
|
|
70
|
+
if (!job.Notes) {
|
|
71
|
+
job.Notes = [];
|
|
72
|
+
}
|
|
73
|
+
job.Notes.push({
|
|
74
|
+
Id: uuid.v4(),
|
|
75
|
+
Timestamp: moment.utc().valueOf(),
|
|
76
|
+
User: user,
|
|
77
|
+
Note: data.note,
|
|
78
|
+
Attachments: data.attachments,
|
|
79
|
+
});
|
|
80
|
+
activityAction = values.activityAddMaintenanceNote;
|
|
81
|
+
break;
|
|
82
|
+
case "DeleteNote":
|
|
83
|
+
job.Notes = _.filter(job.Notes, (n) => {
|
|
84
|
+
return n.Id !== data.noteId;
|
|
85
|
+
});
|
|
86
|
+
activityAction = values.activityDeleteMaintenanceNote;
|
|
87
|
+
break;
|
|
88
|
+
case "EditNote":
|
|
89
|
+
const note = _.find(job.Notes, (n) => {
|
|
90
|
+
return n.Id === data.noteId;
|
|
91
|
+
});
|
|
92
|
+
if (!note) {
|
|
93
|
+
return callback(
|
|
94
|
+
null,
|
|
95
|
+
generateJsonResponse(404, {
|
|
96
|
+
error: { message: "Note not found" },
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
note.Note = data.note;
|
|
101
|
+
note.Attachments = data.attachments;
|
|
102
|
+
activityAction = values.activityEditMaintenanceNote;
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
updateRef(values.tableNameMaintenance, job).then((result) => {
|
|
108
|
+
publishActivity(activityAction, result.site, result.id, user, {
|
|
109
|
+
title: result.title,
|
|
110
|
+
description: result.description,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return callback(
|
|
114
|
+
null,
|
|
115
|
+
generateJsonResponse(200, {
|
|
116
|
+
success: true,
|
|
117
|
+
job: result,
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
})
|
|
123
|
+
.catch((error) => {
|
|
124
|
+
console.log("Fail on edit job authentication");
|
|
125
|
+
console.log(error);
|
|
126
|
+
return callback(
|
|
127
|
+
null,
|
|
128
|
+
generateJsonResponse(422, {
|
|
129
|
+
error,
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const { values } = require("./values.config");
|
|
2
|
+
|
|
3
|
+
exports.permissions = [
|
|
4
|
+
values.permissionMaintenanceTracking,
|
|
5
|
+
values.permissionMaintenanceAssignment,
|
|
6
|
+
values.permissionMaintenanceTypes,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
exports.entity = {
|
|
10
|
+
key: values.entityKey,
|
|
11
|
+
permission: values.permissionMaintenanceTracking,
|
|
12
|
+
table: values.tableNameMaintenance,
|
|
13
|
+
id: "id",
|
|
14
|
+
webPath: values.routeEntityPath,
|
|
15
|
+
appPath: values.screenMaintenanceDetail,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.serverless = {
|
|
19
|
+
name: values.serviceKey,
|
|
20
|
+
apis: [
|
|
21
|
+
{
|
|
22
|
+
name: "getJobType",
|
|
23
|
+
file: "getJobType",
|
|
24
|
+
function: "getJobType",
|
|
25
|
+
memorySize: 256,
|
|
26
|
+
timeout: 10,
|
|
27
|
+
path: "getjobtype",
|
|
28
|
+
method: "post",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "getJobTypes",
|
|
32
|
+
file: "getJobTypes",
|
|
33
|
+
function: "getJobTypes",
|
|
34
|
+
memorySize: 256,
|
|
35
|
+
timeout: 10,
|
|
36
|
+
path: "getjobtypes",
|
|
37
|
+
method: "post",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "createJobType",
|
|
41
|
+
file: "createJobType",
|
|
42
|
+
function: "createJobType",
|
|
43
|
+
memorySize: 256,
|
|
44
|
+
timeout: 10,
|
|
45
|
+
path: "createJobType",
|
|
46
|
+
method: "post",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "editJobType",
|
|
50
|
+
file: "editJobType",
|
|
51
|
+
function: "editJobType",
|
|
52
|
+
memorySize: 256,
|
|
53
|
+
timeout: 10,
|
|
54
|
+
path: "editJobType",
|
|
55
|
+
method: "post",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "deleteJobType",
|
|
59
|
+
file: "deleteJobType",
|
|
60
|
+
function: "deleteJobType",
|
|
61
|
+
memorySize: 256,
|
|
62
|
+
timeout: 10,
|
|
63
|
+
path: "deleteJobType",
|
|
64
|
+
method: "post",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "getJob",
|
|
68
|
+
file: "getJob",
|
|
69
|
+
function: "getJob",
|
|
70
|
+
memorySize: 256,
|
|
71
|
+
timeout: 10,
|
|
72
|
+
path: "getJob",
|
|
73
|
+
method: "post",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "getJobs",
|
|
77
|
+
file: "getJobs",
|
|
78
|
+
function: "getJobs",
|
|
79
|
+
memorySize: 256,
|
|
80
|
+
timeout: 10,
|
|
81
|
+
path: "getJobs",
|
|
82
|
+
method: "post",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "createJob",
|
|
86
|
+
file: "createJob",
|
|
87
|
+
function: "createJob",
|
|
88
|
+
memorySize: 256,
|
|
89
|
+
timeout: 10,
|
|
90
|
+
path: "sendMaintenance",
|
|
91
|
+
method: "post",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "editJob",
|
|
95
|
+
file: "editJob",
|
|
96
|
+
function: "editJob",
|
|
97
|
+
memorySize: 256,
|
|
98
|
+
timeout: 10,
|
|
99
|
+
path: "editJob",
|
|
100
|
+
method: "post",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "deleteJob",
|
|
104
|
+
file: "deleteJob",
|
|
105
|
+
function: "deleteJob",
|
|
106
|
+
memorySize: 256,
|
|
107
|
+
timeout: 10,
|
|
108
|
+
path: "requests/remove",
|
|
109
|
+
method: "post",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "editJobStatus",
|
|
113
|
+
file: "editJobStatus",
|
|
114
|
+
function: "editJobStatus",
|
|
115
|
+
memorySize: 256,
|
|
116
|
+
timeout: 10,
|
|
117
|
+
path: "editJobStatus",
|
|
118
|
+
method: "post",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "editNote",
|
|
122
|
+
file: "editNote",
|
|
123
|
+
function: "editNote",
|
|
124
|
+
memorySize: 256,
|
|
125
|
+
timeout: 10,
|
|
126
|
+
path: "requests/note",
|
|
127
|
+
method: "post",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "getData",
|
|
131
|
+
file: "getData",
|
|
132
|
+
function: "getData",
|
|
133
|
+
memorySize: 256,
|
|
134
|
+
timeout: 10,
|
|
135
|
+
path: "get/{action}",
|
|
136
|
+
method: "get",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "updateData",
|
|
140
|
+
file: "updateData",
|
|
141
|
+
function: "updateData",
|
|
142
|
+
memorySize: 256,
|
|
143
|
+
timeout: 10,
|
|
144
|
+
path: "update/{action}",
|
|
145
|
+
method: "post",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
triggers: [
|
|
149
|
+
{
|
|
150
|
+
name: "jobChanged",
|
|
151
|
+
file: "jobChanged",
|
|
152
|
+
function: "jobChanged",
|
|
153
|
+
memorySize: 2048,
|
|
154
|
+
timeout: 300,
|
|
155
|
+
table: values.tableKeyMaintenance,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
schedules: [
|
|
159
|
+
{
|
|
160
|
+
name: "watchJobs",
|
|
161
|
+
file: "watchJobs",
|
|
162
|
+
function: "watchJobs",
|
|
163
|
+
memorySize: "2048",
|
|
164
|
+
timeout: "300",
|
|
165
|
+
rate: "1/5 * * * ? *",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "scheduleJobImport",
|
|
169
|
+
file: "scheduleJobImport",
|
|
170
|
+
function: "scheduleJobImport",
|
|
171
|
+
memorySize: "2048",
|
|
172
|
+
timeout: "300",
|
|
173
|
+
rate: "2/3 * * * ? *",
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
tables: [
|
|
177
|
+
{
|
|
178
|
+
key: values.tableKeyJobTypes,
|
|
179
|
+
name: values.tableNameJobTypes,
|
|
180
|
+
attributes: [
|
|
181
|
+
{ name: "id", type: "S" },
|
|
182
|
+
{ name: "site", type: "S" },
|
|
183
|
+
{ name: "typeName", type: "S" },
|
|
184
|
+
],
|
|
185
|
+
id: "id",
|
|
186
|
+
indexes: [
|
|
187
|
+
{
|
|
188
|
+
name: "JobTypeSiteIndex",
|
|
189
|
+
keys: [
|
|
190
|
+
{ name: "site", type: "HASH" },
|
|
191
|
+
{ name: "typeName", type: "RANGE" },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
key: values.tableKeyMaintenance,
|
|
198
|
+
name: values.tableNameMaintenance,
|
|
199
|
+
attributes: [
|
|
200
|
+
{ name: "id", type: "S" },
|
|
201
|
+
{ name: "site", type: "S" },
|
|
202
|
+
{ name: "jobId", type: "S" },
|
|
203
|
+
{ name: "jobNo", type: "N" },
|
|
204
|
+
{ name: "userID", type: "S" },
|
|
205
|
+
],
|
|
206
|
+
id: "id",
|
|
207
|
+
indexes: [
|
|
208
|
+
{
|
|
209
|
+
name: "MaintenanceSiteIndex",
|
|
210
|
+
keys: [{ name: "site", type: "HASH" }],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "MaintenanceSiteJobIdIndex",
|
|
214
|
+
keys: [
|
|
215
|
+
{ name: "site", type: "HASH" },
|
|
216
|
+
{ name: "jobId", type: "RANGE" },
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "MaintenanceSiteJobNoIndex",
|
|
221
|
+
keys: [
|
|
222
|
+
{ name: "site", type: "HASH" },
|
|
223
|
+
{ name: "jobNo", type: "RANGE" },
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "MaintenanceSiteUserIdIndex",
|
|
228
|
+
keys: [
|
|
229
|
+
{ name: "site", type: "HASH" },
|
|
230
|
+
{ name: "userID", type: "RANGE" },
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
key: values.tableKeySupportTickets,
|
|
237
|
+
name: values.tableNameSupportTickets,
|
|
238
|
+
attributes: [
|
|
239
|
+
{ name: "Id", type: "S" },
|
|
240
|
+
{ name: "Site", type: "S" },
|
|
241
|
+
{ name: "Status", type: "S" },
|
|
242
|
+
],
|
|
243
|
+
id: "Id",
|
|
244
|
+
indexes: [
|
|
245
|
+
{
|
|
246
|
+
name: "TicketsSiteStatusIndex",
|
|
247
|
+
keys: [
|
|
248
|
+
{ name: "Site", type: "HASH" },
|
|
249
|
+
{ name: "Status", type: "RANGE" },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
};
|
package/getData.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const config = require("./config.json");
|
|
2
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
3
|
+
const { log } = require("@plusscommunities/pluss-core-aws/helper");
|
|
4
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
5
|
+
const getAssignees = require("./requests/getAssignees");
|
|
6
|
+
const getRequests = require("./requests/getRequests");
|
|
7
|
+
const getRequest = require("./requests/getRequest");
|
|
8
|
+
|
|
9
|
+
module.exports.getData = async (event, context, callback) => {
|
|
10
|
+
init(config);
|
|
11
|
+
const action = event.pathParameters.action;
|
|
12
|
+
const logId = log(action, "Input", event.queryStringParameters);
|
|
13
|
+
|
|
14
|
+
let response;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
switch (action) {
|
|
18
|
+
case "requests":
|
|
19
|
+
response = await getRequests(event);
|
|
20
|
+
if (response.status === 200) {
|
|
21
|
+
log(action, "ResponseLength", response.data.Items.length, logId);
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case "request":
|
|
26
|
+
response = await getRequest(event);
|
|
27
|
+
if (response.status === 200) {
|
|
28
|
+
log(action, "ResponseLength", response.data, logId);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case "assignees":
|
|
32
|
+
response = await getAssignees(event);
|
|
33
|
+
if (response.status === 200) {
|
|
34
|
+
log(action, "ResponseLength", response.data.Users.length, logId);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
log(action, "InternalError", err.toString(), logId);
|
|
42
|
+
if (!response) {
|
|
43
|
+
response = { status: 500, data: { error: "Internal Error" } };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
log(action, "ResponseStatus", response.status, logId);
|
|
47
|
+
|
|
48
|
+
return callback(null, generateJsonResponse(response.status, response.data));
|
|
49
|
+
};
|
package/getJob.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const config = require("./config.json");
|
|
2
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
3
|
+
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
4
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
5
|
+
const getRequest = require("./requests/getRequest");
|
|
6
|
+
|
|
7
|
+
module.exports.getJob = async (event, context, callback) => {
|
|
8
|
+
init(config);
|
|
9
|
+
const data = getBody(event);
|
|
10
|
+
|
|
11
|
+
const result = await getRequest(event, data);
|
|
12
|
+
|
|
13
|
+
return callback(null, generateJsonResponse(result.status, result.data));
|
|
14
|
+
};
|
package/getJobType.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const config = require("./config.json");
|
|
2
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
3
|
+
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
4
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
5
|
+
const getRef = require("@plusscommunities/pluss-core-aws/db/common/getRef");
|
|
6
|
+
const validateSiteAccess = require("@plusscommunities/pluss-core-aws/helper/auth/validateSiteAccess");
|
|
7
|
+
const { values } = require("./values.config");
|
|
8
|
+
|
|
9
|
+
module.exports.getJobType = (event, context, callback) => {
|
|
10
|
+
init(config);
|
|
11
|
+
const data = getBody(event);
|
|
12
|
+
|
|
13
|
+
if (!data.site || !data.typeId) {
|
|
14
|
+
return callback(
|
|
15
|
+
null,
|
|
16
|
+
generateJsonResponse(422, {
|
|
17
|
+
error: { message: "User Types fetch -- no site or type id detected." },
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
validateSiteAccess(event, data.site)
|
|
23
|
+
.then((authorised) => {
|
|
24
|
+
if (!authorised) {
|
|
25
|
+
return callback(
|
|
26
|
+
null,
|
|
27
|
+
generateJsonResponse(422, { fail: true, error: "not authorised" })
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
getRef(values.tableNameJobTypes, "id", data.typeId)
|
|
31
|
+
.then((gweg) => {
|
|
32
|
+
return callback(null, generateJsonResponse(200, gweg));
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
return callback(
|
|
36
|
+
null,
|
|
37
|
+
generateJsonResponse(200, {
|
|
38
|
+
userFetchFail: true,
|
|
39
|
+
message: "Fail on user query. Please try again.",
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
.catch((error) => {
|
|
45
|
+
callback(null, generateJsonResponse(422, { fail: true, error }));
|
|
46
|
+
});
|
|
47
|
+
};
|
package/getJobTypes.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const config = require("./config.json");
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
const { init } = require("@plusscommunities/pluss-core-aws/config");
|
|
4
|
+
const { getBody } = require("@plusscommunities/pluss-core-aws/helper");
|
|
5
|
+
const generateJsonResponse = require("@plusscommunities/pluss-core-aws/helper/generateJsonResponse");
|
|
6
|
+
const indexQuery = require("@plusscommunities/pluss-core-aws/db/common/indexQuery");
|
|
7
|
+
const updateRef = require("@plusscommunities/pluss-core-aws/db/common/updateRef");
|
|
8
|
+
const validateSiteAccess = require("@plusscommunities/pluss-core-aws/helper/auth/validateSiteAccess");
|
|
9
|
+
const createGuid = require("@plusscommunities/pluss-core-aws/helper/createGuid");
|
|
10
|
+
const { values } = require("./values.config");
|
|
11
|
+
|
|
12
|
+
module.exports.getJobTypes = (event, context, callback) => {
|
|
13
|
+
init(config);
|
|
14
|
+
const data = getBody(event);
|
|
15
|
+
|
|
16
|
+
if (!data.site) {
|
|
17
|
+
return callback(
|
|
18
|
+
null,
|
|
19
|
+
generateJsonResponse(422, {
|
|
20
|
+
error: { message: "User Types fetch -- no site detected." },
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
validateSiteAccess(event, data.site)
|
|
25
|
+
.then((authorised) => {
|
|
26
|
+
if (!authorised) {
|
|
27
|
+
return callback(
|
|
28
|
+
null,
|
|
29
|
+
generateJsonResponse(422, { fail: true, error: "not authorised" })
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const query = {
|
|
34
|
+
IndexName: "JobTypeSiteIndex",
|
|
35
|
+
KeyConditionExpression: "site = :site",
|
|
36
|
+
ExpressionAttributeValues: {
|
|
37
|
+
":site": data.site,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
indexQuery(values.tableNameJobTypes, query)
|
|
42
|
+
.then((typeRes) => {
|
|
43
|
+
if (!_.isEmpty(typeRes.Items) || !values.allowGeneralType) {
|
|
44
|
+
return callback(null, generateJsonResponse(200, typeRes.Items));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const jobType = {
|
|
48
|
+
id: createGuid().substring(0, 8),
|
|
49
|
+
typeName: "General",
|
|
50
|
+
site: data.site,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
updateRef(values.tableNameJobTypes, jobType).then(() => {
|
|
54
|
+
return callback(null, generateJsonResponse(200, [jobType]));
|
|
55
|
+
});
|
|
56
|
+
})
|
|
57
|
+
.catch((error) => {
|
|
58
|
+
return callback(
|
|
59
|
+
null,
|
|
60
|
+
generateJsonResponse(200, {
|
|
61
|
+
userFetchFail: true,
|
|
62
|
+
message: "Fail on user query. Please try again.",
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
.catch((error) => {
|
|
68
|
+
callback(null, generateJsonResponse(422, { fail: true, error }));
|
|
69
|
+
});
|
|
70
|
+
};
|