aloux-iam 0.0.116 → 0.0.118

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.
@@ -1,228 +1,228 @@
1
- const {
2
- S3Client,
3
- PutObjectCommand,
4
- DeleteObjectsCommand,
5
- DeleteObjectCommand,
6
- } = require("@aws-sdk/client-s3");
7
- const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
8
- const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");
9
- const path = require("path");
10
- const self = module.exports;
11
-
12
- /**
13
- * pathFile = folder/file_name-file_id
14
- * file = req.files.property
15
- */
16
- self.upload = async (pathFile, file) => {
17
- try {
18
- const s3Client = new S3Client({ region: process.env.AWS_REGION });
19
- const extension = path.extname(file.name);
20
- const params = {
21
- Bucket: process.env.AWS_BUCKET,
22
- Key: pathFile + extension,
23
- ContentType: "application/" + path.extname(file.name).replace(".", ""),
24
- ContentDisposition: "inline",
25
- Body: file.data,
26
- ACL: "public-read",
27
- };
28
- const command = new PutObjectCommand(params);
29
- await s3Client.send(command);
30
- const evidence =
31
- "https://" +
32
- process.env.AWS_BUCKET +
33
- ".s3.amazonaws.com/" +
34
- pathFile +
35
- extension;
36
-
37
- return evidence;
38
- } catch (error) {
39
- throw {
40
- code: 400,
41
- title: "Error en los parametros",
42
- detail: new Error(error),
43
- suggestion: "Contacta con el administrador",
44
- };
45
- }
46
- };
47
-
48
- // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
49
- self.deleteMany = async (files) => {
50
- try {
51
- let evidence;
52
- const s3Client = new S3Client({ region: process.env.AWS_REGION });
53
- if (files.length > 0) {
54
- const params = {
55
- Bucket: process.env.AWS_BUCKET,
56
- Delete: {
57
- Objects: files,
58
- Quiet: true,
59
- },
60
- };
61
- const command = new DeleteObjectsCommand(params);
62
- evidence = await s3Client.send(command);
63
- }
64
-
65
- return evidence;
66
- } catch (error) {
67
- throw {
68
- code: 400,
69
- title: "Error en los parametros",
70
- detail: new Error(error),
71
- suggestion: "Contacta con el administrador",
72
- };
73
- }
74
- };
75
-
76
- // file = folder/file_name
77
- self.delete = async (file) => {
78
- try {
79
- const s3Client = new S3Client({ region: process.env.AWS_REGION });
80
-
81
- const params = {
82
- Bucket: process.env.AWS_BUCKET,
83
- Key: file,
84
- };
85
-
86
- const command = new DeleteObjectCommand(params);
87
- const evidence = await s3Client.send(command);
88
-
89
- return evidence;
90
- } catch (error) {
91
- throw {
92
- code: 400,
93
- title: "Error en los parametros",
94
- detail: new Error(error),
95
- suggestion: "Contacta con el administrador",
96
- };
97
- }
98
- };
99
-
100
- /**
101
- * email: Destination email
102
- * message: Link to login
103
- * subject: Mail subject
104
- */
105
- self.send = async (email, message, subject) => {
106
- try {
107
- const client = new SESClient({ region: process.env.AWS_REGION });
108
- const params = {
109
- Destination: {
110
- ToAddresses: [email],
111
- },
112
- Message: {
113
- Body: {
114
- Html: {
115
- Charset: "UTF-8",
116
- Data:
117
- `<html>
118
- <body style="font-family: Verdana, Geneva, sans-serif;">
119
- <table align='center' width='100%' cellpadding='0' cellspacing='0'
120
- style='max-width: 640px; padding: 20px 40px; background-color: #fff; box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.1), 0 15px 35px 0 rgba(0, 0, 0, 0.05);'>
121
- <tbody>
122
- <tr>
123
- <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
124
- <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
125
- <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
126
- <a style="width: 100%!important; text-decoration:none;">
127
- <div
128
- style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
129
- <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
130
- href="` +
131
- message +
132
- `">Acceder
133
- </a>
134
- </div>
135
- </a>
136
- </div>
137
- <hr style="width:100%; background:#000000; padding:4px 0;">
138
- </td>
139
- </tr>
140
- </tbody>
141
- </table>
142
- </body>
143
- </html>`,
144
- },
145
- },
146
- Subject: {
147
- Charset: "UTF-8",
148
- Data: subject,
149
- },
150
- },
151
- Source: process.env.AWS_EMAIL_SENDER, //verified mail
152
- };
153
- const command = new SendEmailCommand(params);
154
- await client.send(command);
155
- return true;
156
- } catch (error) {
157
- throw {
158
- code: 400,
159
- title: "Error en los parametros",
160
- detail: new Error(error),
161
- suggestion: "Contacta con el administrador",
162
- };
163
- }
164
- };
165
-
166
- /**
167
- * email: Destination email
168
- * message: Mail body
169
- * subject: Mail subject
170
- */
171
- self.sendCustom = async (email, message, subject) => {
172
- try {
173
- const client = new SESClient({ region: process.env.AWS_REGION });
174
- const params = {
175
- Destination: {
176
- ToAddresses: [email],
177
- },
178
- Message: {
179
- Body: {
180
- Html: {
181
- Charset: "UTF-8",
182
- Data: message,
183
- },
184
- },
185
- Subject: {
186
- Charset: "UTF-8",
187
- Data: subject,
188
- },
189
- },
190
- Source: process.env.AWS_EMAIL_SENDER, //verified mail
191
- };
192
- const command = new SendEmailCommand(params);
193
- await client.send(command);
194
- return true;
195
- } catch (error) {
196
- throw {
197
- code: 400,
198
- title: "Error en los parametros",
199
- detail: new Error(error),
200
- suggestion: "Contacta con el administrador",
201
- };
202
- }
203
- };
204
-
205
- /**
206
- * phoneNumber: Destination email
207
- * message: Mail body
208
- */
209
- self.sendMessagePhone = async (phoneNumber, message) => {
210
- try {
211
- const client = new SNSClient({ region: process.env.AWS_REGION });
212
- const params = {
213
- PhoneNumber: phoneNumber,
214
- Message: message,
215
- };
216
-
217
- const command = new PublishCommand(params);
218
- await client.send(command);
219
- return true;
220
- } catch (error) {
221
- throw {
222
- code: 400,
223
- title: "Error en los parametros",
224
- detail: new Error(error),
225
- suggestion: "Contacta con el administrador",
226
- };
227
- }
228
- };
1
+ const {
2
+ S3Client,
3
+ PutObjectCommand,
4
+ DeleteObjectsCommand,
5
+ DeleteObjectCommand,
6
+ } = require("@aws-sdk/client-s3");
7
+ const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
8
+ const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");
9
+ const path = require("path");
10
+ const self = module.exports;
11
+
12
+ /**
13
+ * pathFile = folder/file_name-file_id
14
+ * file = req.files.property
15
+ */
16
+ self.upload = async (pathFile, file) => {
17
+ try {
18
+ const s3Client = new S3Client({ region: process.env.AWS_REGION });
19
+ const extension = path.extname(file.name);
20
+ const params = {
21
+ Bucket: process.env.AWS_BUCKET,
22
+ Key: pathFile + extension,
23
+ ContentType: "application/" + path.extname(file.name).replace(".", ""),
24
+ ContentDisposition: "inline",
25
+ Body: file.data,
26
+ ACL: "public-read",
27
+ };
28
+ const command = new PutObjectCommand(params);
29
+ await s3Client.send(command);
30
+ const evidence =
31
+ "https://" +
32
+ process.env.AWS_BUCKET +
33
+ ".s3.amazonaws.com/" +
34
+ pathFile +
35
+ extension;
36
+
37
+ return evidence;
38
+ } catch (error) {
39
+ throw {
40
+ code: 400,
41
+ title: "Error en los parametros",
42
+ detail: new Error(error),
43
+ suggestion: "Contacta con el administrador",
44
+ };
45
+ }
46
+ };
47
+
48
+ // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
49
+ self.deleteMany = async (files) => {
50
+ try {
51
+ let evidence;
52
+ const s3Client = new S3Client({ region: process.env.AWS_REGION });
53
+ if (files.length > 0) {
54
+ const params = {
55
+ Bucket: process.env.AWS_BUCKET,
56
+ Delete: {
57
+ Objects: files,
58
+ Quiet: true,
59
+ },
60
+ };
61
+ const command = new DeleteObjectsCommand(params);
62
+ evidence = await s3Client.send(command);
63
+ }
64
+
65
+ return evidence;
66
+ } catch (error) {
67
+ throw {
68
+ code: 400,
69
+ title: "Error en los parametros",
70
+ detail: new Error(error),
71
+ suggestion: "Contacta con el administrador",
72
+ };
73
+ }
74
+ };
75
+
76
+ // file = folder/file_name
77
+ self.delete = async (file) => {
78
+ try {
79
+ const s3Client = new S3Client({ region: process.env.AWS_REGION });
80
+
81
+ const params = {
82
+ Bucket: process.env.AWS_BUCKET,
83
+ Key: file,
84
+ };
85
+
86
+ const command = new DeleteObjectCommand(params);
87
+ const evidence = await s3Client.send(command);
88
+
89
+ return evidence;
90
+ } catch (error) {
91
+ throw {
92
+ code: 400,
93
+ title: "Error en los parametros",
94
+ detail: new Error(error),
95
+ suggestion: "Contacta con el administrador",
96
+ };
97
+ }
98
+ };
99
+
100
+ /**
101
+ * email: Destination email
102
+ * message: Link to login
103
+ * subject: Mail subject
104
+ */
105
+ self.send = async (email, message, subject) => {
106
+ try {
107
+ const client = new SESClient({ region: process.env.AWS_REGION });
108
+ const params = {
109
+ Destination: {
110
+ ToAddresses: [email],
111
+ },
112
+ Message: {
113
+ Body: {
114
+ Html: {
115
+ Charset: "UTF-8",
116
+ Data:
117
+ `<html>
118
+ <body style="font-family: Verdana, Geneva, sans-serif;">
119
+ <table align='center' width='100%' cellpadding='0' cellspacing='0'
120
+ style='max-width: 640px; padding: 20px 40px; background-color: #fff; box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.1), 0 15px 35px 0 rgba(0, 0, 0, 0.05);'>
121
+ <tbody>
122
+ <tr>
123
+ <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
124
+ <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
125
+ <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
126
+ <a style="width: 100%!important; text-decoration:none;">
127
+ <div
128
+ style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
129
+ <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
130
+ href="` +
131
+ message +
132
+ `">Acceder
133
+ </a>
134
+ </div>
135
+ </a>
136
+ </div>
137
+ <hr style="width:100%; background:#000000; padding:4px 0;">
138
+ </td>
139
+ </tr>
140
+ </tbody>
141
+ </table>
142
+ </body>
143
+ </html>`,
144
+ },
145
+ },
146
+ Subject: {
147
+ Charset: "UTF-8",
148
+ Data: subject,
149
+ },
150
+ },
151
+ Source: process.env.AWS_EMAIL_SENDER, //verified mail
152
+ };
153
+ const command = new SendEmailCommand(params);
154
+ await client.send(command);
155
+ return true;
156
+ } catch (error) {
157
+ throw {
158
+ code: 400,
159
+ title: "Error en los parametros",
160
+ detail: new Error(error),
161
+ suggestion: "Contacta con el administrador",
162
+ };
163
+ }
164
+ };
165
+
166
+ /**
167
+ * email: Destination email
168
+ * message: Mail body
169
+ * subject: Mail subject
170
+ */
171
+ self.sendCustom = async (email, message, subject) => {
172
+ try {
173
+ const client = new SESClient({ region: process.env.AWS_REGION });
174
+ const params = {
175
+ Destination: {
176
+ ToAddresses: [email],
177
+ },
178
+ Message: {
179
+ Body: {
180
+ Html: {
181
+ Charset: "UTF-8",
182
+ Data: message,
183
+ },
184
+ },
185
+ Subject: {
186
+ Charset: "UTF-8",
187
+ Data: subject,
188
+ },
189
+ },
190
+ Source: process.env.AWS_EMAIL_SENDER, //verified mail
191
+ };
192
+ const command = new SendEmailCommand(params);
193
+ await client.send(command);
194
+ return true;
195
+ } catch (error) {
196
+ throw {
197
+ code: 400,
198
+ title: "Error en los parametros",
199
+ detail: new Error(error),
200
+ suggestion: "Contacta con el administrador",
201
+ };
202
+ }
203
+ };
204
+
205
+ /**
206
+ * phoneNumber: Destination email
207
+ * message: Mail body
208
+ */
209
+ self.sendMessagePhone = async (phoneNumber, message) => {
210
+ try {
211
+ const client = new SNSClient({ region: process.env.AWS_REGION });
212
+ const params = {
213
+ PhoneNumber: phoneNumber,
214
+ Message: message,
215
+ };
216
+
217
+ const command = new PublishCommand(params);
218
+ await client.send(command);
219
+ return true;
220
+ } catch (error) {
221
+ throw {
222
+ code: 400,
223
+ title: "Error en los parametros",
224
+ detail: new Error(error),
225
+ suggestion: "Contacta con el administrador",
226
+ };
227
+ }
228
+ };
@@ -1,91 +1,91 @@
1
- const Permission = require('../models/Permission')
2
- const self = module.exports
3
-
4
- self.create = async (req, res) => {
5
- try {
6
- const permission = new Permission(req.body)
7
- permission.createdAt = (new Date()).getTime()
8
- permission.status = 'Activo'
9
- await permission.save()
10
- res.status(201).send(permission)
11
- } catch (error) {
12
- switch(error.code){
13
- case 11000: obj = { error: 'El campo ' + JSON.stringify(error.keyValue) + ' ya se encuentra dado de alta', suggestion: 'Revisa la información e intenta nuevamente.' }; break
14
- default: obj = error
15
- }
16
- res.status(400).send(obj)
17
- }
18
- }
19
-
20
- self.update = async (req, resp) => {
21
- try {
22
- await (new Permission(req.body)).validate()
23
- const _id = req.params.PERMISSION_ID
24
- const count = await Permission.findOne({ _id }).countDocuments()
25
- if(!count)
26
- throw new Error('Upss! No se encontró el registro')
27
- req.body.lastUpdate = (new Date()).getTime()
28
- const result = await Permission.updateOne({ _id }, req.body)
29
- resp.status(200).send(req.body)
30
- } catch (error) {
31
- resp.status(400).send({error:error.message})
32
- }
33
- }
34
- self.status = async (req, resp) => {
35
- try {
36
- const _id = req.params.PERMISSION_ID
37
- const user = await Permission.findOne({ _id })
38
- if(!user)
39
- throw new Error('Upss! No se encontró el Elemento')
40
- user.status = req.body.status
41
- user.lastUpdate = (new Date()).getTime()
42
- const result = await user.save()
43
-
44
- resp.status(200).send(result)
45
- } catch (error) {
46
- resp.status(400).send({error:error.message})
47
- }
48
- }
49
- self.retrieve = async(req, res) => {
50
- try {
51
- const consulta = await Permission.find({}).sort({createdAt:-1}).populate('_menu')
52
- res.status(200).send(consulta)
53
- } catch (error) {
54
- res.status(400).send(error)
55
- }
56
- }
57
-
58
- self.get = async(req, res) => {
59
- try {
60
- const _id = req.params.PERMISSION_ID
61
- const permission = await Permission.findOne({_id}).populate({ path: "_menu" })
62
- if(!permission)
63
- res.status(404).send()
64
- res.status(200).send(permission)
65
- } catch (error) {
66
- console.log(error)
67
- res.status(400).send(error)
68
- }
69
- }
70
-
71
- self.delete = async(req, res) => {
72
- try {
73
- const _id = req.params.PERMISSION_ID
74
- const response = await Permission.deleteOne({ _id })
75
- if(!response.deletedCount)
76
- res.status(404).send({ error : "El registro no existe"})
77
- else
78
- res.status(200).send({})
79
- } catch (error) {
80
- res.status(400).send({error:error.message})
81
- }
82
- }
83
-
84
- self.count = async(req, res) => {
85
- try {
86
- let result = await Permission.find({}).countDocuments()
87
- res.status(200).send({ count: result })
88
- } catch (error) {
89
- res.status(400).send({error:error.message})
90
- }
1
+ const Permission = require('../models/Permission')
2
+ const self = module.exports
3
+
4
+ self.create = async (req, res) => {
5
+ try {
6
+ const permission = new Permission(req.body)
7
+ permission.createdAt = (new Date()).getTime()
8
+ permission.status = 'Activo'
9
+ await permission.save()
10
+ res.status(201).send(permission)
11
+ } catch (error) {
12
+ switch(error.code){
13
+ case 11000: obj = { error: 'El campo ' + JSON.stringify(error.keyValue) + ' ya se encuentra dado de alta', suggestion: 'Revisa la información e intenta nuevamente.' }; break
14
+ default: obj = error
15
+ }
16
+ res.status(400).send(obj)
17
+ }
18
+ }
19
+
20
+ self.update = async (req, resp) => {
21
+ try {
22
+ await (new Permission(req.body)).validate()
23
+ const _id = req.params.PERMISSION_ID
24
+ const count = await Permission.findOne({ _id }).countDocuments()
25
+ if(!count)
26
+ throw new Error('Upss! No se encontró el registro')
27
+ req.body.lastUpdate = (new Date()).getTime()
28
+ const result = await Permission.updateOne({ _id }, req.body)
29
+ resp.status(200).send(req.body)
30
+ } catch (error) {
31
+ resp.status(400).send({error:error.message})
32
+ }
33
+ }
34
+ self.status = async (req, resp) => {
35
+ try {
36
+ const _id = req.params.PERMISSION_ID
37
+ const user = await Permission.findOne({ _id })
38
+ if(!user)
39
+ throw new Error('Upss! No se encontró el Elemento')
40
+ user.status = req.body.status
41
+ user.lastUpdate = (new Date()).getTime()
42
+ const result = await user.save()
43
+
44
+ resp.status(200).send(result)
45
+ } catch (error) {
46
+ resp.status(400).send({error:error.message})
47
+ }
48
+ }
49
+ self.retrieve = async(req, res) => {
50
+ try {
51
+ const consulta = await Permission.find({}).sort({createdAt:-1}).populate('_menu')
52
+ res.status(200).send(consulta)
53
+ } catch (error) {
54
+ res.status(400).send(error)
55
+ }
56
+ }
57
+
58
+ self.get = async(req, res) => {
59
+ try {
60
+ const _id = req.params.PERMISSION_ID
61
+ const permission = await Permission.findOne({_id}).populate({ path: "_menu" })
62
+ if(!permission)
63
+ res.status(404).send()
64
+ res.status(200).send(permission)
65
+ } catch (error) {
66
+ console.log(error)
67
+ res.status(400).send(error)
68
+ }
69
+ }
70
+
71
+ self.delete = async(req, res) => {
72
+ try {
73
+ const _id = req.params.PERMISSION_ID
74
+ const response = await Permission.deleteOne({ _id })
75
+ if(!response.deletedCount)
76
+ res.status(404).send({ error : "El registro no existe"})
77
+ else
78
+ res.status(200).send({})
79
+ } catch (error) {
80
+ res.status(400).send({error:error.message})
81
+ }
82
+ }
83
+
84
+ self.count = async(req, res) => {
85
+ try {
86
+ let result = await Permission.find({}).countDocuments()
87
+ res.status(200).send({ count: result })
88
+ } catch (error) {
89
+ res.status(400).send({error:error.message})
90
+ }
91
91
  }