aloux-iam 0.0.115 → 0.0.117

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,99 +1,99 @@
1
- const User = require('../models/User')
2
- const self = module.exports
3
-
4
- self.create = async (body) => {
5
- let user
6
- user = await User.findOne({email: body.email}).lean()
7
-
8
- if(user){
9
- throw {
10
- code: 404,
11
- title: 'Upss!',
12
- detail: '',
13
- suggestion: 'El correo ya se encuentra resgitrado',
14
- error: new Error()
15
- }
16
- }
17
-
18
- user = new User(body)
19
- user.createdAt = (new Date()).getTime()
20
- user.status = body?.status ? body?.status : 'Activo'
21
-
22
- delete user.pwd
23
- user.data.changePwd = false
24
- await user.save()
25
-
26
- return user
27
- }
28
-
29
- self.update = async (USER_ID, body) => {
30
- const _id = USER_ID
31
- const user = await User.findOne({ _id }).countDocuments().lean()
32
-
33
- if (!user) {
34
- throw {
35
- code: 404,
36
- title: 'Upss!',
37
- detail: 'No se encontró el elemento',
38
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
39
- error: new Error()
40
- }
41
- }
42
-
43
- if (body.phone) {
44
- await User.updateOne({ _id }, { 'validateKey.validatePhone.validCodePhone': false })
45
- }
46
-
47
- body.lastUpdate = (new Date()).getTime()
48
- const result = await User.updateOne({ _id }, { $set: body })
49
-
50
- return result
51
- }
52
-
53
- self.status = async (USER_ID, body) => {
54
- const _id = USER_ID
55
- const user = await User.findOne({ _id })
56
-
57
- if (!user) {
58
- throw {
59
- code: 404,
60
- title: 'Upss!',
61
- detail: 'No se encontró el elemento',
62
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
63
- error: new Error()
64
- }
65
- }
66
-
67
- user.status = body.status
68
- user.lastUpdate = (new Date()).getTime()
69
-
70
- const result = await user.save()
71
-
72
- return result
73
- }
74
-
75
- self.updatepassword = async (body, USER_ID) => {
76
- let user
77
- user = User(body)
78
- const _id = USER_ID
79
-
80
- user = await User.findOne({ _id })
81
-
82
- if (!user) {
83
- throw {
84
- code: 404,
85
- title: 'Upss!',
86
- detail: 'No se encontró el elemento',
87
- suggestion: 'Verifica que el usuario aun este activo en la plataforma',
88
- error: new Error()
89
- }
90
- }
91
-
92
- user.pwd = body.pwd
93
- user.lastUpdate = (new Date()).getTime()
94
-
95
- const result = await user.save()
96
-
97
- return result
98
- }
99
-
1
+ const User = require('../models/User')
2
+ const self = module.exports
3
+
4
+ self.create = async (body) => {
5
+ let user
6
+ user = await User.findOne({email: body.email}).lean()
7
+
8
+ if(user){
9
+ throw {
10
+ code: 404,
11
+ title: 'Upss!',
12
+ detail: '',
13
+ suggestion: 'El correo ya se encuentra resgitrado',
14
+ error: new Error()
15
+ }
16
+ }
17
+
18
+ user = new User(body)
19
+ user.createdAt = (new Date()).getTime()
20
+ user.status = body?.status ? body?.status : 'Activo'
21
+
22
+ delete user.pwd
23
+ user.data.changePwd = false
24
+ await user.save()
25
+
26
+ return user
27
+ }
28
+
29
+ self.update = async (USER_ID, body) => {
30
+ const _id = USER_ID
31
+ const user = await User.findOne({ _id }).countDocuments().lean()
32
+
33
+ if (!user) {
34
+ throw {
35
+ code: 404,
36
+ title: 'Upss!',
37
+ detail: 'No se encontró el elemento',
38
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
39
+ error: new Error()
40
+ }
41
+ }
42
+
43
+ if (body.phone) {
44
+ await User.updateOne({ _id }, { 'validateKey.validatePhone.validCodePhone': false })
45
+ }
46
+
47
+ body.lastUpdate = (new Date()).getTime()
48
+ const result = await User.updateOne({ _id }, { $set: body })
49
+
50
+ return result
51
+ }
52
+
53
+ self.status = async (USER_ID, body) => {
54
+ const _id = USER_ID
55
+ const user = await User.findOne({ _id })
56
+
57
+ if (!user) {
58
+ throw {
59
+ code: 404,
60
+ title: 'Upss!',
61
+ detail: 'No se encontró el elemento',
62
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
63
+ error: new Error()
64
+ }
65
+ }
66
+
67
+ user.status = body.status
68
+ user.lastUpdate = (new Date()).getTime()
69
+
70
+ const result = await user.save()
71
+
72
+ return result
73
+ }
74
+
75
+ self.updatepassword = async (body, USER_ID) => {
76
+ let user
77
+ user = User(body)
78
+ const _id = USER_ID
79
+
80
+ user = await User.findOne({ _id })
81
+
82
+ if (!user) {
83
+ throw {
84
+ code: 404,
85
+ title: 'Upss!',
86
+ detail: 'No se encontró el elemento',
87
+ suggestion: 'Verifica que el usuario aun este activo en la plataforma',
88
+ error: new Error()
89
+ }
90
+ }
91
+
92
+ user.pwd = body.pwd
93
+ user.lastUpdate = (new Date()).getTime()
94
+
95
+ const result = await user.save()
96
+
97
+ return result
98
+ }
99
+