From 5b62b65d51d9540f6aecce69b280d8e0f3d2fe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:54:56 -0600 Subject: [PATCH 1/4] instalando libreria para crear codigos qr --- backend/package-lock.json | 194 ++++++++++++++++++++++++++++++-------- backend/package.json | 2 + 2 files changed, 157 insertions(+), 39 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 07cd3119..887ba3f6 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -18,13 +18,13 @@ "@nestjs/serve-static": "^4.0.2", "@nestjs/swagger": "^7.3.0", "@nestjs/typeorm": "^10.0.2", - "axios": "^1.7.5", "bcrypt": "^5.1.1", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", "dotenv": "^16.4.5", "mysql2": "^3.9.2", "network": "^0.7.0", + "qrcode": "^1.5.4", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "typeorm": "^0.3.20" @@ -38,6 +38,7 @@ "@types/jest": "^29.5.2", "@types/multer": "^1.4.11", "@types/node": "^20.3.1", + "@types/qrcode": "^1.5.5", "@types/supertest": "^6.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", @@ -2616,6 +2617,15 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/qrcode": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.5.5.tgz", + "integrity": "sha512-CdfBi/e3Qk+3Z/fXYShipBT13OJ2fDO2Q2w5CIP5anLTLIndQG9z6P1cnm+8zCWSpm5dnxMFd/uREtb0EXuQzg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/qs": { "version": "6.9.12", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.12.tgz", @@ -3374,16 +3384,6 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, - "node_modules/axios": { - "version": "1.7.5", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz", - "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -3772,7 +3772,6 @@ "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", - "dev": true, "engines": { "node": ">=6" } @@ -4323,6 +4322,14 @@ } } }, + "node_modules/decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/dedent": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", @@ -4463,6 +4470,11 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dijkstrajs": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.3.tgz", + "integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==" + }, "node_modules/dir-glob": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", @@ -5332,25 +5344,6 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, - "node_modules/follow-redirects": { - "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/foreground-child": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", @@ -5420,6 +5413,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -7962,7 +7956,6 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true, "engines": { "node": ">=6" } @@ -8027,7 +8020,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, "engines": { "node": ">=8" } @@ -8191,6 +8183,14 @@ "node": ">=4" } }, + "node_modules/pngjs": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz", + "integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==", + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -8317,11 +8317,6 @@ "node": ">= 0.10" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -8347,6 +8342,118 @@ } ] }, + "node_modules/qrcode": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz", + "integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==", + "dependencies": { + "dijkstrajs": "^1.0.1", + "pngjs": "^5.0.0", + "yargs": "^15.3.1" + }, + "bin": { + "qrcode": "bin/qrcode" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/qrcode/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" + } + }, + "node_modules/qrcode/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/qrcode/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==" + }, + "node_modules/qrcode/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "dependencies": { + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/qrcode/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "dependencies": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/qs": { "version": "6.11.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", @@ -8504,6 +8611,11 @@ "node": ">=0.10.0" } }, + "node_modules/require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -10286,6 +10398,11 @@ "node": ">= 8" } }, + "node_modules/which-module": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==" + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", @@ -10323,7 +10440,6 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", diff --git a/backend/package.json b/backend/package.json index 4b33bcab..1f6f164f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -35,6 +35,7 @@ "dotenv": "^16.4.5", "mysql2": "^3.9.2", "network": "^0.7.0", + "qrcode": "^1.5.4", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "typeorm": "^0.3.20" @@ -48,6 +49,7 @@ "@types/jest": "^29.5.2", "@types/multer": "^1.4.11", "@types/node": "^20.3.1", + "@types/qrcode": "^1.5.5", "@types/supertest": "^6.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", -- GitLab From e43fa26fd5c799df84efb87b6947d35056678fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:55:08 -0600 Subject: [PATCH 2/4] funcion para crear un codigo qr --- backend/src/pointOfInterest/utils/qrcode.ts | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/src/pointOfInterest/utils/qrcode.ts diff --git a/backend/src/pointOfInterest/utils/qrcode.ts b/backend/src/pointOfInterest/utils/qrcode.ts new file mode 100644 index 00000000..f314cd7b --- /dev/null +++ b/backend/src/pointOfInterest/utils/qrcode.ts @@ -0,0 +1,31 @@ +import * as qrcode from 'qrcode'; +import * as fs from 'fs'; +import { InternalServerErrorException } from '@nestjs/common'; +import * as path from 'path'; +import { ServerConstants } from 'src/constants/server.contants'; + +const QR_FOLDER = 'qr'; +export const generateQRCode = async (idState: number, idTown: number, idActivity: number, idPoint: number) => { + try { + const url = `/state/${idState}/town/${idTown}/activity/${idActivity}/travel?id=${idPoint}`; + const qrCodeImage = await qrcode.toDataURL(url); + + // Decode base64 string + const base64Data = qrCodeImage.replace(/^data:image\/png;base64,/, ''); + + // Save image to the filesystem + const filename = path.join(ServerConstants.ROOT_STATIC_PATH, QR_FOLDER, `${idPoint}.png`); + + fs.writeFile(filename, base64Data, 'base64', (err) => { + if (err) { + console.error(err); + throw new InternalServerErrorException('Error saving QR code image'); + } else { + console.log('QR code image saved as qrcode.png'); + } + }); + } catch (err) { + console.error(err); + throw new InternalServerErrorException('Error generating QR code'); + } +}; -- GitLab From 415228ec6de7bf9c47ad14ca85708622873feec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:55:24 -0600 Subject: [PATCH 3/4] agregando creacion de codigo qr --- backend/src/pointOfInterest/PointOfInterest.service.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/pointOfInterest/PointOfInterest.service.ts b/backend/src/pointOfInterest/PointOfInterest.service.ts index 95cd7232..5c23f3d5 100644 --- a/backend/src/pointOfInterest/PointOfInterest.service.ts +++ b/backend/src/pointOfInterest/PointOfInterest.service.ts @@ -12,6 +12,8 @@ import { getPointDto } from './dto/getPoint.dto'; import { ServerConstants } from 'src/constants/server.contants'; import { createReadStream } from 'fs'; import { join } from 'path'; +import { generateQRCode } from './utils/qrcode'; +import { Place } from 'src/place/entities/place.entity'; @Injectable() export class PointOfInterestService { @@ -19,9 +21,15 @@ export class PointOfInterestService { @InjectRepository(PointOfInterest) private pointRepository: Repository, @InjectRepository(PointOfInterestTraduction) private pointTraductionRepository, private readonly placeService: PlaceService, + @InjectRepository(Place) private placeRepository: Repository, @InjectDataSource() private dataSource: DataSource, ) {} async create(createPointAndTradDto: CreatePointAndTradDto) { + const placeRelation = await this.placeRepository.findOne({ + where: { idPlace: createPointAndTradDto.idPlace }, + relations: ['town'], + }); + const place = await this.placeService.findOne(createPointAndTradDto.idPlace); if (!place) { throw new BadRequestException('Place not found'); @@ -50,6 +58,7 @@ export class PointOfInterestService { }; await this.pointTraductionRepository.insert(createTradEs); await this.pointTraductionRepository.insert(createTradEn); + generateQRCode(placeRelation.town.state.stateId, placeRelation.town.townId, placeRelation.idPlace, insertedId); } async findAllByPlace(idPlace: number, lang: LANGUAGES): Promise { @@ -84,6 +93,7 @@ export class PointOfInterestService { directions: point.directions, }; }); + return points; } -- GitLab From ca339668eae16a8a9bfca59865357deb606ad06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:15:48 -0600 Subject: [PATCH 4/4] creando carpeta para guardar los codigos qr --- backend/static/qr/qrcode.png | Bin 0 -> 984 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 backend/static/qr/qrcode.png diff --git a/backend/static/qr/qrcode.png b/backend/static/qr/qrcode.png new file mode 100644 index 0000000000000000000000000000000000000000..a5e1e86c7b2043712e58021e25705b30d3176fe1 GIT binary patch literal 984 zcma)5O-vI(7+t9`mZUUUZv3QCmMV=THIS?(jZK>x8Emm-_n;h5VnDdGm3U|q(u1xx z9zf||fEsE;UE$(^c#woxp?cYHXz)rP5cgoBN$J7Rq$z&iw%s1}Ff%)uo%i1N-ZwAZ zL$`FzZOs%#>BxX%7*+wt`ExLP9M9gv(nK6KK5*t&TWFV}H1oLoy=9y0AWa(EqqmjQ z@%x>BzHrp@9q;7XrEk`SQa0zjz7zY`R4TaXP*iFqCod!yy)<}x+cz9MGIK3`vYETF z>6Be0a8c`$joMxe2H6H+Df^=iT7DSuuM~ChB-}b(SO3lNpaUgvQ{1XmIXDv z+Jk{@miO`_4abi4qv+2blU}pTE2K!Qkb_i!RZMT`>#l5RNFXY)KrsT=C2Mr>jTQvI zD|L^FGl4}o11~WHMBQUR!ySZwT(>TC4*+H%R#t&>(OxtKIU6M!>TV>2R0eEG#lSmW z4f!T#XsU)R&f AL;wH) literal 0 HcmV?d00001 -- GitLab