aloux-iam 0.0.20 → 0.0.21

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