aloux-iam 0.0.0

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.
@@ -0,0 +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
99
+ }