From 2f50428c34ee21c10c88b2d3bf4a42fb69e2cb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Geraldo=20D=2E=20F?= Date: Thu, 30 May 2024 18:44:38 -0300 Subject: [PATCH] =?UTF-8?q?Feat:=20carrinho=20de=20doa=C3=A7=C3=B5es=20(#1?= =?UTF-8?q?82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sos-rs.insomnia.json | 670 +++++++++++++++++- prisma/dev_dump.sql | 2 +- .../migrations/20240528182902_/migration.sql | 44 ++ prisma/schema.prisma | 61 +- src/app.module.ts | 4 +- .../dashboard/dashboard.controller.spec.ts | 12 +- .../dashboard/dashboard.controller.ts | 0 .../dashboard/dashboard.module.ts | 0 .../dashboard/dashboard.service.spec.ts | 12 +- .../dashboard/dashboard.service.ts | 82 ++- .../donation-order.controller.spec.ts | 30 + .../donation-order.controller.ts | 82 +++ src/donation-order/donation-order.module.ts | 12 + .../donation-order.service.spec.ts | 28 + src/donation-order/donation-order.service.ts | 143 ++++ src/donation-order/types.ts | 39 + .../shelter-supply-history/utils.ts | 32 +- .../shelter-supply.controller.ts | 22 - src/shelter-supply/shelter-supply.service.ts | 51 +- src/shelter-supply/types.ts | 6 - src/shelter/shelter.service.ts | 2 +- .../supplies-history.service.ts | 1 + src/users/users.controller.ts | 41 +- src/users/users.service.ts | 9 + 24 files changed, 1216 insertions(+), 169 deletions(-) create mode 100644 prisma/migrations/20240528182902_/migration.sql rename src/{modules => }/dashboard/dashboard.controller.spec.ts (67%) rename src/{modules => }/dashboard/dashboard.controller.ts (100%) rename src/{modules => }/dashboard/dashboard.module.ts (100%) rename src/{modules => }/dashboard/dashboard.service.spec.ts (61%) rename src/{modules => }/dashboard/dashboard.service.ts (73%) create mode 100644 src/donation-order/donation-order.controller.spec.ts create mode 100644 src/donation-order/donation-order.controller.ts create mode 100644 src/donation-order/donation-order.module.ts create mode 100644 src/donation-order/donation-order.service.spec.ts create mode 100644 src/donation-order/donation-order.service.ts create mode 100644 src/donation-order/types.ts diff --git a/docs/sos-rs.insomnia.json b/docs/sos-rs.insomnia.json index 52abb855..916ae0ac 100644 --- a/docs/sos-rs.insomnia.json +++ b/docs/sos-rs.insomnia.json @@ -1 +1,669 @@ -{"_type":"export","__export_format":4,"__export_date":"2024-05-08T00:03:58.774Z","__export_source":"insomnia.desktop.app:v2023.5.8","resources":[{"_id":"req_2cec83a23bd8471691471135813f5c97","parentId":"fld_c4388cda095c4c39a43aafa32cefe2b8","modified":1714943748677,"created":1714936267905,"url":"{{ _.url }}/users","name":"Create","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"name\": \"Dinho\",\n\t\"lastName\": \"Duarte\",\n\t\"phone\": \"(31) 996675945\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714464599040,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_c4388cda095c4c39a43aafa32cefe2b8","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714940272493,"created":1714935778575,"name":"Users","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714937058452,"_type":"request_group"},{"_id":"wrk_a61684b639de4828aadbeb27d5fb06c2","parentId":null,"modified":1714933336427,"created":1714933336427,"name":"SOS - RS","description":"","scope":"collection","_type":"workspace"},{"_id":"req_e21013e88a174768a98348955f72c132","parentId":"fld_c4388cda095c4c39a43aafa32cefe2b8","modified":1714937581205,"created":1714937048293,"url":"{{ _.url }}/users","name":"Update","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n\t\"password\": \"{{ _.password }}\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}"},"metaSortKey":-1714228783645,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_04870db7df8f4303a36816da619912a3","parentId":"fld_73a709cd6af74d3fbb4405084ec5e8ca","modified":1714948018434,"created":1714937067812,"url":"{{ _.url }}/sessions","name":"Login","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"login\": \"31996675945\",\n\t\"password\": \"{{ _.password }}\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937071296,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_73a709cd6af74d3fbb4405084ec5e8ca","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714940270087,"created":1714937057951,"name":"Sessions","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714937058352,"_type":"request_group"},{"_id":"req_af589f721bf64c3284282ba537363913","parentId":"fld_73a709cd6af74d3fbb4405084ec5e8ca","modified":1714937629632,"created":1714937602570,"url":"{{ _.url }}/sessions","name":"Show","description":"","method":"GET","body":{},"parameters":[],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}","disabled":false},"metaSortKey":-1714700835168,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_29c7dc3ac6d6499eaee070b9a16df23d","parentId":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","modified":1715027093193,"created":1714938746809,"url":"{{ _.url }}/shelters","name":"Index","description":"","method":"GET","body":{},"parameters":[{"id":"pair_ed301dbad729421a819cf291a5476e0d","name":"search","value":"address:contains:avenida,name:contains:abrigo","description":"","disabled":false},{"id":"pair_ff5b87c85c9f43cf8d949b7dcce34b8a","name":"perPage","value":"2","description":"","disabled":false},{"id":"pair_f1811cb5e0d74429b94592ec3695aa46","name":"page","value":"2","description":"","disabled":false},{"id":"pair_f577dad0d6fb4d90ba7f40a3024cae1c","name":"or","value":"true","description":"","disabled":false},{"id":"pair_612e6829b3ee4689b38269c704c351ba","name":"","value":"","description":""}],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714938160109,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714940263026,"created":1714937696393,"name":"Shelters","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714937058152,"_type":"request_group"},{"_id":"req_3a33bb80e5f443e08da29f5402326698","parentId":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","modified":1715007005651,"created":1714971065261,"url":"{{ _.url }}/shelters/62a17be9-a744-42a6-a7dd-8ce2872c56c8","name":"Show","description":"","method":"GET","body":{},"parameters":[],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714938160059,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_e752bbc19fa74ed4a2f98df209429042","parentId":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","modified":1714964882912,"created":1714938158398,"url":"{{ _.url }}/shelters","name":"Create","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"pix\": \"abrigo-test@gmail.com\",\n\t\"name\": \"Abrigo\",\n\t\"address\": \"Porto Alegre 123 - Rio Grande do Sul\",\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 200,\n\t\"contact\": \"(51) 99999-9999\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}"},"metaSortKey":-1714938160009,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_19a1b609ba8945918f1522f39f790aa4","parentId":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","modified":1714939354278,"created":1714939326458,"url":"{{ _.url }}/shelters/f48720c2-53c0-4ad7-8ecb-5d99715289ff","name":"Update","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 100\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937887830.75,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_73490676e9284d929c11a147ac08bc91","parentId":"fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d","modified":1714940105497,"created":1714940087947,"url":"{{ _.url }}/shelters/f48720c2-53c0-4ad7-8ecb-5d99715289ff/admin","name":"Update Adm","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 100,\n\t\"address\": \"Porto Alegre 252 - Rio Grande do Sul\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937751741.625,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_f9f8be1faea348378c53e6dca51b27b4","parentId":"fld_43a721aaeef04e1386732d41c31a778a","modified":1714941828416,"created":1714941788002,"url":"{{ _.url }}/supply-categories","name":"Index","description":"","method":"GET","body":{},"parameters":[{"id":"pair_ed301dbad729421a819cf291a5476e0d","name":"search","value":"pix:contains:abrigo","description":"","disabled":true},{"id":"pair_ff5b87c85c9f43cf8d949b7dcce34b8a","name":"perPage","value":"1","description":"","disabled":true},{"id":"pair_f1811cb5e0d74429b94592ec3695aa46","name":"page","value":"2","description":"","disabled":true}],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714938160109,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_43a721aaeef04e1386732d41c31a778a","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714941792124,"created":1714941787999,"name":"Supply Category","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714701034874.75,"_type":"request_group"},{"_id":"req_99ec7d50412242d58edf68ca7745d082","parentId":"fld_43a721aaeef04e1386732d41c31a778a","modified":1714948186876,"created":1714941788001,"url":"{{ _.url }}/supply-categories","name":"Create","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"name\": \"Roupas\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}"},"metaSortKey":-1714938160009,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_71fea5194e9143a1adeccc1f9e751868","parentId":"fld_43a721aaeef04e1386732d41c31a778a","modified":1714944576289,"created":1714941788004,"url":"{{ _.url }}/supply-categories/8b684946-89b7-4741-81e5-cb679d94fae7","name":"Update","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n\t\"name\": \"Roupas\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}"},"metaSortKey":-1714937887830.75,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_e540a2a47e854964a90c85c954e3a5fa","parentId":"fld_2b4a4b05308748559e1abe82ec94d62c","modified":1714963807376,"created":1714941690618,"url":"{{ _.url }}/supplies","name":"Create","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"shelterId\": \"{{ _.shelterId }}\",\n\t\"supplyCategoryId\": \"236d72c4-66d1-4a06-8749-625dc16dc11a\",\n\t\"name\": \"Absorvente\",\n\t\"priority\": 0\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714938160009,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_2b4a4b05308748559e1abe82ec94d62c","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714941690616,"created":1714941690616,"name":"Supplies","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714465011597.5,"_type":"request_group"},{"_id":"req_b0641cadd0604de7961042b83c84199d","parentId":"fld_2b4a4b05308748559e1abe82ec94d62c","modified":1714963287737,"created":1714941690622,"url":"{{ _.url }}/supplies/867584d6-f7b6-45c8-9f68-98190639a324","name":"Update","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n\t\"priority\": 10\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937887830.75,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_e6d2ab40315f4b40b1d7e5dc21bff09b","parentId":"fld_2b4a4b05308748559e1abe82ec94d62c","modified":1714948340128,"created":1714941690620,"url":"{{ _.url }}/supplies/{{ _.shelterId }}","name":"Index","description":"","method":"GET","body":{},"parameters":[{"id":"pair_ed301dbad729421a819cf291a5476e0d","name":"search","value":"pix:contains:abrigo","description":"","disabled":true},{"id":"pair_ff5b87c85c9f43cf8d949b7dcce34b8a","name":"perPage","value":"1","description":"","disabled":true},{"id":"pair_f1811cb5e0d74429b94592ec3695aa46","name":"page","value":"2","description":"","disabled":true}],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937615652.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_b02963992a3546868c226e54c25e3499","parentId":"fld_c7f5b02294b44b20bce3de13b7f14710","modified":1715026104841,"created":1715025970336,"url":"{{ _.url }}/shelter/managers","name":"Create","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n\t\"shelterId\": \"{{ _.shelterId }}\",\n\t\"userId\": \"7f71d975-03d1-4a7d-859e-cf5f03845473\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"},{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{"type":"bearer","token":"{{ _.token }}"},"metaSortKey":-1714938160009,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_c7f5b02294b44b20bce3de13b7f14710","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1715025970334,"created":1715025970334,"name":"Shelter Manager","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1714228988320.25,"_type":"request_group"},{"_id":"req_15404a5b37ea4872ac0bef869246a0e8","parentId":"fld_c7f5b02294b44b20bce3de13b7f14710","modified":1715026350701,"created":1715025970338,"url":"{{ _.url }}/shelter/managers/{{ _.shelterId }}","name":"Index","description":"","method":"GET","body":{},"parameters":[{"id":"pair_6463a0ccc83742c99202284e920784cb","name":"includes","value":"user","description":"","disabled":true}],"headers":[{"name":"User-Agent","value":"insomnia/2023.5.8"}],"authentication":{},"metaSortKey":-1714937615652.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_3f99728f85808417b4aa32432285d40a45688cee","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1715126560949,"created":1714933336431,"name":"Base Environment","data":{"baseURL":"http://localhost:4000","externalURL":"https://api.sos-rs.com","url":"{{ _.baseURL }}","password":"12345678","shelterId":"01d7c6e8-f040-486e-bb26-968ec4e8c717","token":""},"dataPropertyOrder":{"&":["baseURL","externalURL","url","password","shelterId","token"]},"color":null,"isPrivate":false,"metaSortKey":1714933336431,"_type":"environment"},{"_id":"jar_3f99728f85808417b4aa32432285d40a45688cee","parentId":"wrk_a61684b639de4828aadbeb27d5fb06c2","modified":1714933336431,"created":1714933336431,"name":"Default Jar","cookies":[],"_type":"cookie_jar"}]} \ No newline at end of file +{ + "_type": "export", + "__export_format": 4, + "__export_date": "2024-05-08T00:03:58.774Z", + "__export_source": "insomnia.desktop.app:v2023.5.8", + "resources": [ + { + "_id": "req_2cec83a23bd8471691471135813f5c97", + "parentId": "fld_c4388cda095c4c39a43aafa32cefe2b8", + "modified": 1714943748677, + "created": 1714936267905, + "url": "{{ _.url }}/users", + "name": "Create", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"name\": \"Administrador\",\n\t\"lastName\": \"WEB\",\n\t\"phone\": \"(31) 999999999\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714464599040, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_c4388cda095c4c39a43aafa32cefe2b8", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714940272493, + "created": 1714935778575, + "name": "Users", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714937058452, + "_type": "request_group" + }, + { + "_id": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "parentId": null, + "modified": 1714933336427, + "created": 1714933336427, + "name": "SOS - RS", + "description": "", + "scope": "collection", + "_type": "workspace" + }, + { + "_id": "req_e21013e88a174768a98348955f72c132", + "parentId": "fld_c4388cda095c4c39a43aafa32cefe2b8", + "modified": 1714937581205, + "created": 1714937048293, + "url": "{{ _.url }}/users", + "name": "Update", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"password\": \"{{ _.password }}\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": { "type": "bearer", "token": "{{ _.token }}" }, + "metaSortKey": -1714228783645, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_04870db7df8f4303a36816da619912a3", + "parentId": "fld_73a709cd6af74d3fbb4405084ec5e8ca", + "modified": 1714948018434, + "created": 1714937067812, + "url": "{{ _.url }}/sessions", + "name": "Login", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"login\": \"31999999999\",\n\t\"password\": \"{{ _.password }}\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714937071296, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_73a709cd6af74d3fbb4405084ec5e8ca", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714940270087, + "created": 1714937057951, + "name": "Sessions", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714937058352, + "_type": "request_group" + }, + { + "_id": "req_af589f721bf64c3284282ba537363913", + "parentId": "fld_73a709cd6af74d3fbb4405084ec5e8ca", + "modified": 1714937629632, + "created": 1714937602570, + "url": "{{ _.url }}/sessions", + "name": "Show", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": { + "type": "bearer", + "token": "{{ _.token }}", + "disabled": false + }, + "metaSortKey": -1714700835168, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_29c7dc3ac6d6499eaee070b9a16df23d", + "parentId": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "modified": 1715027093193, + "created": 1714938746809, + "url": "{{ _.url }}/shelters", + "name": "Index", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_ed301dbad729421a819cf291a5476e0d", + "name": "search", + "value": "address:contains:avenida,name:contains:abrigo", + "description": "", + "disabled": false + }, + { + "id": "pair_ff5b87c85c9f43cf8d949b7dcce34b8a", + "name": "perPage", + "value": "2", + "description": "", + "disabled": false + }, + { + "id": "pair_f1811cb5e0d74429b94592ec3695aa46", + "name": "page", + "value": "2", + "description": "", + "disabled": false + }, + { + "id": "pair_f577dad0d6fb4d90ba7f40a3024cae1c", + "name": "or", + "value": "true", + "description": "", + "disabled": false + }, + { + "id": "pair_612e6829b3ee4689b38269c704c351ba", + "name": "", + "value": "", + "description": "" + } + ], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": {}, + "metaSortKey": -1714938160109, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714940263026, + "created": 1714937696393, + "name": "Shelters", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714937058152, + "_type": "request_group" + }, + { + "_id": "req_3a33bb80e5f443e08da29f5402326698", + "parentId": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "modified": 1715007005651, + "created": 1714971065261, + "url": "{{ _.url }}/shelters/62a17be9-a744-42a6-a7dd-8ce2872c56c8", + "name": "Show", + "description": "", + "method": "GET", + "body": {}, + "parameters": [], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": {}, + "metaSortKey": -1714938160059, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_e752bbc19fa74ed4a2f98df209429042", + "parentId": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "modified": 1714964882912, + "created": 1714938158398, + "url": "{{ _.url }}/shelters", + "name": "Create", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"pix\": \"abrigo-test@gmail.com\",\n\t\"name\": \"Abrigo\",\n\t\"address\": \"Porto Alegre 123 - Rio Grande do Sul\",\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 200,\n\t\"contact\": \"(51) 99999-9999\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": { "type": "bearer", "token": "{{ _.token }}" }, + "metaSortKey": -1714938160009, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_19a1b609ba8945918f1522f39f790aa4", + "parentId": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "modified": 1714939354278, + "created": 1714939326458, + "url": "{{ _.url }}/shelters/f48720c2-53c0-4ad7-8ecb-5d99715289ff", + "name": "Update", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 100\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714937887830.75, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_73490676e9284d929c11a147ac08bc91", + "parentId": "fld_66073a1e9d6c415aa0ccf6c5fcfb5d7d", + "modified": 1714940105497, + "created": 1714940087947, + "url": "{{ _.url }}/shelters/f48720c2-53c0-4ad7-8ecb-5d99715289ff/admin", + "name": "Update Adm", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"petFriendly\": true,\n\t\"shelteredPeople\": null,\n\t\"capacity\": 100,\n\t\"address\": \"Porto Alegre 252 - Rio Grande do Sul\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714937751741.625, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_f9f8be1faea348378c53e6dca51b27b4", + "parentId": "fld_43a721aaeef04e1386732d41c31a778a", + "modified": 1714941828416, + "created": 1714941788002, + "url": "{{ _.url }}/supply-categories", + "name": "Index", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_ed301dbad729421a819cf291a5476e0d", + "name": "search", + "value": "pix:contains:abrigo", + "description": "", + "disabled": true + }, + { + "id": "pair_ff5b87c85c9f43cf8d949b7dcce34b8a", + "name": "perPage", + "value": "1", + "description": "", + "disabled": true + }, + { + "id": "pair_f1811cb5e0d74429b94592ec3695aa46", + "name": "page", + "value": "2", + "description": "", + "disabled": true + } + ], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": {}, + "metaSortKey": -1714938160109, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_43a721aaeef04e1386732d41c31a778a", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714941792124, + "created": 1714941787999, + "name": "Supply Category", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714701034874.75, + "_type": "request_group" + }, + { + "_id": "req_99ec7d50412242d58edf68ca7745d082", + "parentId": "fld_43a721aaeef04e1386732d41c31a778a", + "modified": 1714948186876, + "created": 1714941788001, + "url": "{{ _.url }}/supply-categories", + "name": "Create", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"name\": \"Roupas\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": { "type": "bearer", "token": "{{ _.token }}" }, + "metaSortKey": -1714938160009, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_71fea5194e9143a1adeccc1f9e751868", + "parentId": "fld_43a721aaeef04e1386732d41c31a778a", + "modified": 1714944576289, + "created": 1714941788004, + "url": "{{ _.url }}/supply-categories/8b684946-89b7-4741-81e5-cb679d94fae7", + "name": "Update", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"name\": \"Roupas\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": { "type": "bearer", "token": "{{ _.token }}" }, + "metaSortKey": -1714937887830.75, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_e540a2a47e854964a90c85c954e3a5fa", + "parentId": "fld_2b4a4b05308748559e1abe82ec94d62c", + "modified": 1714963807376, + "created": 1714941690618, + "url": "{{ _.url }}/supplies", + "name": "Create", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"shelterId\": \"{{ _.shelterId }}\",\n\t\"supplyCategoryId\": \"236d72c4-66d1-4a06-8749-625dc16dc11a\",\n\t\"name\": \"Absorvente\",\n\t\"priority\": 0\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714938160009, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_2b4a4b05308748559e1abe82ec94d62c", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714941690616, + "created": 1714941690616, + "name": "Supplies", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714465011597.5, + "_type": "request_group" + }, + { + "_id": "req_b0641cadd0604de7961042b83c84199d", + "parentId": "fld_2b4a4b05308748559e1abe82ec94d62c", + "modified": 1714963287737, + "created": 1714941690622, + "url": "{{ _.url }}/supplies/867584d6-f7b6-45c8-9f68-98190639a324", + "name": "Update", + "description": "", + "method": "PUT", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"priority\": 10\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": {}, + "metaSortKey": -1714937887830.75, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_e6d2ab40315f4b40b1d7e5dc21bff09b", + "parentId": "fld_2b4a4b05308748559e1abe82ec94d62c", + "modified": 1714948340128, + "created": 1714941690620, + "url": "{{ _.url }}/supplies/{{ _.shelterId }}", + "name": "Index", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_ed301dbad729421a819cf291a5476e0d", + "name": "search", + "value": "pix:contains:abrigo", + "description": "", + "disabled": true + }, + { + "id": "pair_ff5b87c85c9f43cf8d949b7dcce34b8a", + "name": "perPage", + "value": "1", + "description": "", + "disabled": true + }, + { + "id": "pair_f1811cb5e0d74429b94592ec3695aa46", + "name": "page", + "value": "2", + "description": "", + "disabled": true + } + ], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": {}, + "metaSortKey": -1714937615652.5, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "req_b02963992a3546868c226e54c25e3499", + "parentId": "fld_c7f5b02294b44b20bce3de13b7f14710", + "modified": 1715026104841, + "created": 1715025970336, + "url": "{{ _.url }}/shelter/managers", + "name": "Create", + "description": "", + "method": "POST", + "body": { + "mimeType": "application/json", + "text": "{\n\t\"shelterId\": \"{{ _.shelterId }}\",\n\t\"userId\": \"7f71d975-03d1-4a7d-859e-cf5f03845473\"\n}" + }, + "parameters": [], + "headers": [ + { "name": "Content-Type", "value": "application/json" }, + { "name": "User-Agent", "value": "insomnia/2023.5.8" } + ], + "authentication": { "type": "bearer", "token": "{{ _.token }}" }, + "metaSortKey": -1714938160009, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "fld_c7f5b02294b44b20bce3de13b7f14710", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1715025970334, + "created": 1715025970334, + "name": "Shelter Manager", + "description": "", + "environment": {}, + "environmentPropertyOrder": null, + "metaSortKey": -1714228988320.25, + "_type": "request_group" + }, + { + "_id": "req_15404a5b37ea4872ac0bef869246a0e8", + "parentId": "fld_c7f5b02294b44b20bce3de13b7f14710", + "modified": 1715026350701, + "created": 1715025970338, + "url": "{{ _.url }}/shelter/managers/{{ _.shelterId }}", + "name": "Index", + "description": "", + "method": "GET", + "body": {}, + "parameters": [ + { + "id": "pair_6463a0ccc83742c99202284e920784cb", + "name": "includes", + "value": "user", + "description": "", + "disabled": true + } + ], + "headers": [{ "name": "User-Agent", "value": "insomnia/2023.5.8" }], + "authentication": {}, + "metaSortKey": -1714937615652.5, + "isPrivate": false, + "settingStoreCookies": true, + "settingSendCookies": true, + "settingDisableRenderRequestBody": false, + "settingEncodeUrl": true, + "settingRebuildPath": true, + "settingFollowRedirects": "global", + "_type": "request" + }, + { + "_id": "env_3f99728f85808417b4aa32432285d40a45688cee", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1715126560949, + "created": 1714933336431, + "name": "Base Environment", + "data": { + "baseURL": "http://localhost:4000", + "externalURL": "https://api.sos-rs.com", + "url": "{{ _.baseURL }}", + "password": "12345678", + "shelterId": "01d7c6e8-f040-486e-bb26-968ec4e8c717", + "token": "" + }, + "dataPropertyOrder": { + "&": ["baseURL", "externalURL", "url", "password", "shelterId", "token"] + }, + "color": null, + "isPrivate": false, + "metaSortKey": 1714933336431, + "_type": "environment" + }, + { + "_id": "jar_3f99728f85808417b4aa32432285d40a45688cee", + "parentId": "wrk_a61684b639de4828aadbeb27d5fb06c2", + "modified": 1714933336431, + "created": 1714933336431, + "name": "Default Jar", + "cookies": [], + "_type": "cookie_jar" + } + ] +} diff --git a/prisma/dev_dump.sql b/prisma/dev_dump.sql index 211625a8..83b66b3b 100644 --- a/prisma/dev_dump.sql +++ b/prisma/dev_dump.sql @@ -93,7 +93,7 @@ INSERT INTO public.partners VALUES ('33fc6b9c-e9dd-446d-b0a1-f66dd8a45cda', 'Pai -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: doadmin -- -INSERT INTO public.users VALUES ('e0306bc0-8c29-429a-bbd2-384f48d4f993', 'Dinho', '31996675945', '$2b$10$V4hFTbT7MrskROc4TI2lNe6gAd0g7U1niziAPycFueLhPJRFIfoGm', '31996675945', '2024-05-05T22:04:59.468Z', '2024-05-09T17:56:55.037Z', 'Admin', 'Duarte'); +INSERT INTO public.users VALUES ('e0306bc0-8c29-429a-bbd2-384f48d4f993', 'Administrador', '31999999999', '$2b$10$V4hFTbT7MrskROc4TI2lNe6gAd0g7U1niziAPycFueLhPJRFIfoGm', '31999999999', '2024-05-05T22:04:59.468Z', '2024-05-09T17:56:55.037Z', 'Admin', 'Web'); INSERT INTO public.users VALUES ('e82f476a-1574-4dd2-a4c4-1c1f0117db12', 'Rhuam', '51992047974', '$2b$10$V4hFTbT7MrskROc4TI2lNe6gAd0g7U1niziAPycFueLhPJRFIfoGm', '51992047974', '2024-05-05T22:06:11.390Z', '2024-05-16T18:52:36.650Z', 'Admin', 'Estevam'); diff --git a/prisma/migrations/20240528182902_/migration.sql b/prisma/migrations/20240528182902_/migration.sql new file mode 100644 index 00000000..6d13c04d --- /dev/null +++ b/prisma/migrations/20240528182902_/migration.sql @@ -0,0 +1,44 @@ +-- CreateEnum +CREATE TYPE "SupplyMeasure" AS ENUM ('Unit', 'Kg', 'Litters', 'Box', 'Piece'); + +-- CreateEnum +CREATE TYPE "DonationOrderStatus" AS ENUM ('Pending', 'Canceled', 'Complete'); + +-- AlterTable +ALTER TABLE "supplies" ADD COLUMN "measure" "SupplyMeasure" NOT NULL DEFAULT 'Unit'; + +-- CreateTable +CREATE TABLE "donation_order_supplies" ( + "id" TEXT NOT NULL, + "donation_order_id" TEXT NOT NULL, + "supply_id" TEXT NOT NULL, + "quantity" INTEGER NOT NULL, + "created_at" VARCHAR(32) NOT NULL, + "updated_at" VARCHAR(32), + + CONSTRAINT "donation_order_supplies_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "donation_orders" ( + "id" TEXT NOT NULL, + "user_id" TEXT NOT NULL, + "shelter_id" TEXT NOT NULL, + "status" "DonationOrderStatus" NOT NULL DEFAULT 'Pending', + "created_at" VARCHAR(32) NOT NULL, + "updated_at" VARCHAR(32), + + CONSTRAINT "donation_orders_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "donation_order_supplies" ADD CONSTRAINT "donation_order_supplies_supply_id_fkey" FOREIGN KEY ("supply_id") REFERENCES "supplies"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "donation_order_supplies" ADD CONSTRAINT "donation_order_supplies_donation_order_id_fkey" FOREIGN KEY ("donation_order_id") REFERENCES "donation_orders"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "donation_orders" ADD CONSTRAINT "donation_orders_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "donation_orders" ADD CONSTRAINT "donation_orders_shelter_id_fkey" FOREIGN KEY ("shelter_id") REFERENCES "shelters"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 69d25067..57447c75 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -19,6 +19,20 @@ enum ShelterCategory { DistributionCenter } +enum SupplyMeasure { + Unit + Kg + Litters + Box + Piece +} + +enum DonationOrderStatus { + Pending + Canceled + Complete +} + model User { id String @id @default(uuid()) name String @@ -33,6 +47,7 @@ model User { sessions Session[] shelterManagers ShelterManagers[] suppliesHistory SupplyHistory[] + donationOrders DonationOrder[] @@map("users") } @@ -78,15 +93,17 @@ model ShelterSupply { } model Supply { - id String @id @default(uuid()) - supplyCategoryId String @map("supply_category_id") + id String @id @default(uuid()) + supplyCategoryId String @map("supply_category_id") name String - createdAt String @map("created_at") @db.VarChar(32) - updatedAt String? @map("updated_at") @db.VarChar(32) + measure SupplyMeasure @default(value: Unit) + createdAt String @map("created_at") @db.VarChar(32) + updatedAt String? @map("updated_at") @db.VarChar(32) - supplyCategory SupplyCategory @relation(fields: [supplyCategoryId], references: [id]) - shelterSupplies ShelterSupply[] - supplyHistories SupplyHistory[] + supplyCategory SupplyCategory @relation(fields: [supplyCategoryId], references: [id]) + shelterSupplies ShelterSupply[] + supplyHistories SupplyHistory[] + DonationOrderSupply DonationOrderSupply[] @@map("supplies") } @@ -117,6 +134,7 @@ model Shelter { shelterManagers ShelterManagers[] shelterSupplies ShelterSupply[] supplyHistories SupplyHistory[] + DonationOrder DonationOrder[] @@map("shelters") } @@ -175,3 +193,32 @@ model SupplyHistory { @@map("supplies_history") } + +model DonationOrderSupply { + id String @id @default(uuid()) + donationOrderId String @map("donation_order_id") + supplyId String @map("supply_id") + quantity Int + createdAt String @map("created_at") @db.VarChar(32) + updatedAt String? @map("updated_at") @db.VarChar(32) + + supply Supply @relation(fields: [supplyId], references: [id]) + donationOrder DonationOrder @relation(fields: [donationOrderId], references: [id]) + + @@map("donation_order_supplies") +} + +model DonationOrder { + id String @id @default(uuid()) + userId String @map("user_id") + shelterId String @map("shelter_id") + status DonationOrderStatus @default(value: Pending) + createdAt String @map("created_at") @db.VarChar(32) + updatedAt String? @map("updated_at") @db.VarChar(32) + + user User @relation(fields: [userId], references: [id]) + shelter Shelter @relation(fields: [shelterId], references: [id]) + donationOrderSupplies DonationOrderSupply[] + + @@map("donation_orders") +} diff --git a/src/app.module.ts b/src/app.module.ts index 3f814215..5f953f1a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -12,9 +12,10 @@ import { SupplyCategoriesModule } from './supply-categories/supply-categories.mo import { ShelterManagersModule } from './shelter-managers/shelter-managers.module'; import { ShelterSupplyModule } from './shelter-supply/shelter-supply.module'; import { PartnersModule } from './partners/partners.module'; -import { DashboardModule } from './modules/dashboard/dashboard.module'; +import { DashboardModule } from './dashboard/dashboard.module'; import { SupportersModule } from './supporters/supporters.module'; import { SuppliesHistoryModule } from './supplies-history/supplies-history.module'; +import { DonationOrderModule } from './donation-order/donation-order.module'; @Module({ imports: [ @@ -30,6 +31,7 @@ import { SuppliesHistoryModule } from './supplies-history/supplies-history.modul DashboardModule, SupportersModule, SuppliesHistoryModule, + DonationOrderModule, ], controllers: [], providers: [ diff --git a/src/modules/dashboard/dashboard.controller.spec.ts b/src/dashboard/dashboard.controller.spec.ts similarity index 67% rename from src/modules/dashboard/dashboard.controller.spec.ts rename to src/dashboard/dashboard.controller.spec.ts index 9ae8da71..312a8e2a 100644 --- a/src/modules/dashboard/dashboard.controller.spec.ts +++ b/src/dashboard/dashboard.controller.spec.ts @@ -1,15 +1,25 @@ import { Test, TestingModule } from '@nestjs/testing'; + import { DashboardController } from './dashboard.controller'; import { DashboardService } from './dashboard.service'; +import { PrismaService } from '../../prisma/prisma.service'; +import { PrismaModule } from '../../prisma/prisma.module'; describe('DashboardController', () => { let controller: DashboardController; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], controllers: [DashboardController], providers: [DashboardService], - }).compile(); + }) + .useMocker((token) => { + if (token === PrismaService) { + return {}; + } + }) + .compile(); controller = module.get(DashboardController); }); diff --git a/src/modules/dashboard/dashboard.controller.ts b/src/dashboard/dashboard.controller.ts similarity index 100% rename from src/modules/dashboard/dashboard.controller.ts rename to src/dashboard/dashboard.controller.ts diff --git a/src/modules/dashboard/dashboard.module.ts b/src/dashboard/dashboard.module.ts similarity index 100% rename from src/modules/dashboard/dashboard.module.ts rename to src/dashboard/dashboard.module.ts diff --git a/src/modules/dashboard/dashboard.service.spec.ts b/src/dashboard/dashboard.service.spec.ts similarity index 61% rename from src/modules/dashboard/dashboard.service.spec.ts rename to src/dashboard/dashboard.service.spec.ts index dc3993ae..d02863a9 100644 --- a/src/modules/dashboard/dashboard.service.spec.ts +++ b/src/dashboard/dashboard.service.spec.ts @@ -1,13 +1,23 @@ import { Test, TestingModule } from '@nestjs/testing'; + import { DashboardService } from './dashboard.service'; +import { PrismaService } from '../../prisma/prisma.service'; +import { PrismaModule } from '../../prisma/prisma.module'; describe('DashboardService', () => { let service: DashboardService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], providers: [DashboardService], - }).compile(); + }) + .useMocker((token) => { + if (token === PrismaService) { + return {}; + } + }) + .compile(); service = module.get(DashboardService); }); diff --git a/src/modules/dashboard/dashboard.service.ts b/src/dashboard/dashboard.service.ts similarity index 73% rename from src/modules/dashboard/dashboard.service.ts rename to src/dashboard/dashboard.service.ts index 22952e26..25d29883 100644 --- a/src/modules/dashboard/dashboard.service.ts +++ b/src/dashboard/dashboard.service.ts @@ -46,6 +46,7 @@ export class DashboardService { priority: true, supply: { select: { + measure: true, supplyCategory: { select: { name: true, @@ -58,34 +59,35 @@ export class DashboardService { }, }); - const categoriesWithPriorities = await this.prismaService.supplyCategory.findMany({ - select: { - id: true, - name: true, - supplies: { - select: { - shelterSupplies: { - select: { - priority: true, - shelterId: true - } - } - } - } - } - }); - - const result = categoriesWithPriorities.map(category => { + const categoriesWithPriorities = + await this.prismaService.supplyCategory.findMany({ + select: { + id: true, + name: true, + supplies: { + select: { + shelterSupplies: { + select: { + priority: true, + shelterId: true, + }, + }, + }, + }, + }, + }); + + const result = categoriesWithPriorities.map((category) => { const priorityCounts = { priority100: 0, priority10: 0, priority1: 0, }; - + const countedShelters = new Set(); - - category.supplies.forEach(supply => { - supply.shelterSupplies.forEach(shelterSupply => { + + category.supplies.forEach((supply) => { + supply.shelterSupplies.forEach((shelterSupply) => { if (!countedShelters.has(shelterSupply.shelterId)) { switch (shelterSupply.priority) { case 100: @@ -124,30 +126,40 @@ export class DashboardService { } }, 0); - const numSheltersAvailable = allShelters.filter(shelter => { - if (shelter.actived && shelter.capacity !== null && shelter.capacity > 0) { - return (shelter.shelteredPeople ?? 0) < shelter.capacity; + const numSheltersAvailable = allShelters.filter((shelter) => { + if ( + shelter.actived && + shelter.capacity !== null && + shelter.capacity > 0 + ) { + return (shelter.shelteredPeople ?? 0) < shelter.capacity; } - return false; - }).length; + return false; + }).length; const numSheltersFull = allShelters.reduce((count, shelter) => { - if (shelter.actived && shelter.capacity !== null && shelter.capacity > 0) { - if ((shelter.shelteredPeople ?? 0) >= shelter.capacity) { - return count + 1; - } + if ( + shelter.actived && + shelter.capacity !== null && + shelter.capacity > 0 + ) { + if ((shelter.shelteredPeople ?? 0) >= shelter.capacity) { + return count + 1; + } } return count; }, 0); const shelterWithoutInformation = allShelters.reduce((count, shelter) => { - if (shelter.shelteredPeople === null || shelter.shelteredPeople === undefined) { - return count + 1; + if ( + shelter.shelteredPeople === null || + shelter.shelteredPeople === undefined + ) { + return count + 1; } return count; }, 0); - - + return { allShelters: allShelters.length, allPeopleSheltered: allPeopleSheltered, diff --git a/src/donation-order/donation-order.controller.spec.ts b/src/donation-order/donation-order.controller.spec.ts new file mode 100644 index 00000000..9f734f1f --- /dev/null +++ b/src/donation-order/donation-order.controller.spec.ts @@ -0,0 +1,30 @@ +import { Test, TestingModule } from '@nestjs/testing'; + +import { DonationOrderController } from './donation-order.controller'; +import { PrismaService } from '../prisma/prisma.service'; +import { PrismaModule } from '../prisma/prisma.module'; +import { DonationOrderService } from './donation-order.service'; + +describe('DonationOrderController', () => { + let controller: DonationOrderController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [DonationOrderService], + controllers: [DonationOrderController], + }) + .useMocker((token) => { + if (token === PrismaService) { + return {}; + } + }) + .compile(); + + controller = module.get(DonationOrderController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/donation-order/donation-order.controller.ts b/src/donation-order/donation-order.controller.ts new file mode 100644 index 00000000..52997ecc --- /dev/null +++ b/src/donation-order/donation-order.controller.ts @@ -0,0 +1,82 @@ +import { + Body, + Controller, + Get, + HttpException, + Logger, + Param, + Post, + Put, + Query, + Request, + UseGuards, +} from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; + +import { DonationOrderService } from './donation-order.service'; +import { ServerResponse } from '../utils'; +import { UserGuard } from '@/guards/user.guard'; + +@ApiTags('Doações') +@Controller('donation/order') +export class DonationOrderController { + private logger = new Logger(DonationOrderController.name); + + constructor(private readonly donationOrderService: DonationOrderService) {} + + @Post('') + @UseGuards(UserGuard) + async store(@Body() body, @Request() req) { + try { + const { userId } = req.user; + const data = await this.donationOrderService.store({ ...body, userId }); + return new ServerResponse(200, 'Successfully store donation order', data); + } catch (err: any) { + this.logger.error(`Failed to store donation order: ${err}`); + throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); + } + } + + @Put(':orderId') + @UseGuards(UserGuard) + async update(@Param('orderId') orderId: string, @Body() body) { + try { + await this.donationOrderService.update(orderId, body); + return new ServerResponse(200, 'Successfully updated donation order'); + } catch (err: any) { + this.logger.error(`Failed to update donation order: ${err}`); + throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); + } + } + + @Get('') + @UseGuards(UserGuard) + async index(@Query() query, @Request() req) { + try { + const { userId } = req.user; + const data = await this.donationOrderService.index(userId, query); + return new ServerResponse( + 200, + 'Successfully get all donation orders', + data, + ); + } catch (err: any) { + this.logger.error(`Failed to get all donation orders: ${err}`); + throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); + } + } + + @Get(':id') + @UseGuards(UserGuard) + async show(@Param('id') id: string, @Request() req) { + try { + const { userId } = req.user; + const data = await this.donationOrderService.show(id, userId); + if (!data) throw new HttpException('Not founded donation order', 404); + return new ServerResponse(200, 'Successfully get donation order', data); + } catch (err: any) { + this.logger.error(`Failed to get donation order: ${err}`); + throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); + } + } +} diff --git a/src/donation-order/donation-order.module.ts b/src/donation-order/donation-order.module.ts new file mode 100644 index 00000000..cf1191b0 --- /dev/null +++ b/src/donation-order/donation-order.module.ts @@ -0,0 +1,12 @@ +import { Module } from '@nestjs/common'; + +import { DonationOrderService } from './donation-order.service'; +import { DonationOrderController } from './donation-order.controller'; +import { PrismaModule } from '../prisma/prisma.module'; + +@Module({ + imports: [PrismaModule], + providers: [DonationOrderService], + controllers: [DonationOrderController], +}) +export class DonationOrderModule {} diff --git a/src/donation-order/donation-order.service.spec.ts b/src/donation-order/donation-order.service.spec.ts new file mode 100644 index 00000000..aa1e49f7 --- /dev/null +++ b/src/donation-order/donation-order.service.spec.ts @@ -0,0 +1,28 @@ +import { Test, TestingModule } from '@nestjs/testing'; + +import { DonationOrderService } from './donation-order.service'; +import { PrismaService } from '../prisma/prisma.service'; +import { PrismaModule } from '../prisma/prisma.module'; + +describe('DonationOrderService', () => { + let service: DonationOrderService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [DonationOrderService], + }) + .useMocker((token) => { + if (token === PrismaService) { + return {}; + } + }) + .compile(); + + service = module.get(DonationOrderService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/donation-order/donation-order.service.ts b/src/donation-order/donation-order.service.ts new file mode 100644 index 00000000..6bcb11d1 --- /dev/null +++ b/src/donation-order/donation-order.service.ts @@ -0,0 +1,143 @@ +import { z } from 'zod'; +import { Injectable } from '@nestjs/common'; +import { Prisma } from '@prisma/client'; +import { DefaultArgs } from '@prisma/client/runtime/library'; + +import { PrismaService } from '../prisma/prisma.service'; +import { CreateDonationOrderScheme, UpdateDonationOrderScheme } from './types'; +import { SearchSchema } from '../types'; + +@Injectable() +export class DonationOrderService { + constructor(private readonly prismaService: PrismaService) {} + + async index(userId: string, query: any) { + const { shelterId } = query; + const { order, orderBy, page, perPage } = SearchSchema.parse(query); + + const where: Prisma.DonationOrderWhereInput = { + shelterId, + userId, + }; + + const count = await this.prismaService.donationOrder.count({ where }); + + const take = perPage; + const skip = perPage * (page - 1); + + const whereData: Prisma.DonationOrderFindManyArgs = { + take, + skip, + orderBy: { [orderBy]: order }, + where, + }; + + const results = await this.prismaService.donationOrder.findMany({ + ...whereData, + select: { + id: true, + status: true, + userId: true, + shelter: { + select: { + id: true, + name: true, + }, + }, + donationOrderSupplies: { + select: { + quantity: true, + supply: { + select: { + name: true, + measure: true, + }, + }, + }, + }, + createdAt: true, + updatedAt: true, + }, + orderBy: { + createdAt: 'desc', + }, + }); + + return { + page, + perPage, + count, + results, + }; + } + + async show(id: string, userId: string) { + const data = await this.prismaService.donationOrder.findUnique({ + where: { id, userId }, + select: { + id: true, + status: true, + userId: true, + shelter: { + select: { + id: true, + name: true, + }, + }, + donationOrderSupplies: { + select: { + quantity: true, + supply: { + select: { + name: true, + measure: true, + }, + }, + }, + }, + createdAt: true, + updatedAt: true, + }, + }); + return data; + } + + async store(body: z.infer) { + const { supplies, shelterId, userId } = + CreateDonationOrderScheme.parse(body); + const donation = await this.prismaService.donationOrder.create({ + data: { + shelterId, + userId, + createdAt: new Date().toISOString(), + donationOrderSupplies: { + createMany: { + data: supplies.map((s) => ({ + supplyId: s.id, + quantity: s.quantity, + createdAt: new Date().toISOString(), + })), + }, + }, + }, + }); + + return donation; + } + + async update( + orderId: string, + body: z.infer, + ) { + const { status } = UpdateDonationOrderScheme.parse(body); + await this.prismaService.donationOrder.update({ + where: { + id: orderId, + }, + data: { + status, + updatedAt: new Date().toISOString(), + }, + }); + } +} diff --git a/src/donation-order/types.ts b/src/donation-order/types.ts new file mode 100644 index 00000000..f0c524c0 --- /dev/null +++ b/src/donation-order/types.ts @@ -0,0 +1,39 @@ +import { DonationOrderStatus } from '@prisma/client'; +import z from 'zod'; + +const DonationOrderScheme = z.object({ + id: z.string(), + userId: z.string(), + shelterId: z.string(), + status: z.enum([ + DonationOrderStatus.Canceled, + DonationOrderStatus.Complete, + DonationOrderStatus.Pending, + ]), + createdAt: z.string(), + updatedAt: z.string().nullish(), +}); + +const CreateDonationOrderScheme = DonationOrderScheme.omit({ + id: true, + status: true, + createdAt: true, + updatedAt: true, +}).extend({ + supplies: z.array( + z.object({ + id: z.string(), + quantity: z.number().min(1), + }), + ), +}); + +const UpdateDonationOrderScheme = DonationOrderScheme.pick({ + status: true, +}); + +export { + DonationOrderScheme, + CreateDonationOrderScheme, + UpdateDonationOrderScheme, +}; diff --git a/src/interceptors/interceptors/shelter-supply-history/utils.ts b/src/interceptors/interceptors/shelter-supply-history/utils.ts index 46119734..2bcfee53 100644 --- a/src/interceptors/interceptors/shelter-supply-history/utils.ts +++ b/src/interceptors/interceptors/shelter-supply-history/utils.ts @@ -4,14 +4,12 @@ import { Logger } from '@nestjs/common'; import { CreateShelterSupplySchema, - UpdateManyShelterSupplySchema, UpdateShelterSupplySchema, } from '../../../shelter-supply/types'; import { PrismaService } from '../../../prisma/prisma.service'; import { CreateSupplyHistorySchema } from '../../../supplies-history/types'; -import { SupplyPriority } from '../../../supply/types'; import { ShelterSupplyHistoryAction, UserIdentity } from './types'; -import { getSessionData } from '@/utils/utils'; +import { getSessionData } from '@/utils'; function registerSupplyLog( body: z.infer, @@ -80,25 +78,6 @@ function registerUpdateSupplyLog( ); } -function registerUpdateManySupplyLog( - body: z.infer, - user: UserIdentity, -) { - const { ids, shelterId } = UpdateManyShelterSupplySchema.parse(body); - - ids.forEach((id) => - registerSupplyLog( - { - shelterId, - supplyId: id, - priority: SupplyPriority.UnderControl, - quantity: 0, - }, - user, - ), - ); -} - function handler( prismaService: PrismaService, action: ShelterSupplyHistoryAction, @@ -129,15 +108,6 @@ function handler( user, ); break; - case ShelterSupplyHistoryAction.UpdateMany: - registerUpdateManySupplyLog( - { - shelterId: (request.params as any).shelterId, - ids: (request.body as any).ids, - }, - user, - ); - break; } } diff --git a/src/shelter-supply/shelter-supply.controller.ts b/src/shelter-supply/shelter-supply.controller.ts index d052579f..226d0796 100644 --- a/src/shelter-supply/shelter-supply.controller.ts +++ b/src/shelter-supply/shelter-supply.controller.ts @@ -7,13 +7,11 @@ import { Param, Post, Put, - UseGuards, } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { ShelterSupplyService } from './shelter-supply.service'; import { ServerResponse } from '../utils'; -import { DistributionCenterGuard } from '@/guards/distribution-center.guard'; import { RegisterShelterSupplyHistory } from '@/decorators/RegisterShelterSupplyHistory'; import { ShelterSupplyHistoryAction } from '@/interceptors/interceptors/shelter-supply-history/types'; @@ -73,24 +71,4 @@ export class ShelterSupplyController { throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); } } - - @Put(':shelterId/supplies/many') - @UseGuards(DistributionCenterGuard) - @RegisterShelterSupplyHistory(ShelterSupplyHistoryAction.UpdateMany) - async updateMany(@Body() body, @Param('shelterId') shelterId: string) { - try { - const data = await this.shelterSupplyService.updateMany({ - shelterId, - ...body, - }); - return new ServerResponse( - 200, - 'Successfully updated many shelter supplies', - data, - ); - } catch (err: any) { - this.logger.error(`Failed to update many shelter supplies: ${err}`); - throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); - } - } } diff --git a/src/shelter-supply/shelter-supply.service.ts b/src/shelter-supply/shelter-supply.service.ts index ef4cf97a..5c9b2a77 100644 --- a/src/shelter-supply/shelter-supply.service.ts +++ b/src/shelter-supply/shelter-supply.service.ts @@ -2,11 +2,7 @@ import { z } from 'zod'; import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; -import { - CreateShelterSupplySchema, - UpdateManyShelterSupplySchema, - UpdateShelterSupplySchema, -} from './types'; +import { CreateShelterSupplySchema, UpdateShelterSupplySchema } from './types'; import { SupplyPriority } from '../supply/types'; @Injectable() @@ -79,50 +75,6 @@ export class ShelterSupplyService { }); } - async updateMany(body: z.infer) { - const { ids, shelterId } = UpdateManyShelterSupplySchema.parse(body); - - const supplies = await this.prismaService.shelterSupply.findMany({ - where: { - shelterId, - supplyId: { - in: ids, - }, - }, - }); - - const prioritySum = supplies.reduce( - (prev, current) => prev + current.priority, - 0, - ); - - await this.prismaService.$transaction([ - this.prismaService.shelter.update({ - where: { - id: shelterId, - }, - data: { - prioritySum: { - decrement: prioritySum, - }, - updatedAt: new Date().toISOString(), - }, - }), - this.prismaService.shelterSupply.updateMany({ - where: { - shelterId, - supplyId: { - in: ids, - }, - }, - data: { - priority: SupplyPriority.UnderControl, - updatedAt: new Date().toISOString(), - }, - }), - ]); - } - async index(shelterId: string) { return await this.prismaService.shelterSupply.findMany({ where: { @@ -135,6 +87,7 @@ export class ShelterSupplyService { select: { id: true, name: true, + measure: true, supplyCategory: { select: { id: true, diff --git a/src/shelter-supply/types.ts b/src/shelter-supply/types.ts index f683bf68..0de6cc72 100644 --- a/src/shelter-supply/types.ts +++ b/src/shelter-supply/types.ts @@ -44,14 +44,8 @@ const UpdateShelterSupplySchema = z.object({ }), }); -const UpdateManyShelterSupplySchema = z.object({ - ids: z.array(z.string()), - shelterId: z.string(), -}); - export { ShelterSupplySchema, CreateShelterSupplySchema, UpdateShelterSupplySchema, - UpdateManyShelterSupplySchema, }; diff --git a/src/shelter/shelter.service.ts b/src/shelter/shelter.service.ts index 058db35f..757acdba 100644 --- a/src/shelter/shelter.service.ts +++ b/src/shelter/shelter.service.ts @@ -104,7 +104,7 @@ export class ShelterService implements OnModuleInit { select: { id: true, name: true, - + measure: true, supplyCategory: { select: { id: true, diff --git a/src/supplies-history/supplies-history.service.ts b/src/supplies-history/supplies-history.service.ts index 3505ebf9..4bfd0a02 100644 --- a/src/supplies-history/supplies-history.service.ts +++ b/src/supplies-history/supplies-history.service.ts @@ -36,6 +36,7 @@ export class SuppliesHistoryService { id: true, supply: { select: { + measure: true, name: true, }, }, diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 18baf4b6..586290e1 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -1,6 +1,7 @@ import { Body, Controller, + Get, HttpException, Logger, Param, @@ -24,7 +25,6 @@ export class UsersController { constructor(private readonly userServices: UsersService) {} @Post('') - @UseGuards(AdminGuard) @ApiBearerAuth() @ApiOperation({ summary: 'Cria um novo usuário', @@ -43,9 +43,9 @@ export class UsersController { examples: { 'Exemplo 1': { value: { - name: 'Dinho', - lastName: 'Duarte', - phone: '(31) 996675945', + name: 'Administrador', + lastName: 'Web', + phone: '(31) 999999999', }, }, }, @@ -83,10 +83,10 @@ export class UsersController { examples: { 'Exemplo 1': { value: { - name: 'Dinho', - lastName: 'Duarte', - phone: '(31) 996675945', - login: 'dinho duarte', + name: 'Administrador', + lastName: 'Web', + phone: '(31) 999999999', + login: 'admin', password: '123456', }, }, @@ -125,11 +125,11 @@ export class UsersController { examples: { 'Exemplo 1': { value: { - name: 'Dinho', - lastName: 'Duarte', - phone: '(31) 996675945', - login: 'dinho duarte', - password: '123456', + name: 'João', + lastName: 'Neves', + phone: '(11) 99999-9999', + login: 'joaodasneves', + password: '12345678', }, }, }, @@ -144,4 +144,19 @@ export class UsersController { throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); } } + + @Get('find/:field/:value') + async find(@Param('field') field: string, @Param('value') value: string) { + try { + const result = await this.userServices.checkIfUserExists({ + [field]: value, + }); + return new ServerResponse(201, 'Successfully searched user', { + exists: result, + }); + } catch (err: any) { + this.logger.error(`Failed to find user: ${err}`); + throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); + } + } } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 49e5df91..339b468a 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { CreateUserSchema, UpdateUserSchema } from './types'; +import { User } from '@prisma/client'; @Injectable() export class UsersService { @@ -33,4 +34,12 @@ export class UsersService { }, }); } + + async checkIfUserExists(payload: Partial): Promise { + const result = await this.prismaService.user.findFirst({ + where: payload, + }); + + return !!result; + } }