From ff15f01bcb7ffe84c9d86114e66d4ff6f1a17fb8 Mon Sep 17 00:00:00 2001 From: bayan2002 Date: Wed, 12 Oct 2022 16:24:48 +0300 Subject: [PATCH 1/3] create Advertisements & Announcements models relates #42 --- .eslintrc.js | 25 +-- package-lock.json | 275 +++++++++++++++++++++++++++ package.json | 1 + server/database/config/connection.ts | 28 +-- server/models/Advertisements.ts | 51 +++++ server/models/Announcements.ts | 41 ++++ 6 files changed, 396 insertions(+), 25 deletions(-) create mode 100644 server/models/Advertisements.ts create mode 100644 server/models/Announcements.ts diff --git a/.eslintrc.js b/.eslintrc.js index cfc0ca8..77abab5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,18 +10,19 @@ module.exports = { 'airbnb-base', 'airbnb-typescript/base' ], - overrides: [ - { - files: ['*.ts', '*.tsx'], - extends: [ - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/recommended-requiring-type-checking', - ], - parserOptions: { - project: ['./tsconfig.json'], - }, - }, - ], + overrides: [], + // overrides: [ + // { + // files: ['*.ts', '*.tsx'], + // extends: [ + // 'plugin:@typescript-eslint/recommended', + // 'plugin:@typescript-eslint/recommended-requiring-type-checking', + // ], + // parserOptions: { + // project: ['./tsconfig.json'], + // }, + // }, + // ], parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', diff --git a/package-lock.json b/package-lock.json index ae9837c..9526f49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "jsonwebtoken": "^8.5.1", "pg": "^8.8.0", "pg-hstore": "^2.3.4", + "sequelize": "^6.25.0", "ts-jest": "^27.1.4" }, "devDependencies": { @@ -1438,6 +1439,14 @@ "integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==", "dev": true }, + "node_modules/@types/debug": { + "version": "4.1.7", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.7.tgz", + "integrity": "sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==", + "dependencies": { + "@types/ms": "*" + } + }, "node_modules/@types/express": { "version": "4.17.14", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.14.tgz", @@ -1527,6 +1536,11 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", "dev": true }, + "node_modules/@types/ms": { + "version": "0.7.31", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", + "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" + }, "node_modules/@types/node": { "version": "17.0.45", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", @@ -1621,6 +1635,11 @@ "@types/superagent": "*" } }, + "node_modules/@types/validator": { + "version": "13.7.7", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.7.tgz", + "integrity": "sha512-jiEw2kTUJ8Jsh4A1K4b5Pkjj9Xz6FktLLOQ36ZVLRkmxFbpTvAV2VRoKMojz8UlZxNg/2dZqzpigH4JYn1bkQg==" + }, "node_modules/@types/yargs": { "version": "16.0.4", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", @@ -3018,6 +3037,11 @@ "node": ">=12" } }, + "node_modules/dottie": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", + "integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" + }, "node_modules/dynamic-dedupe": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz", @@ -4668,6 +4692,14 @@ "node": ">=0.8.19" } }, + "node_modules/inflection": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.13.4.tgz", + "integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw==", + "engines": [ + "node >= 0.4.0" + ] + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -7039,6 +7071,25 @@ "node": ">=10" } }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.37", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.37.tgz", + "integrity": "sha512-uEDzDNFhfaywRl+vwXxffjjq1q0Vzr+fcQpQ1bU0kbzorfS7zVtZnCnGc8mhWmF39d4g4YriF6kwA75mJKE/Zg==", + "dependencies": { + "moment": ">= 2.9.0" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -7823,6 +7874,11 @@ "node": ">=10" } }, + "node_modules/retry-as-promised": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-6.1.0.tgz", + "integrity": "sha512-Hj/jY+wFC+SB9SDlIIFWiGOHnNG0swYbGYsOj2BJ8u2HKUaobNKab0OIC0zOLYzDy0mb7A4xA5BMo4LMz5YtEA==" + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -7954,6 +8010,89 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/sequelize": { + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.25.0.tgz", + "integrity": "sha512-Bu2V+Yjw/4fwGve0rwk02jmbuA0JGGGD1N7yrfGQXVRD91hg4j9Ecth4NwnK4fX1MQA4R0Cqfx3BaJDAOoaiSA==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/sequelize" + } + ], + "dependencies": { + "@types/debug": "^4.1.7", + "@types/validator": "^13.7.1", + "debug": "^4.3.3", + "dottie": "^2.0.2", + "inflection": "^1.13.2", + "lodash": "^4.17.21", + "moment": "^2.29.1", + "moment-timezone": "^0.5.34", + "pg-connection-string": "^2.5.0", + "retry-as-promised": "^6.1.0", + "semver": "^7.3.5", + "sequelize-pool": "^7.1.0", + "toposort-class": "^1.0.1", + "uuid": "^8.3.2", + "validator": "^13.7.0", + "wkx": "^0.5.0" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependenciesMeta": { + "ibm_db": { + "optional": true + }, + "mariadb": { + "optional": true + }, + "mysql2": { + "optional": true + }, + "oracledb": { + "optional": true + }, + "pg": { + "optional": true + }, + "pg-hstore": { + "optional": true + }, + "snowflake-sdk": { + "optional": true + }, + "sqlite3": { + "optional": true + }, + "tedious": { + "optional": true + } + } + }, + "node_modules/sequelize-pool": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-7.1.0.tgz", + "integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/sequelize/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/serve-static": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", @@ -8424,6 +8563,11 @@ "node": ">=0.6" } }, + "node_modules/toposort-class": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", + "integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg==" + }, "node_modules/tough-cookie": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz", @@ -8825,6 +8969,14 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-to-istanbul": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz", @@ -8846,6 +8998,14 @@ "node": ">= 8" } }, + "node_modules/validator": { + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", + "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -8953,6 +9113,14 @@ "string-width": "^1.0.2 || 2 || 3 || 4" } }, + "node_modules/wkx": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz", + "integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", @@ -10177,6 +10345,14 @@ "integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==", "dev": true }, + "@types/debug": { + "version": "4.1.7", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.7.tgz", + "integrity": "sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==", + "requires": { + "@types/ms": "*" + } + }, "@types/express": { "version": "4.17.14", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.14.tgz", @@ -10266,6 +10442,11 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", "dev": true }, + "@types/ms": { + "version": "0.7.31", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", + "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" + }, "@types/node": { "version": "17.0.45", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", @@ -10360,6 +10541,11 @@ "@types/superagent": "*" } }, + "@types/validator": { + "version": "13.7.7", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.7.tgz", + "integrity": "sha512-jiEw2kTUJ8Jsh4A1K4b5Pkjj9Xz6FktLLOQ36ZVLRkmxFbpTvAV2VRoKMojz8UlZxNg/2dZqzpigH4JYn1bkQg==" + }, "@types/yargs": { "version": "16.0.4", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", @@ -11365,6 +11551,11 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" }, + "dottie": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", + "integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" + }, "dynamic-dedupe": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz", @@ -12569,6 +12760,11 @@ "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==" }, + "inflection": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.13.4.tgz", + "integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw==" + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -14304,6 +14500,19 @@ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" }, + "moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" + }, + "moment-timezone": { + "version": "0.5.37", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.37.tgz", + "integrity": "sha512-uEDzDNFhfaywRl+vwXxffjjq1q0Vzr+fcQpQ1bU0kbzorfS7zVtZnCnGc8mhWmF39d4g4YriF6kwA75mJKE/Zg==", + "requires": { + "moment": ">= 2.9.0" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -14861,6 +15070,11 @@ "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-1.1.0.tgz", "integrity": "sha512-J1l+Zxxp4XK3LUDZ9m60LRJF/mAe4z6a4xyabPHk7pvK5t35dACV32iIjJDFeWZFfZlO29w6SZ67knR0tHzJtQ==" }, + "retry-as-promised": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-6.1.0.tgz", + "integrity": "sha512-Hj/jY+wFC+SB9SDlIIFWiGOHnNG0swYbGYsOj2BJ8u2HKUaobNKab0OIC0zOLYzDy0mb7A4xA5BMo4LMz5YtEA==" + }, "reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -14960,6 +15174,44 @@ } } }, + "sequelize": { + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.25.0.tgz", + "integrity": "sha512-Bu2V+Yjw/4fwGve0rwk02jmbuA0JGGGD1N7yrfGQXVRD91hg4j9Ecth4NwnK4fX1MQA4R0Cqfx3BaJDAOoaiSA==", + "requires": { + "@types/debug": "^4.1.7", + "@types/validator": "^13.7.1", + "debug": "^4.3.3", + "dottie": "^2.0.2", + "inflection": "^1.13.2", + "lodash": "^4.17.21", + "moment": "^2.29.1", + "moment-timezone": "^0.5.34", + "pg-connection-string": "^2.5.0", + "retry-as-promised": "^6.1.0", + "semver": "^7.3.5", + "sequelize-pool": "^7.1.0", + "toposort-class": "^1.0.1", + "uuid": "^8.3.2", + "validator": "^13.7.0", + "wkx": "^0.5.0" + }, + "dependencies": { + "semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, + "sequelize-pool": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-7.1.0.tgz", + "integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==" + }, "serve-static": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", @@ -15306,6 +15558,11 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, + "toposort-class": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", + "integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg==" + }, "tough-cookie": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz", @@ -15574,6 +15831,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "v8-to-istanbul": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz", @@ -15591,6 +15853,11 @@ } } }, + "validator": { + "version": "13.7.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", + "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -15677,6 +15944,14 @@ "string-width": "^1.0.2 || 2 || 3 || 4" } }, + "wkx": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz", + "integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==", + "requires": { + "@types/node": "*" + } + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index 9d43244..98a8921 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "jsonwebtoken": "^8.5.1", "pg": "^8.8.0", "pg-hstore": "^2.3.4", + "sequelize": "^6.25.0", "ts-jest": "^27.1.4" }, "devDependencies": { diff --git a/server/database/config/connection.ts b/server/database/config/connection.ts index c99aede..1346870 100644 --- a/server/database/config/connection.ts +++ b/server/database/config/connection.ts @@ -1,28 +1,30 @@ -import { boolean } from "joi"; +import { Sequelize } from 'sequelize'; -const { sequelize } =require('sequelize'); +import dotenv from 'dotenv'; -require("dotenv").config(); +dotenv.config(); -const { NODE_ENV, DEV_DB_URL, TEST_DB_URL, DATABASE_URL } = process.env; +const { + NODE_ENV, DEV_DB_URL, TEST_DB_URL, DATABASE_URL, +} = process.env; -let url:string = "" || undefined; -let ssl:object | boolean = false; +let url:string = '' || undefined; +let ssl : object | boolean = false; switch (NODE_ENV) { - case "development": + case 'development': url = DEV_DB_URL; break; - case "production": + case 'production': url = DATABASE_URL; ssl = { rejectUnauthorized: false }; break; - case "test": + case 'test': url = TEST_DB_URL; break; default: - throw new Error("The database url is invalid!"); + throw new Error('The database url is invalid!'); } -if(!url) throw new Error("The database url is invalid!"); +if (!url) throw new Error('The database url is invalid!'); -const sequelizeConfig = new sequelize(url); -export default sequelizeConfig; \ No newline at end of file +const sequelizeConfig = new Sequelize(url); +export default sequelizeConfig; diff --git a/server/models/Advertisements.ts b/server/models/Advertisements.ts new file mode 100644 index 0000000..2dd5988 --- /dev/null +++ b/server/models/Advertisements.ts @@ -0,0 +1,51 @@ +import { + InferAttributes, + InferCreationAttributes, + DataTypes, + Model, + CreationOptional, +} from 'sequelize'; +import sequelize from '../database/config/connection'; + +interface AdvertisementsModel + extends Model< + InferAttributes, + InferCreationAttributes + > { + id: CreationOptional + Title: string + Description: string + StartDate: Date + EndDate: Date + Image: string +} + +const Advertisements = sequelize.define('Advertisements', { + id: { + primaryKey: true, + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + }, + Title: { + type: DataTypes.STRING, + allowNull: false, + }, + Description: { + type: DataTypes.STRING, + allowNull: false, + }, + StartDate: { + type: DataTypes.DATE, + allowNull: false, + }, + EndDate: { + type: DataTypes.DATE, + allowNull: false, + }, + Image: { + type: DataTypes.STRING, + allowNull: false, + }, +}); + +export default Advertisements; diff --git a/server/models/Announcements.ts b/server/models/Announcements.ts new file mode 100644 index 0000000..df1f3cb --- /dev/null +++ b/server/models/Announcements.ts @@ -0,0 +1,41 @@ +import { + InferAttributes, + InferCreationAttributes, + DataTypes, + Model, + CreationOptional, +} from 'sequelize'; +import sequelize from '../database/config/connection'; + +interface AnnouncementsModel + extends Model< + InferAttributes, + InferCreationAttributes + > { + id: CreationOptional + Title: string + StartDate: Date + EndDate: Date +} + +const Announcements = sequelize.define('Announcements', { + id: { + primaryKey: true, + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, + }, + Title: { + type: DataTypes.STRING, + allowNull: false, + }, + StartDate: { + type: DataTypes.DATE, + allowNull: false, + }, + EndDate: { + type: DataTypes.DATE, + allowNull: false, + }, +}); + +export default Announcements; From 990545778eb19ac02e13f2cb83e0270135367306 Mon Sep 17 00:00:00 2001 From: bayan2002 Date: Thu, 13 Oct 2022 10:33:16 +0300 Subject: [PATCH 2/3] change the sbilling of the models attributes & change the id type relates #43 --- server/models/Advertisements.ts | 22 +++++++++++----------- server/models/Announcements.ts | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/server/models/Advertisements.ts b/server/models/Advertisements.ts index 2dd5988..5b6fd1c 100644 --- a/server/models/Advertisements.ts +++ b/server/models/Advertisements.ts @@ -12,12 +12,12 @@ interface AdvertisementsModel InferAttributes, InferCreationAttributes > { - id: CreationOptional - Title: string - Description: string - StartDate: Date - EndDate: Date - Image: string + id: CreationOptional + title: string + description: string + startDate: Date + endDate: Date + image: string } const Advertisements = sequelize.define('Advertisements', { @@ -26,23 +26,23 @@ const Advertisements = sequelize.define('Advertisements', { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, }, - Title: { + title: { type: DataTypes.STRING, allowNull: false, }, - Description: { + description: { type: DataTypes.STRING, allowNull: false, }, - StartDate: { + startDate: { type: DataTypes.DATE, allowNull: false, }, - EndDate: { + endDate: { type: DataTypes.DATE, allowNull: false, }, - Image: { + image: { type: DataTypes.STRING, allowNull: false, }, diff --git a/server/models/Announcements.ts b/server/models/Announcements.ts index df1f3cb..18b34fd 100644 --- a/server/models/Announcements.ts +++ b/server/models/Announcements.ts @@ -12,27 +12,27 @@ interface AnnouncementsModel InferAttributes, InferCreationAttributes > { - id: CreationOptional - Title: string - StartDate: Date - EndDate: Date + id: CreationOptional + title: string + startDate: Date + endDate: Date } const Announcements = sequelize.define('Announcements', { id: { primaryKey: true, - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, + autoIncrement: true, + type: DataTypes.NUMBER, }, - Title: { + title: { type: DataTypes.STRING, allowNull: false, }, - StartDate: { + startDate: { type: DataTypes.DATE, allowNull: false, }, - EndDate: { + endDate: { type: DataTypes.DATE, allowNull: false, }, From e1b106e33f68f6c9bf5bf3e645ef71f419bc4e44 Mon Sep 17 00:00:00 2001 From: bayan2002 Date: Thu, 13 Oct 2022 10:37:32 +0300 Subject: [PATCH 3/3] remove ssl relates #42 --- server/database/config/connection.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/database/config/connection.ts b/server/database/config/connection.ts index 1346870..4648beb 100644 --- a/server/database/config/connection.ts +++ b/server/database/config/connection.ts @@ -9,14 +9,12 @@ const { } = process.env; let url:string = '' || undefined; -let ssl : object | boolean = false; switch (NODE_ENV) { case 'development': url = DEV_DB_URL; break; case 'production': url = DATABASE_URL; - ssl = { rejectUnauthorized: false }; break; case 'test': url = TEST_DB_URL;