aloux-iam 0.0.0 → 0.0.2

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.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const IAMrouter = require('./lib/router')
2
- const IAMauth = require('./lib/auth')
2
+ const IAMauth = require('./lib/middleware')
3
3
  const awsAloux = require('./lib/controllers/operationsAWS')
4
4
  const YAML = require('yamljs')
5
5
  const path = require('path')
@@ -136,4 +136,13 @@ self.validatePhone = async (req, res) => {
136
136
  } catch (error) {
137
137
  await utils.responseError(res,error)
138
138
  }
139
+ }
140
+
141
+ self.createCustomer = async (req, res) => {
142
+ try {
143
+ let token = await Auth.createCustomer(req, res)
144
+ res.status(201).send(token)
145
+ } catch (error) {
146
+ await utils.responseError(res,error)
147
+ }
139
148
  }
@@ -10,4 +10,5 @@ const functionsSchema = mongoose.Schema({
10
10
  lastUpdate: { type: Number }
11
11
  })
12
12
 
13
- module.exports = mongoose.model('Functions', functionsSchema)
13
+ const Functions = mongoose.model("Functions", functionsSchema)
14
+ module.exports = Functions
@@ -12,4 +12,5 @@ const menuSchema = mongoose.Schema({
12
12
  lastUpdate: { type: Number }
13
13
  })
14
14
 
15
- module.exports = mongoose.model('Menu', menuSchema)
15
+ const Menu = mongoose.model("Menu", menuSchema)
16
+ module.exports = Menu
package/lib/router.js CHANGED
@@ -16,6 +16,7 @@ router.post('/iam/auth/validate/code', auth.verifyCode)
16
16
  router.post('/iam/auth/verify/mail', auth.sendVerifyMailAccount)// sin documentar
17
17
  router.get('/iam/auth/verify/mail/token/:token', auth.verifyMailTokenAccount)
18
18
  router.post('/iam/auth/reset/password', auth.resetPassword)
19
+ router.post('/iam/auth/signup', auth.createCustomer)
19
20
 
20
21
  // User / user self
21
22
  router.get('/iam/auth/me', middleware, auth.me)
@@ -1,3 +1,4 @@
1
+ const Function = require('../models/Functions')
1
2
  const User = require('../models/User')
2
3
  const s3 = require('../services/s3')
3
4
  const ses = require('../services/ses')
@@ -426,4 +427,27 @@ self.validatePhone = async (req, res) => {
426
427
  }
427
428
 
428
429
  return "Teléfono Verificado"
430
+ }
431
+
432
+ self.createCustomer = async (req, res) => {
433
+ let user
434
+ user = await User.findOne({ email: req.body.email }).lean()
435
+ if (user) {
436
+ throw {
437
+ code: 404,
438
+ title: 'Upss!',
439
+ detail: '',
440
+ suggestion: 'El correo ya se encuentra resgitrado',
441
+ error: new Error()
442
+ }
443
+ }
444
+ user = new User(req.body)
445
+ user.createdAt = (new Date()).getTime()
446
+ user.status = 'Activo'
447
+ let fun = await Function.findOne({ name: 'Customer' })
448
+ user._functions.push(fun._id)
449
+ delete user.pwd
450
+ let newCustomer = await user.save()
451
+ const token = await newCustomer.generateAuthToken()
452
+ return token
429
453
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {