Merge branch 'Lino' of https://github.com/IO420/api-nexus into Axel
This commit is contained in:
@@ -85,5 +85,3 @@ CREATE TABLE `servicio` (
|
||||
PRIMARY KEY (`id_servicio`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb3;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@@ -0,0 +1,8 @@
|
||||
PORT=
|
||||
JWT_SECRET=
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
Front_URL=
|
||||
@@ -54,3 +54,6 @@ pids
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
.delete.txt
|
||||
.delete
|
||||
Generated
+219
-3
@@ -12,12 +12,16 @@
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.0",
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.2",
|
||||
"mysql2": "^3.14.4",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.26"
|
||||
@@ -31,6 +35,7 @@
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.18.1",
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
@@ -2387,6 +2392,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/jwt": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/jwt/-/jwt-11.0.0.tgz",
|
||||
"integrity": "sha512-v7YRsW3Xi8HNTsO+jeHSEEqelX37TVWgwt+BcxtkG/OfXJEOs6GZdbdza200d6KqId1pJQZ6UPj1F0M6E+mxaA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/jsonwebtoken": "9.0.7",
|
||||
"jsonwebtoken": "9.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/mapped-types": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.1.0.tgz",
|
||||
@@ -2407,6 +2425,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/passport": {
|
||||
"version": "11.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/passport/-/passport-11.0.5.tgz",
|
||||
"integrity": "sha512-ulQX6mbjlws92PIM15Naes4F4p2JoxGnIJuUsdXQPT+Oo2sqQmENEZXM7eYuimocfHnKlcfZOuyzbA33LwUlOQ==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
||||
"passport": "^0.5.0 || ^0.6.0 || ^0.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/platform-express": {
|
||||
"version": "11.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-11.1.6.tgz",
|
||||
@@ -2861,6 +2889,15 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/jsonwebtoken": {
|
||||
"version": "9.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.7.tgz",
|
||||
"integrity": "sha512-ugo316mmTYBl2g81zDFnZ7cfxlut3o+/EQdaP7J8QN2kY6lJ22hmQYCK5EHcJHbrW+dkCGSCPgbG8JtYj6qSrg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/methods": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz",
|
||||
@@ -2879,12 +2916,43 @@
|
||||
"version": "22.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.18.1.tgz",
|
||||
"integrity": "sha512-rzSDyhn4cYznVG+PCzGe1lwuMYJrcBS1fc3JqSa2PvtABwWo+dZ1ij5OVok3tqfpEBCBoaR4d7upFJk73HRJDw==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/passport": {
|
||||
"version": "1.0.17",
|
||||
"resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.17.tgz",
|
||||
"integrity": "sha512-aciLyx+wDwT2t2/kJGJR2AEeBz0nJU4WuRX04Wu9Dqc5lSUtwu0WERPHYsLhF9PtseiAMPBGNUOtFjxZ56prsg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/express": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/passport-jwt": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/passport-jwt/-/passport-jwt-4.0.1.tgz",
|
||||
"integrity": "sha512-Y0Ykz6nWP4jpxgEUYq8NoVZeCQPo1ZndJLfapI249g1jHChvRfZRO/LS3tqu26YgAS/laI1qx98sYGz0IalRXQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/jsonwebtoken": "*",
|
||||
"@types/passport-strategy": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/passport-strategy": {
|
||||
"version": "0.2.38",
|
||||
"resolved": "https://registry.npmjs.org/@types/passport-strategy/-/passport-strategy-0.2.38.tgz",
|
||||
"integrity": "sha512-GC6eMqqojOooq993Tmnmp7AUTbbQSgilyvpCYQjT+H6JfG/g6RGc7nXEniZlp0zyKJ0WUdOiZWLBZft9Yug1uA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/express": "*",
|
||||
"@types/passport": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/qs": {
|
||||
"version": "6.14.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.14.0.tgz",
|
||||
@@ -4241,6 +4309,12 @@
|
||||
"ieee754": "^1.1.13"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
@@ -4997,6 +5071,15 @@
|
||||
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ecdsa-sig-formatter": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
@@ -7432,6 +7515,49 @@
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/jsonwebtoken": {
|
||||
"version": "9.0.2",
|
||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz",
|
||||
"integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jws": "^3.2.2",
|
||||
"lodash.includes": "^4.3.0",
|
||||
"lodash.isboolean": "^3.0.3",
|
||||
"lodash.isinteger": "^4.0.4",
|
||||
"lodash.isnumber": "^3.0.3",
|
||||
"lodash.isplainobject": "^4.0.6",
|
||||
"lodash.isstring": "^4.0.1",
|
||||
"lodash.once": "^4.0.0",
|
||||
"ms": "^2.1.1",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12",
|
||||
"npm": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/jwa": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.2.tgz",
|
||||
"integrity": "sha512-eeH5JO+21J78qMvTIDdBXidBd6nG2kZjg5Ohz/1fpa28Z4CcsWUzJ1ZZyFq/3z3N17aZy+ZuBoHljASbL1WfOw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "^1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/jws": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
|
||||
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jwa": "^1.4.1",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/keyv": {
|
||||
"version": "4.5.4",
|
||||
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
||||
@@ -7530,6 +7656,42 @@
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.includes": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||
"integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isboolean": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
||||
"integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
"integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isnumber": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
|
||||
"integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isplainobject": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||
"integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isstring": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
||||
"integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.memoize": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
@@ -7544,6 +7706,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.once": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/log-symbols": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
|
||||
@@ -8258,6 +8426,42 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/passport": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz",
|
||||
"integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"passport-strategy": "1.x.x",
|
||||
"pause": "0.0.1",
|
||||
"utils-merge": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jaredhanson"
|
||||
}
|
||||
},
|
||||
"node_modules/passport-jwt": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-4.0.1.tgz",
|
||||
"integrity": "sha512-UCKMDYhNuGOBE9/9Ycuoyh7vP6jpeTp/+sfMJl7nLff/t6dps+iaeE0hhNkKN8/HZHcJ7lCdOyDxHdDoxoSvdQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"passport-strategy": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/passport-strategy": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
|
||||
"integrity": "sha512-CB97UUvDKJde2V0KDWWB3lyf6PC3FaZP7YxZ2G8OAtn9p4HI9j9JLP9qjOGZFvyl8uwNT8qM+hGnz/n16NI7oA==",
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/path-exists": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
|
||||
@@ -8333,6 +8537,11 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/pause": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
|
||||
"integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg=="
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||
@@ -8877,7 +9086,6 @@
|
||||
"version": "7.7.2",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
|
||||
"integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
@@ -10322,7 +10530,6 @@
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
@@ -10426,6 +10633,15 @@
|
||||
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/utils-merge": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.0",
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.2",
|
||||
"mysql2": "^3.14.4",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.26"
|
||||
@@ -42,6 +46,7 @@
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.18.1",
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { IsInt, IsNotEmpty, Min } from "class-validator";
|
||||
|
||||
export class chargePrintDto {
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
@Min(1)
|
||||
monto:number
|
||||
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@IsNotEmpty()
|
||||
numero_hojas: number;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_cuenta: number;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Body, Controller, Post } from "@nestjs/common";
|
||||
import { OperationsService } from "./operations.services";
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController{
|
||||
constructor(private readonly operationsService:OperationsService){}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data) {
|
||||
return this.operationsService.chargePrint(data,data.userid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Student } from 'src/alumno/entities/student.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.services';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Student, DetalleServicio]), // entidades que usarán las transacciones
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
})
|
||||
export class OperationsModule {}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { StudentService } from 'src/alumno/student.service';
|
||||
import { DetalleServicioService } from 'src/detalle_servicio/detalle_servicio.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { chargePrintDto } from './dto/operations.dto';
|
||||
import { CreateDetalleServicioDto } from 'src/detalle_servicio/dto/create-detalle_servicio.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OperationsService {
|
||||
constructor(
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly studentService: StudentService,
|
||||
private readonly detalleServicioService: DetalleServicioService,
|
||||
) {}
|
||||
|
||||
async chargePrint(data: chargePrintDto, userId: number) {
|
||||
const { monto, id_cuenta } = data;
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
const credit = await this.studentService.GetCredit(id_cuenta);
|
||||
|
||||
if (credit < monto) {
|
||||
throw new BadRequestException('Crédito insuficiente');
|
||||
}
|
||||
|
||||
const detalleData: CreateDetalleServicioDto = {
|
||||
...data,
|
||||
id_servicio: 1,
|
||||
id_usuario: userId,
|
||||
fecha_operacion: new Date(),
|
||||
};
|
||||
|
||||
await this.detalleServicioService.Create(detalleData, queryRunner.manager);
|
||||
|
||||
await this.studentService.UpdateCredit(
|
||||
id_cuenta,
|
||||
monto,
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return { message: 'correct' };
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
return { message: 'error', error: error.message };
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
import { IsEmail, IsNotEmpty, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateStudentDto {
|
||||
@IsNotEmpty()
|
||||
@@ -17,6 +17,7 @@ export class CreateStudentDto {
|
||||
@IsNumber()
|
||||
id_carrera: number;
|
||||
|
||||
@IsEmail()
|
||||
@IsString()
|
||||
correo: string;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Student {
|
||||
scale: 2,
|
||||
default: 0.0,
|
||||
})
|
||||
credito: string;
|
||||
credito: number;
|
||||
|
||||
@Column({
|
||||
name: 'fecha_actualizacion_credito',
|
||||
|
||||
@@ -3,13 +3,10 @@ import {
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { StudentService } from './student.service';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { UpdateStudentDto } from './dto/update-student.dto';
|
||||
import { Student } from './entities/student.entity';
|
||||
|
||||
@Controller('student')
|
||||
@@ -27,17 +24,7 @@ export class StudentController {
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.studentService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) {
|
||||
return this.studentService.update(+id, updateStudentDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.studentService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateStudentDto } from './dto/create-student.dto';
|
||||
import { UpdateStudentDto } from './dto/update-student.dto';
|
||||
import { Student } from './entities/student.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
@@ -32,11 +32,22 @@ export class StudentService {
|
||||
return student;
|
||||
}
|
||||
|
||||
update(id: number, updateStudentDto: UpdateStudentDto) {
|
||||
return `This action updates a #${id} student`;
|
||||
async GetCredit(id_cuenta: number): Promise<Student['credito']> {
|
||||
const student = await this.findOne(id_cuenta);
|
||||
return student.credito;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} student`;
|
||||
async UpdateCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
) {
|
||||
const repo = manager.getRepository(Student);
|
||||
return await repo
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({ credito: () => `credito - ${credit}` })
|
||||
.where({ id_cuenta })
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -5,11 +5,14 @@ import { AppService } from './app.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { StudentModule } from './alumno/student.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
import { User } from './user/entities/user.entity';
|
||||
import { Perfil, User } from './user/entities/user.entity';
|
||||
import { DetalleServicioModule } from './detalle_servicio/detalle_servicio.module';
|
||||
import { PeriodoModule } from './periodo/periodo.module';
|
||||
import { ServicioModule } from './servicio/servicio.module';
|
||||
import { Student } from './alumno/entities/student.entity';
|
||||
import { DetalleServicio } from './detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Periodo } from './periodo/entities/periodo.entity';
|
||||
import { Servicio } from './servicio/entities/servicio.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -26,11 +29,12 @@ import { Student } from './alumno/entities/student.entity';
|
||||
username: configService.get<string>('DB_USER'),
|
||||
password: configService.get<string>('DB_PASSWORD'),
|
||||
database: configService.get<string>('DB_NAME'),
|
||||
entities: [User, Student],
|
||||
synchronize: false,
|
||||
entities: [User,Student,DetalleServicio,Periodo,Servicio,Perfil],
|
||||
synchronize: false,//Never change to true in production!
|
||||
}),
|
||||
}),
|
||||
UserModule,
|
||||
StudentModule,
|
||||
DetalleServicioModule,
|
||||
PeriodoModule,
|
||||
ServicioModule,
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { DetalleServicioController } from './detalle_servicio.controller';
|
||||
import { DetalleServicioService } from './detalle_servicio.service';
|
||||
|
||||
describe('DetalleServicioController', () => {
|
||||
let controller: DetalleServicioController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [DetalleServicioController],
|
||||
providers: [DetalleServicioService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<DetalleServicioController>(DetalleServicioController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,34 +1,9 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { DetalleServicioService } from './detalle_servicio.service';
|
||||
import { CreateDetalleServicioDto } from './dto/create-detalle_servicio.dto';
|
||||
import { UpdateDetalleServicioDto } from './dto/update-detalle_servicio.dto';
|
||||
|
||||
|
||||
@Controller('detalle-servicio')
|
||||
export class DetalleServicioController {
|
||||
constructor(private readonly detalleServicioService: DetalleServicioService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createDetalleServicioDto: CreateDetalleServicioDto) {
|
||||
return this.detalleServicioService.create(createDetalleServicioDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.detalleServicioService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.detalleServicioService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateDetalleServicioDto: UpdateDetalleServicioDto) {
|
||||
return this.detalleServicioService.update(+id, updateDetalleServicioDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.detalleServicioService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { DetalleServicioService } from './detalle_servicio.service';
|
||||
|
||||
describe('DetalleServicioService', () => {
|
||||
let service: DetalleServicioService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [DetalleServicioService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<DetalleServicioService>(DetalleServicioService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,26 +1,13 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DetalleServicio } from './entities/detalle_servicio.entity';
|
||||
import { EntityManager } from 'typeorm';
|
||||
import { CreateDetalleServicioDto } from './dto/create-detalle_servicio.dto';
|
||||
import { UpdateDetalleServicioDto } from './dto/update-detalle_servicio.dto';
|
||||
|
||||
@Injectable()
|
||||
export class DetalleServicioService {
|
||||
create(createDetalleServicioDto: CreateDetalleServicioDto) {
|
||||
return 'This action adds a new detalleServicio';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all detalleServicio`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} detalleServicio`;
|
||||
}
|
||||
|
||||
update(id: number, updateDetalleServicioDto: UpdateDetalleServicioDto) {
|
||||
return `This action updates a #${id} detalleServicio`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} detalleServicio`;
|
||||
async Create(data: CreateDetalleServicioDto, manager: EntityManager) {
|
||||
const repo = manager.getRepository(DetalleServicio);
|
||||
const details = repo.create(data);
|
||||
return await repo.save(details);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsInt, IsNotEmpty, IsOptional, Min } from 'class-validator';
|
||||
import { IsDate, IsIn, IsInt, IsNotEmpty, IsOptional, Min } from 'class-validator';
|
||||
|
||||
export class CreateDetalleServicioDto {
|
||||
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
@IsNotEmpty()
|
||||
@Min(1)
|
||||
monto:number
|
||||
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@IsNotEmpty()
|
||||
numero_hojas: number;
|
||||
|
||||
@@ -23,8 +29,4 @@ export class CreateDetalleServicioDto {
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_usuario: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
id_periodo?: number;
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
export class DetalleServicioDto {
|
||||
id_detalle_servicio: number;
|
||||
numero_hojas: number;
|
||||
fecha_operacion: Date;
|
||||
id_cuenta: number;
|
||||
id_servicio: number;
|
||||
id_usuario: number;
|
||||
id_periodo: number | null;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export class DetalleServicio {
|
||||
scale: 2,
|
||||
nullable: false,
|
||||
})
|
||||
monto: string;
|
||||
monto: number;
|
||||
|
||||
@Column({ name: 'numero_hojas', type: 'int', nullable: false, default: 0 })
|
||||
numero_hojas: number;
|
||||
@@ -39,13 +39,4 @@ export class DetalleServicio {
|
||||
|
||||
@Column({ name: 'id_perido', type: 'int', default: null })
|
||||
id_periodo: number;
|
||||
}
|
||||
|
||||
/* `id_detalle_servicio` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`monto` decimal(10,2) NOT NULL,
|
||||
`numero_hojas` int(11) NOT NULL DEFAULT 0,
|
||||
`fecha_operacion` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`id_cuenta` int(9) unsigned zerofill NOT NULL,
|
||||
`id_servicio` int(11) NOT NULL,
|
||||
`id_usuario` int(11) NOT NULL,
|
||||
`id_periodo` int(11) DEFAULT NULL,*/
|
||||
}
|
||||
+10
-1
@@ -1,11 +1,20 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
const configService = app.get(ConfigService);
|
||||
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
app.enableCors();
|
||||
|
||||
app.enableCors(
|
||||
{
|
||||
origin: configService.get<string>('Front_URL'),
|
||||
}
|
||||
);
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PeriodoController } from './periodo.controller';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
|
||||
describe('PeriodoController', () => {
|
||||
let controller: PeriodoController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [PeriodoController],
|
||||
providers: [PeriodoService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<PeriodoController>(PeriodoController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
|
||||
describe('PeriodoService', () => {
|
||||
let service: PeriodoService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [PeriodoService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<PeriodoService>(PeriodoService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ServicioController } from './servicio.controller';
|
||||
import { ServicioService } from './servicio.service';
|
||||
|
||||
describe('ServicioController', () => {
|
||||
let controller: ServicioController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ServicioController],
|
||||
providers: [ServicioService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ServicioController>(ServicioController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -32,3 +32,4 @@ export class ServicioController {
|
||||
return this.servicioService.remove(+id);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ServicioService } from './servicio.service';
|
||||
|
||||
describe('ServicioService', () => {
|
||||
let service: ServicioService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ServicioService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ServicioService>(ServicioService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,35 +1,54 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity({name:'usuario'})
|
||||
export class User {
|
||||
@Entity({ name: 'perfil' })
|
||||
export class Perfil {
|
||||
@PrimaryGeneratedColumn({ name: 'id_perfil', type: 'int' })
|
||||
id_perfil: number;
|
||||
|
||||
@PrimaryGeneratedColumn({name:'id_usuario',type: 'int'})
|
||||
id_usuario:number;
|
||||
@Column({ name: 'perfil', type: 'varchar', length: 45, nullable: false })
|
||||
perfil: string;
|
||||
|
||||
@Column({name:'nombre',type:'varchar'})
|
||||
nombre:string
|
||||
|
||||
@Column({name:'apellido_paterno',type:'varchar'})
|
||||
apellido_paterno:string
|
||||
|
||||
@Column({name:'apellido_materno',type:'varchar'})
|
||||
apellido_materno:string
|
||||
|
||||
@Column({name:'usuario',type:'varchar'})
|
||||
usuario:string
|
||||
|
||||
@Column({name:'password',type:'varchar',length:45, nullable:false})
|
||||
password:string
|
||||
|
||||
@Column({name:'activo',type:'tinyint',nullable:false, default:1})
|
||||
activo: number
|
||||
|
||||
@Column({name:'descripcion',type:'varchar',length:50,default:null})
|
||||
description:boolean
|
||||
|
||||
@Column({name:'fecha_registro',type:'varchar'})
|
||||
fecha_registro:string
|
||||
|
||||
@Column({name:'id_perfil',})
|
||||
id_perfil:number
|
||||
@OneToMany(() => User, (user) => user.perfil)
|
||||
usuarios: User[];
|
||||
}
|
||||
|
||||
@Entity({ name: 'usuario' })
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
|
||||
id_usuario: number;
|
||||
|
||||
@Column({ name: 'nombre', type: 'varchar' })
|
||||
nombre: string;
|
||||
|
||||
@Column({ name: 'apellido_paterno', type: 'varchar' })
|
||||
apellido_paterno: string;
|
||||
|
||||
@Column({ name: 'apellido_materno', type: 'varchar' })
|
||||
apellido_materno: string;
|
||||
|
||||
@Column({ name: 'usuario', type: 'varchar' })
|
||||
usuario: string;
|
||||
|
||||
@Column({ name: 'password', type: 'varchar', length: 45, nullable: false })
|
||||
password: string;
|
||||
|
||||
@Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 })
|
||||
activo: number;
|
||||
|
||||
@Column({ name: 'descripcion', type: 'varchar', length: 50, default: null })
|
||||
description: boolean;
|
||||
|
||||
@Column({ name: 'fecha_registro', type: 'varchar' })
|
||||
fecha_registro: string;
|
||||
|
||||
@ManyToOne(() => Perfil, (perfil) => perfil.usuarios, { eager: true })
|
||||
@JoinColumn({ name: 'id_perfil' })
|
||||
perfil: Perfil;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { UserService } from './user.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private configService: ConfigService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: configService.get('JWT_SECRET')!,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
return { userId: payload.id, username: payload.usuario };
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,30 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Post()
|
||||
Login(@Body() user: CreateUserDto) {
|
||||
return this.userService.Login(user);
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('/validate-token')
|
||||
getProfile(@Request() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
}
|
||||
//IO
|
||||
|
||||
+20
-4
@@ -3,13 +3,29 @@ import { UserService } from './user.service';
|
||||
import { UserController } from './user.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { JwtStrategy } from './jwt.strategy';
|
||||
|
||||
@Module({
|
||||
imports:[
|
||||
TypeOrmModule.forFeature([User])
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User]),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
return {
|
||||
global: true,
|
||||
secret: configService.get('JWT_SECRET'),
|
||||
signOptions: { expiresIn: '1h' },
|
||||
};
|
||||
},
|
||||
|
||||
}),
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService],
|
||||
providers: [UserService,JwtStrategy],
|
||||
exports: [UserService],
|
||||
})
|
||||
export class UserModule {}
|
||||
export class UserModule { }
|
||||
|
||||
@@ -1,38 +1,51 @@
|
||||
import { Injectable, Logger, NotFoundException, UnauthorizedException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
private readonly userRepository: Repository<User>,
|
||||
|
||||
private jwtService: JwtService
|
||||
) { }
|
||||
|
||||
async findOneByNameandPassword(data:CreateUserDto): Promise<User> {
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
|
||||
const { usuario, password } = data
|
||||
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario,password }
|
||||
where: { usuario, password }
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(
|
||||
`El usuario ${usuario} no fue encontrado`,
|
||||
`El usuario o la contraseña es incorrecta`,
|
||||
);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto) {
|
||||
|
||||
async Login(data: CreateUserDto, res: Response) {
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
return user
|
||||
|
||||
const payload = { id: user.id_usuario, usuario: user.usuario };
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
res.cookie('token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // en dev desactívalo
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return res.json({ message: 'Inicio de sesión exitoso' });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user