aloux-iam 0.0.28 → 0.0.30
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/lib/services/auth.js +19 -4
- package/lib/services/bigQuery.js +64 -0
- package/package.json +39 -37
package/lib/services/auth.js
CHANGED
|
@@ -3,6 +3,7 @@ const User = require('../models/User')
|
|
|
3
3
|
const s3 = require('../services/s3')
|
|
4
4
|
const ses = require('../services/ses')
|
|
5
5
|
const sns = require('../services/sns')
|
|
6
|
+
const bigQuery = require('../services/bigQuery')
|
|
6
7
|
const bcrypt = require('bcryptjs')
|
|
7
8
|
const dayjs = require("dayjs")
|
|
8
9
|
const fs = require("fs")
|
|
@@ -13,11 +14,11 @@ const self = module.exports
|
|
|
13
14
|
|
|
14
15
|
self.searchEmail = async (email) => {
|
|
15
16
|
const userLogin = await User.findOne({ email: email })
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
17
|
+
if (userLogin) {
|
|
18
|
+
return true
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
|
-
|
|
21
|
+
throw { code: 404, title: 'Correo no encontrado', detail: '', suggestion: 'Verifica que el correo sean correcto', error: new Error() }
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -53,7 +54,7 @@ self.login = async (body, res) => {
|
|
|
53
54
|
const isPasswordMatch = await bcrypt.compare(pwd, userLogin.pwd)
|
|
54
55
|
|
|
55
56
|
if (!isPasswordMatch) {
|
|
56
|
-
throw { code: 401, title: 'Credenciales incorrectas', detail: '
|
|
57
|
+
throw { code: 401, title: 'Credenciales incorrectas', detail: 'La contraseña es incorrecta', suggestion: 'Verifica que el usuario y contraseña sean correctas', error: new Error() }
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
else {
|
|
@@ -498,5 +499,19 @@ self.createCustomer = async (req, res) => {
|
|
|
498
499
|
delete user.pwd
|
|
499
500
|
let newCustomer = await user.save()
|
|
500
501
|
const token = await newCustomer.generateAuthToken()
|
|
502
|
+
if (process.env.UPLOAD_CUSTOMER === 'true') {
|
|
503
|
+
let row = {
|
|
504
|
+
id: newCustomer._id.toString() || 'NA',
|
|
505
|
+
name: newCustomer.name || 'NA',
|
|
506
|
+
lastName: newCustomer.lastName || 'NA',
|
|
507
|
+
email: newCustomer.email || 'NA',
|
|
508
|
+
age: newCustomer.data.age.toString() || 'NA',
|
|
509
|
+
gender: newCustomer.data.gender || 'NA',
|
|
510
|
+
scholarship: newCustomer.data.scholarship || 'NA',
|
|
511
|
+
entity: newCustomer.data.Entity || 'NA',
|
|
512
|
+
municipality: newCustomer.data.municipality || 'NA'
|
|
513
|
+
}
|
|
514
|
+
await bigQuery.callAppendRows([row], process.env.UPLOAD_CUSTOMER_TABLE)
|
|
515
|
+
}
|
|
501
516
|
return token
|
|
502
517
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { adapt, managedwriter } = require('@google-cloud/bigquery-storage')
|
|
2
|
+
const { WriterClient, JSONWriter } = managedwriter
|
|
3
|
+
const { BigQuery } = require('@google-cloud/bigquery')
|
|
4
|
+
const self = module.exports
|
|
5
|
+
|
|
6
|
+
self.callAppendRows = async (row, table) => {
|
|
7
|
+
const projectId = process.env.PROJECT_ID
|
|
8
|
+
const datasetId = process.env.DATASET_ID
|
|
9
|
+
const tableId = table
|
|
10
|
+
|
|
11
|
+
const destinationTable = `projects/${projectId}/datasets/${datasetId}/tables/${tableId}`
|
|
12
|
+
const writeClient = new WriterClient({ projectId })
|
|
13
|
+
const bigquery = new BigQuery({ projectId: projectId })
|
|
14
|
+
|
|
15
|
+
let results = {}
|
|
16
|
+
try {
|
|
17
|
+
const dataset = bigquery.dataset(datasetId)
|
|
18
|
+
const table = await dataset.table(tableId)
|
|
19
|
+
const [metadata] = await table.getMetadata()
|
|
20
|
+
const { schema } = metadata
|
|
21
|
+
const storageSchema =
|
|
22
|
+
adapt.convertBigQuerySchemaToStorageTableSchema(schema)
|
|
23
|
+
const protoDescriptor = adapt.convertStorageSchemaToProto2Descriptor(
|
|
24
|
+
storageSchema,
|
|
25
|
+
'root'
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const connection = await writeClient.createStreamConnection({
|
|
29
|
+
streamId: managedwriter.DefaultStream,
|
|
30
|
+
destinationTable,
|
|
31
|
+
})
|
|
32
|
+
const streamId = connection.getStreamId()
|
|
33
|
+
|
|
34
|
+
const writer = new JSONWriter({
|
|
35
|
+
streamId,
|
|
36
|
+
connection,
|
|
37
|
+
protoDescriptor,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
let rows = []
|
|
41
|
+
const pendingWrites = []
|
|
42
|
+
rows = row
|
|
43
|
+
|
|
44
|
+
// Send batch.
|
|
45
|
+
pw = writer.appendRows(rows)
|
|
46
|
+
pendingWrites.push(pw)
|
|
47
|
+
|
|
48
|
+
results = await Promise.all(
|
|
49
|
+
pendingWrites.map(pw => pw.getResult())
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw {
|
|
54
|
+
code: 400,
|
|
55
|
+
title: 'Ocurrio un error',
|
|
56
|
+
detail: err.toString(),
|
|
57
|
+
suggestion: 'Revisa callAppendRows()'
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
writeClient.close()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return results
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
}
|
|
2
|
+
"name": "aloux-iam",
|
|
3
|
+
"version": "0.0.30",
|
|
4
|
+
"description": "Aloux IAM for APIs ",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": ""
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/alouxDeveloper/aloux-sdk#readme"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"aloux",
|
|
15
|
+
"aloux-iam",
|
|
16
|
+
"IAM"
|
|
17
|
+
],
|
|
18
|
+
"author": "Aloux",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://github.com/alouxDeveloper/aloux-sdk#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"bcryptjs": "^2.4.3",
|
|
23
|
+
"body-parser": "~1.19.0",
|
|
24
|
+
"express": "~4.17.1",
|
|
25
|
+
"jsonwebtoken": "^9.0.0",
|
|
26
|
+
"method-override": "^3.0.0",
|
|
27
|
+
"mongodb": "^3.5.11",
|
|
28
|
+
"mongoose": "^5.13.3",
|
|
29
|
+
"@aws-sdk/client-s3": "^3.293.0",
|
|
30
|
+
"@aws-sdk/client-ses": "^3.293.0",
|
|
31
|
+
"@aws-sdk/client-sns": "^3.293.0",
|
|
32
|
+
"@google-cloud/bigquery": "^5.12.0",
|
|
33
|
+
"@google-cloud/bigquery-storage": "^4.2.1",
|
|
34
|
+
"@google-cloud/storage": "^5.7.0",
|
|
35
|
+
"yamljs": "^0.3.0",
|
|
36
|
+
"cookie-parser": "^1.4.6",
|
|
37
|
+
"dayjs": "^1.11.9"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {}
|
|
40
|
+
}
|