🐛 Fixing you already voted for this appointment

This commit is contained in:
Maxime Lalo 2023-07-27 13:20:13 +02:00
parent fffcd17944
commit 3b7b9288bc
4 changed files with 146 additions and 108 deletions

185
package-lock.json generated
View File

@ -19,7 +19,7 @@
"cron": "^2.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.57",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.66",
"module-alias": "^2.2.2",
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",
@ -1061,14 +1061,14 @@
}
},
"node_modules/@next/env": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.10.tgz",
"integrity": "sha512-3G1yD/XKTSLdihyDSa8JEsaWOELY+OWe08o0LUYzfuHp1zHDA8SObQlzKt+v+wrkkPcnPweoLH1ImZeUa0A1NQ=="
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/env/-/env-13.4.12.tgz",
"integrity": "sha512-RmHanbV21saP/6OEPBJ7yJMuys68cIf8OBBWd7+uj40LdpmswVAwe1uzeuFyUsd6SfeITWT3XnQfn6wULeKwDQ=="
},
"node_modules/@next/swc-darwin-arm64": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.10.tgz",
"integrity": "sha512-4bsdfKmmg7mgFGph0UorD1xWfZ5jZEw4kKRHYEeTK9bT1QnMbPVPlVXQRIiFPrhoDQnZUoa6duuPUJIEGLV1Jg==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.12.tgz",
"integrity": "sha512-deUrbCXTMZ6ZhbOoloqecnUeNpUOupi8SE2tx4jPfNS9uyUR9zK4iXBvH65opVcA/9F5I/p8vDXSYbUlbmBjZg==",
"cpu": [
"arm64"
],
@ -1081,9 +1081,9 @@
}
},
"node_modules/@next/swc-darwin-x64": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.10.tgz",
"integrity": "sha512-ngXhUBbcZIWZWqNbQSNxQrB9T1V+wgfCzAor2olYuo/YpaL6mUYNUEgeBMhr8qwV0ARSgKaOp35lRvB7EmCRBg==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.12.tgz",
"integrity": "sha512-WRvH7RxgRHlC1yb5oG0ZLx8F7uci9AivM5/HGGv9ZyG2Als8Ij64GC3d+mQ5sJhWjusyU6T6V1WKTUoTmOB0zQ==",
"cpu": [
"x64"
],
@ -1096,9 +1096,9 @@
}
},
"node_modules/@next/swc-linux-arm64-gnu": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.10.tgz",
"integrity": "sha512-SjCZZCOmHD4uyM75MVArSAmF5Y+IJSGroPRj2v9/jnBT36SYFTORN8Ag/lhw81W9EeexKY/CUg2e9mdebZOwsg==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.12.tgz",
"integrity": "sha512-YEKracAWuxp54tKiAvvq73PUs9lok57cc8meYRibTWe/VdPB2vLgkTVWFcw31YDuRXdEhdX0fWS6Q+ESBhnEig==",
"cpu": [
"arm64"
],
@ -1111,9 +1111,9 @@
}
},
"node_modules/@next/swc-linux-arm64-musl": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.10.tgz",
"integrity": "sha512-F+VlcWijX5qteoYIOxNiBbNE8ruaWuRlcYyIRK10CugqI/BIeCDzEDyrHIHY8AWwbkTwe6GRHabMdE688Rqq4Q==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.12.tgz",
"integrity": "sha512-LhJR7/RAjdHJ2Isl2pgc/JaoxNk0KtBgkVpiDJPVExVWA1c6gzY57+3zWuxuyWzTG+fhLZo2Y80pLXgIJv7g3g==",
"cpu": [
"arm64"
],
@ -1126,9 +1126,9 @@
}
},
"node_modules/@next/swc-linux-x64-gnu": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.10.tgz",
"integrity": "sha512-WDv1YtAV07nhfy3i1visr5p/tjiH6CeXp4wX78lzP1jI07t4PnHHG1WEDFOduXh3WT4hG6yN82EQBQHDi7hBrQ==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.12.tgz",
"integrity": "sha512-1DWLL/B9nBNiQRng+1aqs3OaZcxC16Nf+mOnpcrZZSdyKHek3WQh6j/fkbukObgNGwmCoVevLUa/p3UFTTqgqg==",
"cpu": [
"x64"
],
@ -1141,9 +1141,9 @@
}
},
"node_modules/@next/swc-linux-x64-musl": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.10.tgz",
"integrity": "sha512-zFkzqc737xr6qoBgDa3AwC7jPQzGLjDlkNmt/ljvQJ/Veri5ECdHjZCUuiTUfVjshNIIpki6FuP0RaQYK9iCRg==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.12.tgz",
"integrity": "sha512-kEAJmgYFhp0VL+eRWmUkVxLVunn7oL9Mdue/FS8yzRBVj7Z0AnIrHpTIeIUl1bbdQq1VaoOztnKicAjfkLTRCQ==",
"cpu": [
"x64"
],
@ -1156,9 +1156,9 @@
}
},
"node_modules/@next/swc-win32-arm64-msvc": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.10.tgz",
"integrity": "sha512-IboRS8IWz5mWfnjAdCekkl8s0B7ijpWeDwK2O8CdgZkoCDY0ZQHBSGiJ2KViAG6+BJVfLvcP+a2fh6cdyBr9QQ==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.12.tgz",
"integrity": "sha512-GMLuL/loR6yIIRTnPRY6UGbLL9MBdw2anxkOnANxvLvsml4F0HNIgvnU3Ej4BjbqMTNjD4hcPFdlEow4XHPdZA==",
"cpu": [
"arm64"
],
@ -1171,9 +1171,9 @@
}
},
"node_modules/@next/swc-win32-ia32-msvc": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.10.tgz",
"integrity": "sha512-bSA+4j8jY4EEiwD/M2bol4uVEu1lBlgsGdvM+mmBm/BbqofNBfaZ2qwSbwE2OwbAmzNdVJRFRXQZ0dkjopTRaQ==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.12.tgz",
"integrity": "sha512-PhgNqN2Vnkm7XaMdRmmX0ZSwZXQAtamBVSa9A/V1dfKQCV1rjIZeiy/dbBnVYGdj63ANfsOR/30XpxP71W0eww==",
"cpu": [
"ia32"
],
@ -1186,9 +1186,9 @@
}
},
"node_modules/@next/swc-win32-x64-msvc": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.10.tgz",
"integrity": "sha512-g2+tU63yTWmcVQKDGY0MV1PjjqgZtwM4rB1oVVi/v0brdZAcrcTV+04agKzWtvWroyFz6IqtT0MoZJA7PNyLVw==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.12.tgz",
"integrity": "sha512-Z+56e/Ljt0bUs+T+jPjhFyxYBcdY2RIq9ELFU+qAMQMteHo7ymbV7CKmlcX59RI9C4YzN8PgMgLyAoi916b5HA==",
"cpu": [
"x64"
],
@ -1493,9 +1493,9 @@
}
},
"node_modules/@types/node": {
"version": "18.17.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.0.tgz",
"integrity": "sha512-GXZxEtOxYGFchyUzxvKI14iff9KZ2DI+A6a37o6EQevtg6uO9t+aUZKcaC1Te5Ng1OnLM7K9NVVj+FbecD9cJg=="
"version": "18.17.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.1.tgz",
"integrity": "sha512-xlR1jahfizdplZYRU59JlUx9uzF1ARa8jbhM11ccpCJya8kvos5jwdm2ZAgxSCwOl0fq21svP18EVwPBXMQudw=="
},
"node_modules/@types/node-fetch": {
"version": "2.6.4",
@ -2049,9 +2049,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001516",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001516.tgz",
"integrity": "sha512-Wmec9pCBY8CWbmI4HsjBeQLqDTqV91nFVR83DnZpYyRnPI1wePDsTg0bGLPC5VU/3OIZV1fmxEea1b+tFKe86g==",
"version": "1.0.30001517",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001517.tgz",
"integrity": "sha512-Vdhm5S11DaFVLlyiKu4hiUTkpZu+y1KA/rZZqVQfOD5YdDT/eQKlkt7NaE0WGOFgX32diqt9MiP9CAiFeRklaA==",
"funding": [
{
"type": "opencollective",
@ -2335,9 +2335,9 @@
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ=="
},
"node_modules/cron": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/cron/-/cron-2.3.1.tgz",
"integrity": "sha512-1eRRlIT0UfIqauwbG9pkg3J6CX9A6My2ytJWqAXoK0T9oJnUZTzGBNPxao0zjodIbPgf8UQWjE62BMb9eVllSQ==",
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/cron/-/cron-2.4.0.tgz",
"integrity": "sha512-Cx77ic1TyIAtUggr0oAhtS8MLzPBUqGNIvdDM7jE3oFIxfe8LXWI9q3iQN/H2CebAiMir53LQKWOhEKnzkJTAQ==",
"dependencies": {
"luxon": "^3.2.1"
}
@ -2467,9 +2467,9 @@
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
},
"node_modules/electron-to-chromium": {
"version": "1.4.461",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.461.tgz",
"integrity": "sha512-1JkvV2sgEGTDXjdsaQCeSwYYuhLRphRpc+g6EHTFELJXEiznLt3/0pZ9JuAOQ5p2rI3YxKTbivtvajirIfhrEQ==",
"version": "1.4.473",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.473.tgz",
"integrity": "sha512-aVfC8+440vGfl06l8HKKn8/PD5jRfSnLkTTD65EFvU46igbpQRri1gxSzW9/+TeUlwYzrXk1sw867T96zlyECA==",
"dev": true
},
"node_modules/emittery": {
@ -3193,17 +3193,17 @@
}
},
"node_modules/istanbul-lib-report": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz",
"integrity": "sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==",
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz",
"integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==",
"dev": true,
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"make-dir": "^3.0.0",
"make-dir": "^4.0.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=8"
"node": ">=10"
}
},
"node_modules/istanbul-lib-source-maps": {
@ -3244,9 +3244,9 @@
"dev": true
},
"node_modules/istanbul-reports": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.5.tgz",
"integrity": "sha512-nUsEMa9pBt/NOHqbcbeJEgqIlY/K7rVWUX6Lql2orY5e9roQOthbR3vtY4zzf2orPELg80fnxxk9zUyPlgwD1w==",
"version": "3.1.6",
"resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.6.tgz",
"integrity": "sha512-TLgnMkKg3iTDsQ9PbPTdpfAK2DzjF9mqUG7RMgcQl8oFjad8ob4laGxv5XV5U9MAfx8D6tSJiUyuAwzLicaxlg==",
"dev": true,
"dependencies": {
"html-escaper": "^2.0.0",
@ -3972,7 +3972,7 @@
}
},
"node_modules/le-coffre-resources": {
"resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#dffc2429ba6ceb4129deb56e308962799b9b572c",
"resolved": "git+ssh://git@github.com/smart-chain-fr/leCoffre-resources.git#e7916d516fe434c93ef13e765d8d63a7ce3c56b2",
"license": "MIT",
"dependencies": {
"class-transformer": "^0.5.1",
@ -3990,9 +3990,9 @@
}
},
"node_modules/libphonenumber-js": {
"version": "1.10.37",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.37.tgz",
"integrity": "sha512-Z10PCaOCiAxbUxLyR31DNeeNugSVP6iv/m7UrSKS5JHziEMApJtgku4e9Q69pzzSC9LnQiM09sqsGf2ticZnMw=="
"version": "1.10.38",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.38.tgz",
"integrity": "sha512-4NjVXVUmpZ9Zsqq6FXa2+MKI+KAI3tOqA0pxXgXGluhpj4ge5didmbWJpMBqGB3AVGv1SnEtKdGTbxjSEG1kCQ=="
},
"node_modules/lines-and-columns": {
"version": "1.2.4",
@ -4066,20 +4066,53 @@
}
},
"node_modules/make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
"integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",
"integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==",
"dev": true,
"dependencies": {
"semver": "^6.0.0"
"semver": "^7.5.3"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/make-dir/node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/make-dir/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/make-dir/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
},
"node_modules/make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
@ -4386,11 +4419,11 @@
}
},
"node_modules/next": {
"version": "13.4.10",
"resolved": "https://registry.npmjs.org/next/-/next-13.4.10.tgz",
"integrity": "sha512-4ep6aKxVTQ7rkUW2fBLhpBr/5oceCuf4KmlUpvG/aXuDTIf9mexNSpabUD6RWPspu6wiJJvozZREhXhueYO36A==",
"version": "13.4.12",
"resolved": "https://registry.npmjs.org/next/-/next-13.4.12.tgz",
"integrity": "sha512-eHfnru9x6NRmTMcjQp6Nz0J4XH9OubmzOa7CkWL+AUrUxpibub3vWwttjduu9No16dug1kq04hiUUpo7J3m3Xw==",
"dependencies": {
"@next/env": "13.4.10",
"@next/env": "13.4.12",
"@swc/helpers": "0.5.1",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
@ -4406,15 +4439,15 @@
"node": ">=16.8.0"
},
"optionalDependencies": {
"@next/swc-darwin-arm64": "13.4.10",
"@next/swc-darwin-x64": "13.4.10",
"@next/swc-linux-arm64-gnu": "13.4.10",
"@next/swc-linux-arm64-musl": "13.4.10",
"@next/swc-linux-x64-gnu": "13.4.10",
"@next/swc-linux-x64-musl": "13.4.10",
"@next/swc-win32-arm64-msvc": "13.4.10",
"@next/swc-win32-ia32-msvc": "13.4.10",
"@next/swc-win32-x64-msvc": "13.4.10"
"@next/swc-darwin-arm64": "13.4.12",
"@next/swc-darwin-x64": "13.4.12",
"@next/swc-linux-arm64-gnu": "13.4.12",
"@next/swc-linux-arm64-musl": "13.4.12",
"@next/swc-linux-x64-gnu": "13.4.12",
"@next/swc-linux-x64-musl": "13.4.12",
"@next/swc-win32-arm64-msvc": "13.4.12",
"@next/swc-win32-ia32-msvc": "13.4.12",
"@next/swc-win32-x64-msvc": "13.4.12"
},
"peerDependencies": {
"@opentelemetry/api": "^1.1.0",
@ -5661,9 +5694,9 @@
}
},
"node_modules/tslib": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz",
"integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA=="
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz",
"integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig=="
},
"node_modules/type-detect": {
"version": "4.0.8",

View File

@ -52,7 +52,7 @@
"cron": "^2.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.65",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.66",
"module-alias": "^2.2.2",
"multer": "^1.4.5-lts.1",
"next": "^13.1.5",

View File

@ -1,20 +1,25 @@
import { Response, Request } from "express";
import { Controller, Post } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import VotesService from "@Services/super-admin/VotesService/VotesService";
import { Service } from "typedi";
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
import { validateOrReject } from "class-validator";
import authHandler from "@App/middlewares/AuthHandler";
import UsersService from "@Services/super-admin/UsersService/UsersService";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Post } from "@ControllerPattern/index";
import { EAppointmentStatus } from "@prisma/client";
import AppointmentService from "@Services/super-admin/AppointmentsService/AppointmentsService";
import LiveVoteService from "@Services/super-admin/LiveVoteService/LiveVoteService";
import UsersService from "@Services/super-admin/UsersService/UsersService";
import VotesService from "@Services/super-admin/VotesService/VotesService";
import { validateOrReject } from "class-validator";
import { Request, Response } from "express";
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
@Controller()
@Service()
export default class LiveVoteController extends ApiController {
constructor(private liveVoteService: LiveVoteService, private votesService: VotesService, private usersService: UsersService, private appointmentService: AppointmentService) {
constructor(
private liveVoteService: LiveVoteService,
private votesService: VotesService,
private usersService: UsersService,
private appointmentService: AppointmentService,
) {
super();
}
@ -30,6 +35,7 @@ export default class LiveVoteController extends ApiController {
//validate user
await validateOrReject(voteEntity, { groups: ["createVote"] });
let voteFound = [];
if (voteEntity.appointment.uid) {
const appointment = await this.appointmentService.getByUid(voteEntity.appointment.uid);
if (!appointment) {
@ -40,27 +46,25 @@ export default class LiveVoteController extends ApiController {
this.httpBadRequest(response, "Appointment is closed");
return;
}
voteFound = await this.votesService.get({
where: { AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
});
} else {
voteFound = await this.votesService.get({
where: {
AND: [
{
appointment: {
AND: [{ user_uid: voteEntity.appointment.targeted_user.uid }, { status: EAppointmentStatus.OPEN }],
},
},
{ voter: { uid: userId } },
],
},
});
}
const votes = await this.votesService.get({
where: {
OR: [
{ AND: [{ appointment: { uid: voteEntity.appointment.uid } }, { voter: { uid: userId } }] },
{
AND: [
{
appointment: {
AND: [{ user_uid: voteEntity.appointment.targeted_user.uid }, { status: EAppointmentStatus.OPEN }],
},
},
{ voter: { uid: userId } },
],
},
],
},
});
if (votes.length) {
if (voteFound.length) {
this.httpBadRequest(response, "Voter already voted for this appointment");
return;
}
@ -71,7 +75,7 @@ export default class LiveVoteController extends ApiController {
//call service to get prisma entity
const voteEntityCreated = await this.liveVoteService.create(voteEntity);
if(!voteEntityCreated) {
if (!voteEntityCreated) {
this.httpBadRequest(response, "Appointment choice is not valid");
return;
}

View File

@ -1,8 +1,8 @@
import Database from "@Common/databases/database";
import { EAppointmentStatus, EVote, Prisma, Votes } from "@prisma/client";
import BaseRepository from "@Repositories/BaseRepository";
import { Service } from "typedi";
import { Votes, Prisma, EVote, EAppointmentStatus } from "@prisma/client";
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi";
@Service()
export default class VotesRepository extends BaseRepository {
@ -48,6 +48,7 @@ export default class VotesRepository extends BaseRepository {
connectOrCreate: {
where: whereArg,
create: {
choice: EVote[vote.appointment.choice as keyof typeof EVote],
user_uid: vote.appointment.targeted_user.uid!,
}
},