aloux-iam 0.0.114 → 0.0.115

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,102 +1,102 @@
1
- const Menu = require('../models/Menu')
2
- const self = module.exports
3
-
4
- self.create = async (req, res) => {
5
- try {
6
- const menu = new Menu(req.body)
7
- menu.createdAt = (new Date()).getTime()
8
- menu.status = 'Activo'
9
- await menu.save()
10
- res.status(201).send(menu)
11
- } catch (error) {
12
- res.status(400).send({error:error.message})
13
- }
14
- }
15
-
16
- self.update = async (req, resp) => {
17
- try {
18
- await (new Menu(req.body)).validate()
19
- const _id = req.params.MENU_ID
20
- const count = await Menu.findOne({_id}).countDocuments()
21
- if(!count)
22
- throw new Error('Upss! No se encontró el registro')
23
- req.body.lastUpdate = (new Date()).getTime()
24
- const result = await Menu.updateOne({_id}, req.body)
25
- resp.status(200).send(req.body)
26
- } catch (error) {
27
- resp.status(400).send({error:error.message})
28
- }
29
- }
30
- self.status = async (req, resp) => {
31
- try {
32
- const _id = req.params.MENU_ID
33
- const user = await Menu.findOne({ _id })
34
- if(!user)
35
- throw new Error('Upss! No se encontró el Elemento')
36
- user.status = req.body.status
37
- user.lastUpdate = (new Date()).getTime()
38
- const result = await user.save()
39
- resp.status(200).send(result)
40
- } catch (error) {
41
- resp.status(400).send({error:error.message})
42
- }
43
- }
44
- self.retrieve = async(req, res) => {
45
- try {
46
- const consulta = await Menu.find({}).sort({index:1})
47
- if(!consulta)
48
- res.status(404).send()
49
- res.status(200).send(consulta)
50
- } catch (error) {
51
- res.status(400).send(error)
52
- }
53
- }
54
-
55
- self.get = async(req, res) => {
56
- try {
57
- const _id = req.params.MENU_ID
58
- const menu = await Menu.findOne({_id})
59
- if(!menu)
60
- res.status(404).send()
61
- res.status(200).send(menu)
62
- } catch (error) {
63
- res.status(400).send(error)
64
- }
65
- }
66
-
67
- self.delete = async(req, res) => {
68
- try {
69
- const _id = req.params.MENU_ID
70
- const response = await Menu.deleteOne({ _id })
71
- if(!response.deletedCount)
72
- res.status(404).send({ error : "El registro no existe"})
73
- else
74
- res.status(200).send({})
75
- } catch (error) {
76
- res.status(400).send({error:error.message})
77
- }
78
- }
79
-
80
- self.order = async (req, resp) => {
81
- try {
82
- if(!req.body.length)
83
- throw new Error('Upss! No se encontró el registro')
84
-
85
- for(let i in req.body){
86
- const item = req.body[i]
87
- await Menu.updateOne({ _id:item._id }, { $set: { index: item.index } })
88
- }
89
- resp.status(200).send({})
90
- } catch (error) {
91
- resp.status(400).send({error:error.message})
92
- }
93
- }
94
-
95
- self.count = async(req, res) => {
96
- try {
97
- let result = await Menu.find({}).countDocuments()
98
- res.status(200).send({ count: result })
99
- } catch (error) {
100
- res.status(400).send({error:error.message})
101
- }
1
+ const Menu = require('../models/Menu')
2
+ const self = module.exports
3
+
4
+ self.create = async (req, res) => {
5
+ try {
6
+ const menu = new Menu(req.body)
7
+ menu.createdAt = (new Date()).getTime()
8
+ menu.status = 'Activo'
9
+ await menu.save()
10
+ res.status(201).send(menu)
11
+ } catch (error) {
12
+ res.status(400).send({error:error.message})
13
+ }
14
+ }
15
+
16
+ self.update = async (req, resp) => {
17
+ try {
18
+ await (new Menu(req.body)).validate()
19
+ const _id = req.params.MENU_ID
20
+ const count = await Menu.findOne({_id}).countDocuments()
21
+ if(!count)
22
+ throw new Error('Upss! No se encontró el registro')
23
+ req.body.lastUpdate = (new Date()).getTime()
24
+ const result = await Menu.updateOne({_id}, req.body)
25
+ resp.status(200).send(req.body)
26
+ } catch (error) {
27
+ resp.status(400).send({error:error.message})
28
+ }
29
+ }
30
+ self.status = async (req, resp) => {
31
+ try {
32
+ const _id = req.params.MENU_ID
33
+ const user = await Menu.findOne({ _id })
34
+ if(!user)
35
+ throw new Error('Upss! No se encontró el Elemento')
36
+ user.status = req.body.status
37
+ user.lastUpdate = (new Date()).getTime()
38
+ const result = await user.save()
39
+ resp.status(200).send(result)
40
+ } catch (error) {
41
+ resp.status(400).send({error:error.message})
42
+ }
43
+ }
44
+ self.retrieve = async(req, res) => {
45
+ try {
46
+ const consulta = await Menu.find({}).sort({index:1})
47
+ if(!consulta)
48
+ res.status(404).send()
49
+ res.status(200).send(consulta)
50
+ } catch (error) {
51
+ res.status(400).send(error)
52
+ }
53
+ }
54
+
55
+ self.get = async(req, res) => {
56
+ try {
57
+ const _id = req.params.MENU_ID
58
+ const menu = await Menu.findOne({_id})
59
+ if(!menu)
60
+ res.status(404).send()
61
+ res.status(200).send(menu)
62
+ } catch (error) {
63
+ res.status(400).send(error)
64
+ }
65
+ }
66
+
67
+ self.delete = async(req, res) => {
68
+ try {
69
+ const _id = req.params.MENU_ID
70
+ const response = await Menu.deleteOne({ _id })
71
+ if(!response.deletedCount)
72
+ res.status(404).send({ error : "El registro no existe"})
73
+ else
74
+ res.status(200).send({})
75
+ } catch (error) {
76
+ res.status(400).send({error:error.message})
77
+ }
78
+ }
79
+
80
+ self.order = async (req, resp) => {
81
+ try {
82
+ if(!req.body.length)
83
+ throw new Error('Upss! No se encontró el registro')
84
+
85
+ for(let i in req.body){
86
+ const item = req.body[i]
87
+ await Menu.updateOne({ _id:item._id }, { $set: { index: item.index } })
88
+ }
89
+ resp.status(200).send({})
90
+ } catch (error) {
91
+ resp.status(400).send({error:error.message})
92
+ }
93
+ }
94
+
95
+ self.count = async(req, res) => {
96
+ try {
97
+ let result = await Menu.find({}).countDocuments()
98
+ res.status(200).send({ count: result })
99
+ } catch (error) {
100
+ res.status(400).send({error:error.message})
101
+ }
102
102
  }
@@ -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
+ };