aloux-iam 0.0.19 → 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,72 +1,72 @@
1
- const { S3Client, PutObjectCommand, DeleteObjectsCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3")
2
- const path = require('path')
3
- const utils = require('../config/utils')
4
- const self = module.exports
5
-
6
- /**
7
- * pathFile = folder/file_name-file_id
8
- * file = req.files.property
9
- */
10
- self.upload = async (pathFile, file) => {
11
- try {
12
-
13
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
14
- const extension = path.extname(file.name)
15
- const params = {
16
- Bucket: process.env.AWS_BUCKET,
17
- Key: pathFile + extension,
18
- ContentType: 'application/' + extension,
19
- Body: file.data,
20
- ACL: 'public-read'
21
- }
22
- const command = new PutObjectCommand(params)
23
- await s3Client.send(command)
24
- const evidence = 'https://' + process.env.AWS_BUCKET + '.s3.amazonaws.com/' + pathFile + extension
25
-
26
- return evidence
27
- } catch (error) {
28
- await utils.responseError(error)
29
- }
30
- }
31
-
32
- // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
33
- self.deleteMany = async (files) => {
34
- try {
35
- let evidence
36
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
37
- if (files.length > 0) {
38
- const params = {
39
- Bucket: process.env.AWS_BUCKET,
40
- Delete: {
41
- Objects: files,
42
- Quiet: true
43
- },
44
- }
45
- const command = new DeleteObjectsCommand(params)
46
- evidence = await s3Client.send(command)
47
- }
48
-
49
- return evidence
50
- } catch (error) {
51
- await utils.responseError(error)
52
- }
53
- }
54
-
55
- // file = folder/file_name
56
- self.delete = async (file) => {
57
- try {
58
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
59
-
60
- const params = {
61
- Bucket: process.env.AWS_BUCKET,
62
- Key: file,
63
- }
64
-
65
- const command = new DeleteObjectCommand(params)
66
- const evidence = await s3Client.send(command)
67
-
68
- return evidence
69
- } catch (error) {
70
- await utils.responseError(error)
71
- }
1
+ const { S3Client, PutObjectCommand, DeleteObjectsCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3")
2
+ const path = require('path')
3
+ const utils = require('../config/utils')
4
+ const self = module.exports
5
+
6
+ /**
7
+ * pathFile = folder/file_name-file_id
8
+ * file = req.files.property
9
+ */
10
+ self.upload = async (pathFile, file) => {
11
+ try {
12
+
13
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
14
+ const extension = path.extname(file.name)
15
+ const params = {
16
+ Bucket: process.env.AWS_BUCKET,
17
+ Key: pathFile + extension,
18
+ ContentType: 'application/' + extension,
19
+ Body: file.data,
20
+ ACL: 'public-read'
21
+ }
22
+ const command = new PutObjectCommand(params)
23
+ await s3Client.send(command)
24
+ const evidence = 'https://' + process.env.AWS_BUCKET + '.s3.amazonaws.com/' + pathFile + extension
25
+
26
+ return evidence
27
+ } catch (error) {
28
+ await utils.responseError(error)
29
+ }
30
+ }
31
+
32
+ // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
33
+ self.deleteMany = async (files) => {
34
+ try {
35
+ let evidence
36
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
37
+ if (files.length > 0) {
38
+ const params = {
39
+ Bucket: process.env.AWS_BUCKET,
40
+ Delete: {
41
+ Objects: files,
42
+ Quiet: true
43
+ },
44
+ }
45
+ const command = new DeleteObjectsCommand(params)
46
+ evidence = await s3Client.send(command)
47
+ }
48
+
49
+ return evidence
50
+ } catch (error) {
51
+ await utils.responseError(error)
52
+ }
53
+ }
54
+
55
+ // file = folder/file_name
56
+ self.delete = async (file) => {
57
+ try {
58
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
59
+
60
+ const params = {
61
+ Bucket: process.env.AWS_BUCKET,
62
+ Key: file,
63
+ }
64
+
65
+ const command = new DeleteObjectCommand(params)
66
+ const evidence = await s3Client.send(command)
67
+
68
+ return evidence
69
+ } catch (error) {
70
+ await utils.responseError(error)
71
+ }
72
72
  }
@@ -1,98 +1,98 @@
1
- const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses")
2
- const self = module.exports
3
-
4
- /**
5
- * email: Destination email
6
- * message: Link to login
7
- * subject: Mail subject
8
- */
9
- self.send = async (email, message, subject) => {
10
- try {
11
- const client = new SESClient({ region: process.env.AWS_REGION })
12
- const params = {
13
- Destination: {
14
- ToAddresses: [
15
- email
16
- ]
17
- },
18
- Message: {
19
- Body: {
20
- Html: {
21
- Charset: "UTF-8",
22
- Data: `<html>
23
- <body style="font-family: Verdana, Geneva, sans-serif;">
24
- <table align='center' width='100%' cellpadding='0' cellspacing='0'
25
- 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);'>
26
- <tbody>
27
- <tr>
28
- <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
29
- <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
30
- <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
31
- <a style="width: 100%!important; text-decoration:none;">
32
- <div
33
- style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
34
- <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
35
- href="`+ message + `">Acceder
36
- </a>
37
- </div>
38
- </a>
39
- </div>
40
- <hr style="width:100%; background:#000000; padding:4px 0;">
41
- </td>
42
- </tr>
43
- </tbody>
44
- </table>
45
- </body>
46
- </html>`
47
- }
48
- },
49
- Subject: {
50
- Charset: "UTF-8",
51
- Data: subject
52
- }
53
- },
54
- Source: process.env.AWS_EMAIL_SENDER//verified mail
55
- }
56
- const command = new SendEmailCommand(params)
57
- await client.send(command)
58
- return true
59
- } catch (error) {
60
- await utils.responseError(error)
61
- }
62
- }
63
-
64
- /**
65
- * email: Destination email
66
- * message: Mail body
67
- * subject: Mail subject
68
- */
69
- self.sendCustom = async (email, message, subject) => {
70
- try {
71
- const client = new SESClient({ region: process.env.AWS_REGION })
72
- const params = {
73
- Destination: {
74
- ToAddresses: [
75
- email
76
- ]
77
- },
78
- Message: {
79
- Body: {
80
- Html: {
81
- Charset: "UTF-8",
82
- Data: message
83
- }
84
- },
85
- Subject: {
86
- Charset: "UTF-8",
87
- Data: subject
88
- }
89
- },
90
- Source: process.env.AWS_EMAIL_SENDER//verified mail
91
- }
92
- const command = new SendEmailCommand(params)
93
- await client.send(command)
94
- return true
95
- } catch (error) {
96
- await utils.responseError(error)
97
- }
1
+ const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses")
2
+ const self = module.exports
3
+
4
+ /**
5
+ * email: Destination email
6
+ * message: Link to login
7
+ * subject: Mail subject
8
+ */
9
+ self.send = async (email, message, subject) => {
10
+ try {
11
+ const client = new SESClient({ region: process.env.AWS_REGION })
12
+ const params = {
13
+ Destination: {
14
+ ToAddresses: [
15
+ email
16
+ ]
17
+ },
18
+ Message: {
19
+ Body: {
20
+ Html: {
21
+ Charset: "UTF-8",
22
+ Data: `<html>
23
+ <body style="font-family: Verdana, Geneva, sans-serif;">
24
+ <table align='center' width='100%' cellpadding='0' cellspacing='0'
25
+ 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);'>
26
+ <tbody>
27
+ <tr>
28
+ <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
29
+ <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
30
+ <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
31
+ <a style="width: 100%!important; text-decoration:none;">
32
+ <div
33
+ style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
34
+ <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
35
+ href="`+ message + `">Acceder
36
+ </a>
37
+ </div>
38
+ </a>
39
+ </div>
40
+ <hr style="width:100%; background:#000000; padding:4px 0;">
41
+ </td>
42
+ </tr>
43
+ </tbody>
44
+ </table>
45
+ </body>
46
+ </html>`
47
+ }
48
+ },
49
+ Subject: {
50
+ Charset: "UTF-8",
51
+ Data: subject
52
+ }
53
+ },
54
+ Source: process.env.AWS_EMAIL_SENDER//verified mail
55
+ }
56
+ const command = new SendEmailCommand(params)
57
+ await client.send(command)
58
+ return true
59
+ } catch (error) {
60
+ await utils.responseError(error)
61
+ }
62
+ }
63
+
64
+ /**
65
+ * email: Destination email
66
+ * message: Mail body
67
+ * subject: Mail subject
68
+ */
69
+ self.sendCustom = async (email, message, subject) => {
70
+ try {
71
+ const client = new SESClient({ region: process.env.AWS_REGION })
72
+ const params = {
73
+ Destination: {
74
+ ToAddresses: [
75
+ email
76
+ ]
77
+ },
78
+ Message: {
79
+ Body: {
80
+ Html: {
81
+ Charset: "UTF-8",
82
+ Data: message
83
+ }
84
+ },
85
+ Subject: {
86
+ Charset: "UTF-8",
87
+ Data: subject
88
+ }
89
+ },
90
+ Source: process.env.AWS_EMAIL_SENDER//verified mail
91
+ }
92
+ const command = new SendEmailCommand(params)
93
+ await client.send(command)
94
+ return true
95
+ } catch (error) {
96
+ await utils.responseError(error)
97
+ }
98
98
  }
@@ -1,22 +1,22 @@
1
- const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns")
2
- const self = module.exports
3
-
4
- /**
5
- * phoneNumber: Destination email
6
- * message: Mail body
7
- */
8
- self.sendMessagePhone = async (phoneNumber, message) => {
9
- try {
10
- const client = new SNSClient({ region: process.env.AWS_REGION })
11
- const params = {
12
- PhoneNumber: phoneNumber,
13
- Message: message
14
- }
15
-
16
- const command = new PublishCommand(params)
17
- await client.send(command)
18
- return true
19
- } catch (error) {
20
- await utils.responseError(error)
21
- }
1
+ const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns")
2
+ const self = module.exports
3
+
4
+ /**
5
+ * phoneNumber: Destination email
6
+ * message: Mail body
7
+ */
8
+ self.sendMessagePhone = async (phoneNumber, message) => {
9
+ try {
10
+ const client = new SNSClient({ region: process.env.AWS_REGION })
11
+ const params = {
12
+ PhoneNumber: phoneNumber,
13
+ Message: message
14
+ }
15
+
16
+ const command = new PublishCommand(params)
17
+ await client.send(command)
18
+ return true
19
+ } catch (error) {
20
+ await utils.responseError(error)
21
+ }
22
22
  }
@@ -1,99 +1,99 @@
1
- const User = require('../models/User')
2
-
3
- const self = module.exports
4
-
5
- self.create = async (body) => {
6
- let user
7
- user = await User.findOne({email: body.email}).lean()
8
-
9
- if(user){
10
- throw {
11
- code: 404,
12
- title: 'Upss!',
13
- detail: '',
14
- suggestion: 'El correo ya se encuentra resgitrado',
15
- error: new Error()
16
- }
17
- }
18
-
19
- user = new User(body)
20
- user.createdAt = (new Date()).getTime()
21
- user.status = 'Activo'
22
-
23
- delete user.pwd
24
-
25
- await user.save()
26
-
27
- return user
28
- }
29
-
30
- self.update = async (USER_ID, body) => {
31
- const _id = USER_ID
32
- const user = await User.findOne({ _id }).countDocuments().lean()
33
-
34
- if (!user) {
35
- throw {
36
- code: 404,
37
- title: 'Upss!',
38
- detail: 'No se encontró el elemento',
39
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
40
- error: new Error()
41
- }
42
- }
43
-
44
- if (body.phone) {
45
- await User.updateOne({ _id }, { 'validateKey.validatePhone.validCodePhone': false })
46
- }
47
-
48
- body.lastUpdate = (new Date()).getTime()
49
- const result = await User.updateOne({ _id }, { $set: body })
50
-
51
- return result
52
- }
53
-
54
- self.status = async (USER_ID, body) => {
55
- const _id = USER_ID
56
- const user = await User.findOne({ _id })
57
-
58
- if (!user) {
59
- throw {
60
- code: 404,
61
- title: 'Upss!',
62
- detail: 'No se encontró el elemento',
63
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
64
- error: new Error()
65
- }
66
- }
67
-
68
- user.status = body.status
69
- user.lastUpdate = (new Date()).getTime()
70
-
71
- const result = await user.save()
72
-
73
- return result
74
- }
75
-
76
- self.updatepassword = async (body, USER_ID) => {
77
- let user
78
- user = User(body)
79
- const _id = USER_ID
80
-
81
- user = await User.findOne({ _id })
82
-
83
- if (!user) {
84
- throw {
85
- code: 404,
86
- title: 'Upss!',
87
- detail: 'No se encontró el elemento',
88
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
89
- error: new Error()
90
- }
91
- }
92
-
93
- user.pwd = body.pwd
94
- user.lastUpdate = (new Date()).getTime()
95
-
96
- const result = await user.save()
97
-
98
- return result
1
+ const User = require('../models/User')
2
+
3
+ const self = module.exports
4
+
5
+ self.create = async (body) => {
6
+ let user
7
+ user = await User.findOne({email: body.email}).lean()
8
+
9
+ if(user){
10
+ throw {
11
+ code: 404,
12
+ title: 'Upss!',
13
+ detail: '',
14
+ suggestion: 'El correo ya se encuentra resgitrado',
15
+ error: new Error()
16
+ }
17
+ }
18
+
19
+ user = new User(body)
20
+ user.createdAt = (new Date()).getTime()
21
+ user.status = 'Activo'
22
+
23
+ delete user.pwd
24
+
25
+ await user.save()
26
+
27
+ return user
28
+ }
29
+
30
+ self.update = async (USER_ID, body) => {
31
+ const _id = USER_ID
32
+ const user = await User.findOne({ _id }).countDocuments().lean()
33
+
34
+ if (!user) {
35
+ throw {
36
+ code: 404,
37
+ title: 'Upss!',
38
+ detail: 'No se encontró el elemento',
39
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
40
+ error: new Error()
41
+ }
42
+ }
43
+
44
+ if (body.phone) {
45
+ await User.updateOne({ _id }, { 'validateKey.validatePhone.validCodePhone': false })
46
+ }
47
+
48
+ body.lastUpdate = (new Date()).getTime()
49
+ const result = await User.updateOne({ _id }, { $set: body })
50
+
51
+ return result
52
+ }
53
+
54
+ self.status = async (USER_ID, body) => {
55
+ const _id = USER_ID
56
+ const user = await User.findOne({ _id })
57
+
58
+ if (!user) {
59
+ throw {
60
+ code: 404,
61
+ title: 'Upss!',
62
+ detail: 'No se encontró el elemento',
63
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
64
+ error: new Error()
65
+ }
66
+ }
67
+
68
+ user.status = body.status
69
+ user.lastUpdate = (new Date()).getTime()
70
+
71
+ const result = await user.save()
72
+
73
+ return result
74
+ }
75
+
76
+ self.updatepassword = async (body, USER_ID) => {
77
+ let user
78
+ user = User(body)
79
+ const _id = USER_ID
80
+
81
+ user = await User.findOne({ _id })
82
+
83
+ if (!user) {
84
+ throw {
85
+ code: 404,
86
+ title: 'Upss!',
87
+ detail: 'No se encontró el elemento',
88
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
89
+ error: new Error()
90
+ }
91
+ }
92
+
93
+ user.pwd = body.pwd
94
+ user.lastUpdate = (new Date()).getTime()
95
+
96
+ const result = await user.save()
97
+
98
+ return result
99
99
  }