mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
feat: upgrade to TypeORM 0.3
This commit is contained in:
parent
8cee4ec1e4
commit
761ff27771
57 changed files with 412 additions and 325 deletions
210
backend/package-lock.json
generated
210
backend/package-lock.json
generated
|
@ -51,7 +51,7 @@
|
||||||
"tmp": "0.0.33",
|
"tmp": "0.0.33",
|
||||||
"tsconfig-paths": "^3.9.0",
|
"tsconfig-paths": "^3.9.0",
|
||||||
"twemoji": "^12.1.4",
|
"twemoji": "^12.1.4",
|
||||||
"typeorm": "^0.2.31",
|
"typeorm": "^0.3.17",
|
||||||
"utf-8-validate": "^5.0.5",
|
"utf-8-validate": "^5.0.5",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "^3.3.2",
|
||||||
"yawn-yaml": "github:dragory/yawn-yaml#string-number-fix-build",
|
"yawn-yaml": "github:dragory/yawn-yaml#string-number-fix-build",
|
||||||
|
@ -180,6 +180,17 @@
|
||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@babel/runtime": {
|
||||||
|
"version": "7.22.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz",
|
||||||
|
"integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==",
|
||||||
|
"dependencies": {
|
||||||
|
"regenerator-runtime": "^0.13.11"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@clinic/bubbleprof": {
|
"node_modules/@clinic/bubbleprof": {
|
||||||
"version": "9.1.0",
|
"version": "9.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@clinic/bubbleprof/-/bubbleprof-9.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@clinic/bubbleprof/-/bubbleprof-9.1.0.tgz",
|
||||||
|
@ -897,11 +908,6 @@
|
||||||
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
|
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/zen-observable": {
|
|
||||||
"version": "0.8.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz",
|
|
||||||
"integrity": "sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw=="
|
|
||||||
},
|
|
||||||
"node_modules/@vladfrangu/async_event_emitter": {
|
"node_modules/@vladfrangu/async_event_emitter": {
|
||||||
"version": "2.2.2",
|
"version": "2.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.2.2.tgz",
|
||||||
|
@ -2964,6 +2970,21 @@
|
||||||
"node": ">=0.10"
|
"node": ">=0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/date-fns": {
|
||||||
|
"version": "2.30.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
|
||||||
|
"integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.21.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.11"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/date-fns"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/date-time": {
|
"node_modules/date-time": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/date-time/-/date-time-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/date-time/-/date-time-3.1.0.tgz",
|
||||||
|
@ -7891,6 +7912,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
|
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
|
||||||
"integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg=="
|
"integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/regenerator-runtime": {
|
||||||
|
"version": "0.13.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
|
||||||
|
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
|
||||||
|
},
|
||||||
"node_modules/regexp-tree": {
|
"node_modules/regexp-tree": {
|
||||||
"version": "0.1.27",
|
"version": "0.1.27",
|
||||||
"resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz",
|
"resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz",
|
||||||
|
@ -8204,11 +8230,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
},
|
},
|
||||||
"node_modules/sax": {
|
|
||||||
"version": "1.2.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
|
||||||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
|
||||||
},
|
|
||||||
"node_modules/scope-analyzer": {
|
"node_modules/scope-analyzer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/scope-analyzer/-/scope-analyzer-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/scope-analyzer/-/scope-analyzer-2.1.2.tgz",
|
||||||
|
@ -9607,52 +9628,60 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm": {
|
"node_modules/typeorm": {
|
||||||
"version": "0.2.45",
|
"version": "0.3.17",
|
||||||
"resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.2.45.tgz",
|
"resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.3.17.tgz",
|
||||||
"integrity": "sha512-c0rCO8VMJ3ER7JQ73xfk0zDnVv0WDjpsP6Q1m6CVKul7DB9iVdWLRjPzc8v2eaeBuomsbZ2+gTaYr8k1gm3bYA==",
|
"integrity": "sha512-UDjUEwIQalO9tWw9O2A4GU+sT3oyoUXheHJy4ft+RFdnRdQctdQ34L9SqE2p7LdwzafHx1maxT+bqXON+Qnmig==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqltools/formatter": "^1.2.2",
|
"@sqltools/formatter": "^1.2.5",
|
||||||
"app-root-path": "^3.0.0",
|
"app-root-path": "^3.1.0",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.2",
|
||||||
"cli-highlight": "^2.1.11",
|
"cli-highlight": "^2.1.11",
|
||||||
"debug": "^4.3.1",
|
"date-fns": "^2.29.3",
|
||||||
"dotenv": "^8.2.0",
|
"debug": "^4.3.4",
|
||||||
"glob": "^7.1.6",
|
"dotenv": "^16.0.3",
|
||||||
"js-yaml": "^4.0.0",
|
"glob": "^8.1.0",
|
||||||
"mkdirp": "^1.0.4",
|
"mkdirp": "^2.1.3",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"sha.js": "^2.4.11",
|
"sha.js": "^2.4.11",
|
||||||
"tslib": "^2.1.0",
|
"tslib": "^2.5.0",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^9.0.0",
|
||||||
"xml2js": "^0.4.23",
|
"yargs": "^17.6.2"
|
||||||
"yargs": "^17.0.1",
|
|
||||||
"zen-observable-ts": "^1.0.0"
|
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"typeorm": "cli.js"
|
"typeorm": "cli.js",
|
||||||
|
"typeorm-ts-node-commonjs": "cli-ts-node-commonjs.js",
|
||||||
|
"typeorm-ts-node-esm": "cli-ts-node-esm.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 12.9.0"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://opencollective.com/typeorm"
|
"url": "https://opencollective.com/typeorm"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@sap/hana-client": "^2.11.14",
|
"@google-cloud/spanner": "^5.18.0",
|
||||||
"better-sqlite3": "^7.1.2",
|
"@sap/hana-client": "^2.12.25",
|
||||||
|
"better-sqlite3": "^7.1.2 || ^8.0.0",
|
||||||
"hdb-pool": "^0.1.6",
|
"hdb-pool": "^0.1.6",
|
||||||
"ioredis": "^4.28.3",
|
"ioredis": "^5.0.4",
|
||||||
"mongodb": "^3.6.0",
|
"mongodb": "^5.2.0",
|
||||||
"mssql": "^6.3.1",
|
"mssql": "^9.1.1",
|
||||||
"mysql2": "^2.2.5",
|
"mysql2": "^2.2.5 || ^3.0.1",
|
||||||
"oracledb": "^5.1.0",
|
"oracledb": "^5.1.0",
|
||||||
"pg": "^8.5.1",
|
"pg": "^8.5.1",
|
||||||
"pg-native": "^3.0.0",
|
"pg-native": "^3.0.0",
|
||||||
"pg-query-stream": "^4.0.0",
|
"pg-query-stream": "^4.0.0",
|
||||||
"redis": "^3.1.1",
|
"redis": "^3.1.1 || ^4.0.0",
|
||||||
"sql.js": "^1.4.0",
|
"sql.js": "^1.4.0",
|
||||||
"sqlite3": "^5.0.2",
|
"sqlite3": "^5.0.3",
|
||||||
|
"ts-node": "^10.7.0",
|
||||||
"typeorm-aurora-data-api-driver": "^2.0.0"
|
"typeorm-aurora-data-api-driver": "^2.0.0"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
|
"@google-cloud/spanner": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"@sap/hana-client": {
|
"@sap/hana-client": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
@ -9695,15 +9724,21 @@
|
||||||
"sqlite3": {
|
"sqlite3": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"ts-node": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"typeorm-aurora-data-api-driver": {
|
"typeorm-aurora-data-api-driver": {
|
||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm/node_modules/argparse": {
|
"node_modules/typeorm/node_modules/brace-expansion": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
|
||||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
|
||||||
|
"dependencies": {
|
||||||
|
"balanced-match": "^1.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm/node_modules/buffer": {
|
"node_modules/typeorm/node_modules/buffer": {
|
||||||
"version": "6.0.3",
|
"version": "6.0.3",
|
||||||
|
@ -9742,28 +9777,63 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm/node_modules/dotenv": {
|
"node_modules/typeorm/node_modules/dotenv": {
|
||||||
"version": "8.6.0",
|
"version": "16.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
|
||||||
"integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==",
|
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/motdotla/dotenv?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typeorm/node_modules/glob": {
|
||||||
|
"version": "8.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
|
||||||
|
"integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"fs.realpath": "^1.0.0",
|
||||||
|
"inflight": "^1.0.4",
|
||||||
|
"inherits": "2",
|
||||||
|
"minimatch": "^5.0.1",
|
||||||
|
"once": "^1.3.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typeorm/node_modules/minimatch": {
|
||||||
|
"version": "5.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
|
||||||
|
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
|
||||||
|
"dependencies": {
|
||||||
|
"brace-expansion": "^2.0.1"
|
||||||
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm/node_modules/js-yaml": {
|
"node_modules/typeorm/node_modules/mkdirp": {
|
||||||
"version": "4.1.0",
|
"version": "2.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz",
|
||||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
"integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==",
|
||||||
"dependencies": {
|
|
||||||
"argparse": "^2.0.1"
|
|
||||||
},
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"js-yaml": "bin/js-yaml.js"
|
"mkdirp": "dist/cjs/src/bin.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typeorm/node_modules/uuid": {
|
"node_modules/typeorm/node_modules/uuid": {
|
||||||
"version": "8.3.2",
|
"version": "9.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/bin/uuid"
|
||||||
}
|
}
|
||||||
|
@ -10272,26 +10342,6 @@
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/xml2js": {
|
|
||||||
"version": "0.4.23",
|
|
||||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
|
|
||||||
"integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
|
|
||||||
"dependencies": {
|
|
||||||
"sax": ">=0.6.0",
|
|
||||||
"xmlbuilder": "~11.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/xmlbuilder": {
|
|
||||||
"version": "11.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
|
|
||||||
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/xtend": {
|
"node_modules/xtend": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||||
|
@ -10353,20 +10403,6 @@
|
||||||
"yaml-js": "^0.2.3"
|
"yaml-js": "^0.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/zen-observable": {
|
|
||||||
"version": "0.8.15",
|
|
||||||
"resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz",
|
|
||||||
"integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ=="
|
|
||||||
},
|
|
||||||
"node_modules/zen-observable-ts": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-1h4zlLSqI2cRLPJUHJFL8bCWHhkpuXkF+dbGkRaWjgDIG26DmzyshUMrdV/rL3UnR+mhaX4fRq8LPouq0MYYIA==",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/zen-observable": "0.8.3",
|
|
||||||
"zen-observable": "0.8.15"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/zlib-sync": {
|
"node_modules/zlib-sync": {
|
||||||
"version": "0.1.8",
|
"version": "0.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/zlib-sync/-/zlib-sync-0.1.8.tgz",
|
||||||
|
|
|
@ -18,10 +18,12 @@
|
||||||
"start-api-prod-debug": "NODE_ENV=production DEBUG=true clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
"start-api-prod-debug": "NODE_ENV=production DEBUG=true clinic heapprofiler --collect-only --dest .clinic-api -- node -r ./register-tsconfig-paths.js --unhandled-rejections=strict --enable-source-maps --stack-trace-limit=30 dist/backend/src/api/index.js",
|
||||||
"watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"",
|
"watch-api": "cross-env NODE_ENV=development tsc-watch --onSuccess \"npm run start-api-dev\"",
|
||||||
"typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js",
|
"typeorm": "node -r ./register-tsconfig-paths.js ./node_modules/typeorm/cli.js",
|
||||||
"migrate-prod": "cross-env NODE_ENV=production npm run typeorm -- migration:run",
|
"migrate": "npm run typeorm -- migration:run -d dist/backend/src/data/dataSource.js",
|
||||||
"migrate-dev": "npm run build && npm run typeorm -- migration:run",
|
"migrate-prod": "npm run migrate",
|
||||||
"migrate-rollback-prod": "cross-env NODE_ENV=production npm run typeorm -- migration:revert",
|
"migrate-dev": "npm run build && npm run migrate",
|
||||||
"migrate-rollback-dev": "npm run build && npm run typeorm -- migration:revert",
|
"migrate-rollback": "npm run typeorm -- migration:revert -d dist/backend/src/data/dataSource.js",
|
||||||
|
"migrate-rollback-prod": "npm run migrate",
|
||||||
|
"migrate-rollback-dev": "npm run build && npm run migrate",
|
||||||
"test": "npm run build && npm run run-tests",
|
"test": "npm run build && npm run run-tests",
|
||||||
"run-tests": "ava",
|
"run-tests": "ava",
|
||||||
"test-watch": "tsc-watch --onSuccess \"npx ava\""
|
"test-watch": "tsc-watch --onSuccess \"npx ava\""
|
||||||
|
@ -70,7 +72,7 @@
|
||||||
"tmp": "0.0.33",
|
"tmp": "0.0.33",
|
||||||
"tsconfig-paths": "^3.9.0",
|
"tsconfig-paths": "^3.9.0",
|
||||||
"twemoji": "^12.1.4",
|
"twemoji": "^12.1.4",
|
||||||
"typeorm": "^0.2.31",
|
"typeorm": "^0.3.17",
|
||||||
"utf-8-validate": "^5.0.5",
|
"utf-8-validate": "^5.0.5",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "^3.3.2",
|
||||||
"yawn-yaml": "github:dragory/yawn-yaml#string-number-fix-build",
|
"yawn-yaml": "github:dragory/yawn-yaml#string-number-fix-build",
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { ApiPermissionTypes } from "./ApiPermissionAssignments";
|
import { ApiPermissionTypes } from "./ApiPermissionAssignments";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { AllowedGuild } from "./entities/AllowedGuild";
|
import { AllowedGuild } from "./entities/AllowedGuild";
|
||||||
|
|
||||||
export class AllowedGuilds extends BaseRepository {
|
export class AllowedGuilds extends BaseRepository {
|
||||||
|
@ -10,10 +11,10 @@ export class AllowedGuilds extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.allowedGuilds = getRepository(AllowedGuild);
|
this.allowedGuilds = dataSource.getRepository(AllowedGuild);
|
||||||
}
|
}
|
||||||
|
|
||||||
async isAllowed(guildId) {
|
async isAllowed(guildId: string) {
|
||||||
const count = await this.allowedGuilds.count({
|
const count = await this.allowedGuilds.count({
|
||||||
where: {
|
where: {
|
||||||
id: guildId,
|
id: guildId,
|
||||||
|
@ -22,11 +23,15 @@ export class AllowedGuilds extends BaseRepository {
|
||||||
return count !== 0;
|
return count !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
find(guildId) {
|
find(guildId: string) {
|
||||||
return this.allowedGuilds.findOne(guildId);
|
return this.allowedGuilds.findOne({
|
||||||
|
where: {
|
||||||
|
id: guildId,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getForApiUser(userId) {
|
getForApiUser(userId: string) {
|
||||||
return this.allowedGuilds
|
return this.allowedGuilds
|
||||||
.createQueryBuilder("allowed_guilds")
|
.createQueryBuilder("allowed_guilds")
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { getRepository, Repository } from "typeorm/index";
|
import { Repository } from "typeorm/index";
|
||||||
import { AuditLogEventData, AuditLogEventType } from "./apiAuditLogTypes";
|
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { AuditLogEventData, AuditLogEventType } from "./apiAuditLogTypes";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ApiAuditLogEntry } from "./entities/ApiAuditLogEntry";
|
import { ApiAuditLogEntry } from "./entities/ApiAuditLogEntry";
|
||||||
|
|
||||||
export class ApiAuditLog extends BaseRepository {
|
export class ApiAuditLog extends BaseRepository {
|
||||||
|
@ -8,7 +9,7 @@ export class ApiAuditLog extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.auditLog = getRepository(ApiAuditLogEntry);
|
this.auditLog = dataSource.getRepository(ApiAuditLogEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
addEntry<TEventType extends AuditLogEventType>(
|
addEntry<TEventType extends AuditLogEventType>(
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
// tslint:disable-next-line:no-submodule-imports
|
// tslint:disable-next-line:no-submodule-imports
|
||||||
import uuidv4 from "uuid/v4";
|
import uuidv4 from "uuid/v4";
|
||||||
import { DAYS, DBDateFormat } from "../utils";
|
import { DAYS, DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ApiLogin } from "./entities/ApiLogin";
|
import { ApiLogin } from "./entities/ApiLogin";
|
||||||
|
|
||||||
const LOGIN_EXPIRY_TIME = 1 * DAYS;
|
const LOGIN_EXPIRY_TIME = 1 * DAYS;
|
||||||
|
@ -14,7 +15,7 @@ export class ApiLogins extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.apiLogins = getRepository(ApiLogin);
|
this.apiLogins = dataSource.getRepository(ApiLogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserIdByApiKey(apiKey: string): Promise<string | null> {
|
async getUserIdByApiKey(apiKey: string): Promise<string | null> {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { ApiPermissions } from "@shared/apiPermissions";
|
import { ApiPermissions } from "@shared/apiPermissions";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { ApiAuditLog } from "./ApiAuditLog";
|
import { ApiAuditLog } from "./ApiAuditLog";
|
||||||
import { AuditLogEventTypes } from "./apiAuditLogTypes";
|
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { AuditLogEventTypes } from "./apiAuditLogTypes";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment";
|
import { ApiPermissionAssignment } from "./entities/ApiPermissionAssignment";
|
||||||
|
|
||||||
export enum ApiPermissionTypes {
|
export enum ApiPermissionTypes {
|
||||||
|
@ -16,7 +17,7 @@ export class ApiPermissionAssignments extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.apiPermissions = getRepository(ApiPermissionAssignment);
|
this.apiPermissions = dataSource.getRepository(ApiPermissionAssignment);
|
||||||
this.auditLogs = new ApiAuditLog();
|
this.auditLogs = new ApiAuditLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { ApiUserInfoData, ApiUserInfo as ApiUserInfoEntity } from "./entities/ApiUserInfo";
|
import { ApiUserInfoData, ApiUserInfo as ApiUserInfoEntity } from "./entities/ApiUserInfo";
|
||||||
|
|
||||||
export class ApiUserInfo extends BaseRepository {
|
export class ApiUserInfo extends BaseRepository {
|
||||||
|
@ -10,7 +10,7 @@ export class ApiUserInfo extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.apiUserInfo = getRepository(ApiUserInfoEntity);
|
this.apiUserInfo = dataSource.getRepository(ApiUserInfoEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(id) {
|
get(id) {
|
||||||
|
@ -22,7 +22,7 @@ export class ApiUserInfo extends BaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
update(id, data: ApiUserInfoData) {
|
update(id, data: ApiUserInfoData) {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const repo = entityManager.getRepository(ApiUserInfoEntity);
|
const repo = entityManager.getRepository(ApiUserInfoEntity);
|
||||||
|
|
||||||
const existingInfo = await repo.findOne({ where: { id } });
|
const existingInfo = await repo.findOne({ where: { id } });
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
||||||
|
|
||||||
export class Archives extends BaseRepository {
|
export class Archives extends BaseRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class Archives extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.archives = getRepository(ArchiveEntry);
|
this.archives = dataSource.getRepository(ArchiveEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteExpiredArchives() {
|
public deleteExpiredArchives() {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class BaseRepository<TEntity = unknown> {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async processEntityFromDB<T extends TEntity | undefined>(entity: T): Promise<T> {
|
protected async processEntityFromDB<T extends TEntity | null>(entity: T): Promise<T> {
|
||||||
return this._processEntityFromDB(entity);
|
return this._processEntityFromDB(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { isAPI } from "../globals";
|
import { isAPI } from "../globals";
|
||||||
import { HOURS, SECONDS } from "../utils";
|
import { HOURS, SECONDS } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
import { cleanupConfigs } from "./cleanup/configs";
|
import { cleanupConfigs } from "./cleanup/configs";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { Config } from "./entities/Config";
|
import { Config } from "./entities/Config";
|
||||||
|
|
||||||
const CLEANUP_INTERVAL = 1 * HOURS;
|
const CLEANUP_INTERVAL = 1 * HOURS;
|
||||||
|
@ -24,7 +24,7 @@ export class Configs extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.configs = getRepository(Config);
|
this.configs = dataSource.getRepository(Config);
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveByKey(key) {
|
getActiveByKey(key) {
|
||||||
|
@ -37,7 +37,7 @@ export class Configs extends BaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHighestId(): Promise<number> {
|
async getHighestId(): Promise<number> {
|
||||||
const rows = await connection.query("SELECT MAX(id) AS highest_id FROM configs");
|
const rows = await dataSource.query("SELECT MAX(id) AS highest_id FROM configs");
|
||||||
return (rows.length && rows[0].highest_id) || 0;
|
return (rows.length && rows[0].highest_id) || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ export class Configs extends BaseRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveNewRevision(key, config, editedBy) {
|
async saveNewRevision(key, config, editedBy) {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const repo = entityManager.getRepository(Config);
|
const repo = entityManager.getRepository(Config);
|
||||||
// Mark all old revisions inactive
|
// Mark all old revisions inactive
|
||||||
await repo.update({ key }, { is_active: false });
|
await repo.update({ key }, { is_active: false });
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { AntiraidLevel } from "./entities/AntiraidLevel";
|
import { AntiraidLevel } from "./entities/AntiraidLevel";
|
||||||
|
|
||||||
export class GuildAntiraidLevels extends BaseGuildRepository {
|
export class GuildAntiraidLevels extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildAntiraidLevels extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId: string) {
|
constructor(guildId: string) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.antiraidLevels = getRepository(AntiraidLevel);
|
this.antiraidLevels = dataSource.getRepository(AntiraidLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
async get() {
|
async get() {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import { Guild, Snowflake } from "discord.js";
|
import { Guild, Snowflake } from "discord.js";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { isDefaultSticker } from "src/utils/isDefaultSticker";
|
import { isDefaultSticker } from "src/utils/isDefaultSticker";
|
||||||
import { Repository, getRepository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter";
|
import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter";
|
||||||
import { renderUsername, trimLines } from "../utils";
|
import { renderUsername, trimLines } from "../utils";
|
||||||
import { decrypt, encrypt } from "../utils/crypt";
|
import { decrypt, encrypt } from "../utils/crypt";
|
||||||
import { channelToTemplateSafeChannel, guildToTemplateSafeGuild } from "../utils/templateSafeObjects";
|
import { channelToTemplateSafeChannel, guildToTemplateSafeGuild } from "../utils/templateSafeObjects";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
import { ArchiveEntry } from "./entities/ArchiveEntry";
|
||||||
import { SavedMessage } from "./entities/SavedMessage";
|
import { SavedMessage } from "./entities/SavedMessage";
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ export class GuildArchives extends BaseGuildRepository<ArchiveEntry> {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.archives = getRepository(ArchiveEntry);
|
this.archives = dataSource.getRepository(ArchiveEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _processEntityFromDB(entity: ArchiveEntry | undefined) {
|
protected async _processEntityFromDB(entity: ArchiveEntry | undefined) {
|
||||||
|
@ -42,7 +43,7 @@ export class GuildArchives extends BaseGuildRepository<ArchiveEntry> {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(id: string): Promise<ArchiveEntry | undefined> {
|
async find(id: string): Promise<ArchiveEntry | null> {
|
||||||
const result = await this.archives.findOne({
|
const result = await this.archives.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { AutoReaction } from "./entities/AutoReaction";
|
import { AutoReaction } from "./entities/AutoReaction";
|
||||||
|
|
||||||
export class GuildAutoReactions extends BaseGuildRepository {
|
export class GuildAutoReactions extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildAutoReactions extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.autoReactions = getRepository(AutoReaction);
|
this.autoReactions = dataSource.getRepository(AutoReaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
async all(): Promise<AutoReaction[]> {
|
async all(): Promise<AutoReaction[]> {
|
||||||
|
@ -18,7 +19,7 @@ export class GuildAutoReactions extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getForChannel(channelId: string): Promise<AutoReaction | undefined> {
|
async getForChannel(channelId: string): Promise<AutoReaction | null> {
|
||||||
return this.autoReactions.findOne({
|
return this.autoReactions.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -12,15 +12,19 @@ export class GuildButtonRoles extends BaseGuildRepository {
|
||||||
|
|
||||||
async getForButtonId(buttonId: string) {
|
async getForButtonId(buttonId: string) {
|
||||||
return this.buttonRoles.findOne({
|
return this.buttonRoles.findOne({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
button_id: buttonId,
|
guild_id: this.guildId,
|
||||||
|
button_id: buttonId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllForMessageId(messageId: string) {
|
async getAllForMessageId(messageId: string) {
|
||||||
return this.buttonRoles.find({
|
return this.buttonRoles.find({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
message_id: messageId,
|
guild_id: this.guildId,
|
||||||
|
message_id: messageId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +44,10 @@ export class GuildButtonRoles extends BaseGuildRepository {
|
||||||
|
|
||||||
async getForButtonGroup(buttonGroup: string) {
|
async getForButtonGroup(buttonGroup: string) {
|
||||||
return this.buttonRoles.find({
|
return this.buttonRoles.find({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
button_group: buttonGroup,
|
guild_id: this.guildId,
|
||||||
|
button_group: buttonGroup,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { getRepository, In, InsertResult, Repository } from "typeorm";
|
import { In, InsertResult, Repository } from "typeorm";
|
||||||
import { Queue } from "../Queue";
|
import { Queue } from "../Queue";
|
||||||
import { chunkArray } from "../utils";
|
import { chunkArray } from "../utils";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { CaseTypes } from "./CaseTypes";
|
import { CaseTypes } from "./CaseTypes";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { Case } from "./entities/Case";
|
import { Case } from "./entities/Case";
|
||||||
import { CaseNote } from "./entities/CaseNote";
|
import { CaseNote } from "./entities/CaseNote";
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.cases = getRepository(Case);
|
this.cases = dataSource.getRepository(Case);
|
||||||
this.caseNotes = getRepository(CaseNote);
|
this.caseNotes = dataSource.getRepository(CaseNote);
|
||||||
this.createQueue = new Queue();
|
this.createQueue = new Queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(id: number): Promise<Case | undefined> {
|
async find(id: number): Promise<Case | null> {
|
||||||
return this.cases.findOne({
|
return this.cases.findOne({
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
|
@ -40,7 +40,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByCaseNumber(caseNumber: number): Promise<Case | undefined> {
|
async findByCaseNumber(caseNumber: number): Promise<Case | null> {
|
||||||
return this.cases.findOne({
|
return this.cases.findOne({
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
|
@ -50,7 +50,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findLatestByModId(modId: string): Promise<Case | undefined> {
|
async findLatestByModId(modId: string): Promise<Case | null> {
|
||||||
return this.cases.findOne({
|
return this.cases.findOne({
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
|
@ -63,7 +63,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByAuditLogId(auditLogId: string): Promise<Case | undefined> {
|
async findByAuditLogId(auditLogId: string): Promise<Case | null> {
|
||||||
return this.cases.findOne({
|
return this.cases.findOne({
|
||||||
relations: this.getRelations(),
|
relations: this.getRelations(),
|
||||||
where: {
|
where: {
|
||||||
|
@ -88,7 +88,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
mod_id: modId,
|
mod_id: modId,
|
||||||
is_hidden: 0,
|
is_hidden: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
mod_id: modId,
|
mod_id: modId,
|
||||||
is_hidden: 0,
|
is_hidden: false,
|
||||||
},
|
},
|
||||||
skip,
|
skip,
|
||||||
take: count,
|
take: count,
|
||||||
|
@ -181,7 +181,7 @@ export class GuildCases extends BaseGuildRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async softDelete(id: number, deletedById: string, deletedByName: string, deletedByText: string) {
|
async softDelete(id: number, deletedById: string, deletedByName: string, deletedByText: string) {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const cases = entityManager.getRepository(Case);
|
const cases = entityManager.getRepository(Case);
|
||||||
const caseNotes = entityManager.getRepository(CaseNote);
|
const caseNotes = entityManager.getRepository(CaseNote);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { DeleteResult, getRepository, InsertResult, Repository } from "typeorm";
|
import { DeleteResult, InsertResult, Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ContextMenuLink } from "./entities/ContextMenuLink";
|
import { ContextMenuLink } from "./entities/ContextMenuLink";
|
||||||
|
|
||||||
export class GuildContextMenuLinks extends BaseGuildRepository {
|
export class GuildContextMenuLinks extends BaseGuildRepository {
|
||||||
|
@ -7,10 +8,10 @@ export class GuildContextMenuLinks extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.contextLinks = getRepository(ContextMenuLink);
|
this.contextLinks = dataSource.getRepository(ContextMenuLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: string): Promise<ContextMenuLink | undefined> {
|
async get(id: string): Promise<ContextMenuLink | null> {
|
||||||
return this.contextLinks.findOne({
|
return this.contextLinks.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { FindConditions, getRepository, In, IsNull, Not, Repository } from "typeorm";
|
import { FindOptionsWhere, In, IsNull, Not, Repository } from "typeorm";
|
||||||
import { Queue } from "../Queue";
|
import { Queue } from "../Queue";
|
||||||
import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils";
|
import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { Counter } from "./entities/Counter";
|
import { Counter } from "./entities/Counter";
|
||||||
import { CounterTrigger, isValidCounterComparisonOp, TriggerComparisonOp } from "./entities/CounterTrigger";
|
import { CounterTrigger, TriggerComparisonOp, isValidCounterComparisonOp } from "./entities/CounterTrigger";
|
||||||
import { CounterTriggerState } from "./entities/CounterTriggerState";
|
import { CounterTriggerState } from "./entities/CounterTriggerState";
|
||||||
import { CounterValue } from "./entities/CounterValue";
|
import { CounterValue } from "./entities/CounterValue";
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@ const MAX_COUNTER_VALUE = 2147483647; // 2^31-1, for MySQL INT
|
||||||
const decayQueue = new Queue();
|
const decayQueue = new Queue();
|
||||||
|
|
||||||
async function deleteCountersMarkedToBeDeleted(): Promise<void> {
|
async function deleteCountersMarkedToBeDeleted(): Promise<void> {
|
||||||
await getRepository(Counter).createQueryBuilder().where("delete_at <= NOW()").delete().execute();
|
await dataSource.getRepository(Counter).createQueryBuilder().where("delete_at <= NOW()").delete().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteTriggersMarkedToBeDeleted(): Promise<void> {
|
async function deleteTriggersMarkedToBeDeleted(): Promise<void> {
|
||||||
await getRepository(CounterTrigger).createQueryBuilder().where("delete_at <= NOW()").delete().execute();
|
await dataSource.getRepository(CounterTrigger).createQueryBuilder().where("delete_at <= NOW()").delete().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(deleteCountersMarkedToBeDeleted, 1 * HOURS);
|
setInterval(deleteCountersMarkedToBeDeleted, 1 * HOURS);
|
||||||
|
@ -38,10 +38,10 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.counters = getRepository(Counter);
|
this.counters = dataSource.getRepository(Counter);
|
||||||
this.counterValues = getRepository(CounterValue);
|
this.counterValues = dataSource.getRepository(CounterValue);
|
||||||
this.counterTriggers = getRepository(CounterTrigger);
|
this.counterTriggers = dataSource.getRepository(CounterTrigger);
|
||||||
this.counterTriggerStates = getRepository(CounterTriggerState);
|
this.counterTriggerStates = dataSource.getRepository(CounterTriggerState);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOrCreateCounter(name: string, perChannel: boolean, perUser: boolean): Promise<Counter> {
|
async findOrCreateCounter(name: string, perChannel: boolean, perUser: boolean): Promise<Counter> {
|
||||||
|
@ -80,7 +80,7 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async markUnusedCountersToBeDeleted(idsToKeep: number[]): Promise<void> {
|
async markUnusedCountersToBeDeleted(idsToKeep: number[]): Promise<void> {
|
||||||
const criteria: FindConditions<Counter> = {
|
const criteria: FindOptionsWhere<Counter> = {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
delete_at: IsNull(),
|
delete_at: IsNull(),
|
||||||
};
|
};
|
||||||
|
@ -256,10 +256,12 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
throw new Error(`Invalid comparison value: ${reverseComparisonValue}`);
|
throw new Error(`Invalid comparison value: ${reverseComparisonValue}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const existing = await entityManager.findOne(CounterTrigger, {
|
const existing = await entityManager.findOne(CounterTrigger, {
|
||||||
counter_id: counterId,
|
where: {
|
||||||
name: triggerName,
|
counter_id: counterId,
|
||||||
|
name: triggerName,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
@ -308,11 +310,13 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
channelId = channelId || "0";
|
channelId = channelId || "0";
|
||||||
userId = userId || "0";
|
userId = userId || "0";
|
||||||
|
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const previouslyTriggered = await entityManager.findOne(CounterTriggerState, {
|
const previouslyTriggered = await entityManager.findOne(CounterTriggerState, {
|
||||||
trigger_id: counterTrigger.id,
|
where: {
|
||||||
user_id: userId!,
|
trigger_id: counterTrigger.id,
|
||||||
channel_id: channelId!,
|
user_id: userId!,
|
||||||
|
channel_id: channelId!,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (previouslyTriggered) {
|
if (previouslyTriggered) {
|
||||||
|
@ -356,7 +360,7 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
async checkAllValuesForTrigger(
|
async checkAllValuesForTrigger(
|
||||||
counterTrigger: CounterTrigger,
|
counterTrigger: CounterTrigger,
|
||||||
): Promise<Array<{ channelId: string; userId: string }>> {
|
): Promise<Array<{ channelId: string; userId: string }>> {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const matchingValues = await entityManager
|
const matchingValues = await entityManager
|
||||||
.createQueryBuilder(CounterValue, "cv")
|
.createQueryBuilder(CounterValue, "cv")
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
|
@ -407,7 +411,7 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
channelId = channelId || "0";
|
channelId = channelId || "0";
|
||||||
userId = userId || "0";
|
userId = userId || "0";
|
||||||
|
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const matchingValue = await entityManager
|
const matchingValue = await entityManager
|
||||||
.createQueryBuilder(CounterValue, "cv")
|
.createQueryBuilder(CounterValue, "cv")
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
|
@ -446,7 +450,7 @@ export class GuildCounters extends BaseGuildRepository {
|
||||||
async checkAllValuesForReverseTrigger(
|
async checkAllValuesForReverseTrigger(
|
||||||
counterTrigger: CounterTrigger,
|
counterTrigger: CounterTrigger,
|
||||||
): Promise<Array<{ channelId: string; userId: string }>> {
|
): Promise<Array<{ channelId: string; userId: string }>> {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const matchingValues: Array<{
|
const matchingValues: Array<{
|
||||||
id: string;
|
id: string;
|
||||||
triggerStateId: string;
|
triggerStateId: string;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { Blocker } from "../Blocker";
|
import { Blocker } from "../Blocker";
|
||||||
import { DBDateFormat, MINUTES } from "../utils";
|
import { DBDateFormat, MINUTES } from "../utils";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { MemberCacheItem } from "./entities/MemberCacheItem";
|
import { MemberCacheItem } from "./entities/MemberCacheItem";
|
||||||
|
|
||||||
const SAVE_PENDING_BLOCKER_KEY = "save-pending" as const;
|
const SAVE_PENDING_BLOCKER_KEY = "save-pending" as const;
|
||||||
|
@ -20,7 +21,7 @@ export class GuildMemberCache extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId: string) {
|
constructor(guildId: string) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.#memberCache = getRepository(MemberCacheItem);
|
this.#memberCache = dataSource.getRepository(MemberCacheItem);
|
||||||
this.#pendingUpdates = new Map();
|
this.#pendingUpdates = new Map();
|
||||||
this.#blocker = new Blocker();
|
this.#blocker = new Blocker();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm/index";
|
import { Repository } from "typeorm/index";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { MemberTimezone } from "./entities/MemberTimezone";
|
import { MemberTimezone } from "./entities/MemberTimezone";
|
||||||
|
|
||||||
export class GuildMemberTimezones extends BaseGuildRepository {
|
export class GuildMemberTimezones extends BaseGuildRepository {
|
||||||
|
@ -8,22 +8,26 @@ export class GuildMemberTimezones extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId: string) {
|
constructor(guildId: string) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.memberTimezones = getRepository(MemberTimezone);
|
this.memberTimezones = dataSource.getRepository(MemberTimezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(memberId: string) {
|
get(memberId: string) {
|
||||||
return this.memberTimezones.findOne({
|
return this.memberTimezones.findOne({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
member_id: memberId,
|
guild_id: this.guildId,
|
||||||
|
member_id: memberId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(memberId, timezone: string) {
|
async set(memberId, timezone: string) {
|
||||||
await connection.transaction(async (entityManager) => {
|
await dataSource.transaction(async (entityManager) => {
|
||||||
const repo = entityManager.getRepository(MemberTimezone);
|
const repo = entityManager.getRepository(MemberTimezone);
|
||||||
const existingRow = await repo.findOne({
|
const existingRow = await repo.findOne({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
member_id: memberId,
|
guild_id: this.guildId,
|
||||||
|
member_id: memberId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (existingRow) {
|
if (existingRow) {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { Brackets, getRepository, Repository } from "typeorm";
|
import { Brackets, Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { Mute } from "./entities/Mute";
|
|
||||||
import { MuteTypes } from "./MuteTypes";
|
import { MuteTypes } from "./MuteTypes";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
|
import { Mute } from "./entities/Mute";
|
||||||
|
|
||||||
export type AddMuteParams = {
|
export type AddMuteParams = {
|
||||||
userId: Mute["user_id"];
|
userId: Mute["user_id"];
|
||||||
|
@ -19,7 +20,7 @@ export class GuildMutes extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.mutes = getRepository(Mute);
|
this.mutes = dataSource.getRepository(Mute);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExpiredMutes(): Promise<Mute[]> {
|
async getExpiredMutes(): Promise<Mute[]> {
|
||||||
|
@ -31,7 +32,7 @@ export class GuildMutes extends BaseGuildRepository {
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
async findExistingMuteForUserId(userId: string): Promise<Mute | undefined> {
|
async findExistingMuteForUserId(userId: string): Promise<Mute | null> {
|
||||||
return this.mutes.findOne({
|
return this.mutes.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { getRepository, In, Repository } from "typeorm";
|
import { In, Repository } from "typeorm";
|
||||||
import { isAPI } from "../globals";
|
import { isAPI } from "../globals";
|
||||||
import { MINUTES, SECONDS } from "../utils";
|
import { MINUTES, SECONDS } from "../utils";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { cleanupNicknames } from "./cleanup/nicknames";
|
import { cleanupNicknames } from "./cleanup/nicknames";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { NicknameHistoryEntry } from "./entities/NicknameHistoryEntry";
|
import { NicknameHistoryEntry } from "./entities/NicknameHistoryEntry";
|
||||||
|
|
||||||
const CLEANUP_INTERVAL = 5 * MINUTES;
|
const CLEANUP_INTERVAL = 5 * MINUTES;
|
||||||
|
@ -25,7 +26,7 @@ export class GuildNicknameHistory extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.nicknameHistory = getRepository(NicknameHistoryEntry);
|
this.nicknameHistory = dataSource.getRepository(NicknameHistoryEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByUserId(userId): Promise<NicknameHistoryEntry[]> {
|
async getByUserId(userId): Promise<NicknameHistoryEntry[]> {
|
||||||
|
@ -40,7 +41,7 @@ export class GuildNicknameHistory extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastEntry(userId): Promise<NicknameHistoryEntry | undefined> {
|
getLastEntry(userId): Promise<NicknameHistoryEntry | null> {
|
||||||
return this.nicknameHistory.findOne({
|
return this.nicknameHistory.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { PersistedData } from "./entities/PersistedData";
|
import { PersistedData } from "./entities/PersistedData";
|
||||||
|
|
||||||
export class GuildPersistedData extends BaseGuildRepository {
|
export class GuildPersistedData extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildPersistedData extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.persistedData = getRepository(PersistedData);
|
this.persistedData = dataSource.getRepository(PersistedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(userId: string) {
|
async find(userId: string) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { PingableRole } from "./entities/PingableRole";
|
import { PingableRole } from "./entities/PingableRole";
|
||||||
|
|
||||||
export class GuildPingableRoles extends BaseGuildRepository {
|
export class GuildPingableRoles extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildPingableRoles extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.pingableRoles = getRepository(PingableRole);
|
this.pingableRoles = dataSource.getRepository(PingableRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
async all(): Promise<PingableRole[]> {
|
async all(): Promise<PingableRole[]> {
|
||||||
|
@ -27,7 +28,7 @@ export class GuildPingableRoles extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole | undefined> {
|
async getByChannelAndRoleId(channelId: string, roleId: string): Promise<PingableRole | null> {
|
||||||
return this.pingableRoles.findOne({
|
return this.pingableRoles.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ReactionRole } from "./entities/ReactionRole";
|
import { ReactionRole } from "./entities/ReactionRole";
|
||||||
|
|
||||||
export class GuildReactionRoles extends BaseGuildRepository {
|
export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.reactionRoles = getRepository(ReactionRole);
|
this.reactionRoles = dataSource.getRepository(ReactionRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
async all(): Promise<ReactionRole[]> {
|
async all(): Promise<ReactionRole[]> {
|
||||||
|
@ -30,7 +31,7 @@ export class GuildReactionRoles extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole | undefined> {
|
async getByMessageAndEmoji(messageId: string, emoji: string): Promise<ReactionRole | null> {
|
||||||
return this.reactionRoles.findOne({
|
return this.reactionRoles.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Reminder } from "./entities/Reminder";
|
import { Reminder } from "./entities/Reminder";
|
||||||
|
|
||||||
export class GuildReminders extends BaseGuildRepository {
|
export class GuildReminders extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildReminders extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.reminders = getRepository(Reminder);
|
this.reminders = dataSource.getRepository(Reminder);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDueReminders(): Promise<Reminder[]> {
|
async getDueReminders(): Promise<Reminder[]> {
|
||||||
|
@ -28,7 +29,9 @@ export class GuildReminders extends BaseGuildRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
find(id: number) {
|
find(id: number) {
|
||||||
return this.reminders.findOne({ id });
|
return this.reminders.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id) {
|
async delete(id) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { RoleButtonsItem } from "./entities/RoleButtonsItem";
|
import { RoleButtonsItem } from "./entities/RoleButtonsItem";
|
||||||
|
|
||||||
export class GuildRoleButtons extends BaseGuildRepository {
|
export class GuildRoleButtons extends BaseGuildRepository {
|
||||||
|
@ -7,11 +8,15 @@ export class GuildRoleButtons extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.roleButtons = getRepository(RoleButtonsItem);
|
this.roleButtons = dataSource.getRepository(RoleButtonsItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSavedRoleButtons(): Promise<RoleButtonsItem[]> {
|
getSavedRoleButtons(): Promise<RoleButtonsItem[]> {
|
||||||
return this.roleButtons.find({ guild_id: this.guildId });
|
return this.roleButtons.find({
|
||||||
|
where: {
|
||||||
|
guild_id: this.guildId,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteRoleButtonItem(name: string): Promise<void> {
|
async deleteRoleButtonItem(name: string): Promise<void> {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { connection } from "./db";
|
import { dataSource } from "./dataSource";
|
||||||
import { RoleQueueItem } from "./entities/RoleQueueItem";
|
import { RoleQueueItem } from "./entities/RoleQueueItem";
|
||||||
|
|
||||||
export class GuildRoleQueue extends BaseGuildRepository {
|
export class GuildRoleQueue extends BaseGuildRepository {
|
||||||
|
@ -8,11 +8,11 @@ export class GuildRoleQueue extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.roleQueue = getRepository(RoleQueueItem);
|
this.roleQueue = dataSource.getRepository(RoleQueueItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeNextRoleAssignments(count: number): Promise<RoleQueueItem[]> {
|
consumeNextRoleAssignments(count: number): Promise<RoleQueueItem[]> {
|
||||||
return connection.transaction(async (entityManager) => {
|
return dataSource.transaction(async (entityManager) => {
|
||||||
const repository = entityManager.getRepository(RoleQueueItem);
|
const repository = entityManager.getRepository(RoleQueueItem);
|
||||||
|
|
||||||
const nextAssignments = await repository
|
const nextAssignments = await repository
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import { GuildChannel, Message } from "discord.js";
|
import { GuildChannel, Message } from "discord.js";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { Repository, getRepository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
import { QueuedEventEmitter } from "../QueuedEventEmitter";
|
||||||
import { noop } from "../utils";
|
import { noop } from "../utils";
|
||||||
import { asyncMap } from "../utils/async";
|
import { asyncMap } from "../utils/async";
|
||||||
import { decryptJson, encryptJson } from "../utils/cryptHelpers";
|
import { decryptJson, encryptJson } from "../utils/cryptHelpers";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
import { buildEntity } from "./buildEntity";
|
import { buildEntity } from "./buildEntity";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
|
import { ISavedMessageData, SavedMessage } from "./entities/SavedMessage";
|
||||||
|
|
||||||
export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
|
export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
|
||||||
|
@ -17,7 +18,7 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.messages = getRepository(SavedMessage);
|
this.messages = dataSource.getRepository(SavedMessage);
|
||||||
this.events = new QueuedEventEmitter();
|
this.events = new QueuedEventEmitter();
|
||||||
|
|
||||||
this.toBePermanent = new Set();
|
this.toBePermanent = new Set();
|
||||||
|
@ -137,7 +138,7 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(id: string, includeDeleted = false): Promise<SavedMessage | undefined> {
|
async find(id: string, includeDeleted = false): Promise<SavedMessage | null> {
|
||||||
let query = this.messages
|
let query = this.messages
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
.where("guild_id = :guild_id", { guild_id: this.guildId })
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ScheduledPost } from "./entities/ScheduledPost";
|
import { ScheduledPost } from "./entities/ScheduledPost";
|
||||||
|
|
||||||
export class GuildScheduledPosts extends BaseGuildRepository {
|
export class GuildScheduledPosts extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildScheduledPosts extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.scheduledPosts = getRepository(ScheduledPost);
|
this.scheduledPosts = dataSource.getRepository(ScheduledPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
all(): Promise<ScheduledPost[]> {
|
all(): Promise<ScheduledPost[]> {
|
||||||
|
@ -23,7 +24,11 @@ export class GuildScheduledPosts extends BaseGuildRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
find(id: number) {
|
find(id: number) {
|
||||||
return this.scheduledPosts.findOne({ id });
|
return this.scheduledPosts.findOne({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id) {
|
async delete(id) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { SlowmodeChannel } from "./entities/SlowmodeChannel";
|
import { SlowmodeChannel } from "./entities/SlowmodeChannel";
|
||||||
import { SlowmodeUser } from "./entities/SlowmodeUser";
|
import { SlowmodeUser } from "./entities/SlowmodeUser";
|
||||||
|
|
||||||
|
@ -10,11 +11,11 @@ export class GuildSlowmodes extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.slowmodeChannels = getRepository(SlowmodeChannel);
|
this.slowmodeChannels = dataSource.getRepository(SlowmodeChannel);
|
||||||
this.slowmodeUsers = getRepository(SlowmodeUser);
|
this.slowmodeUsers = dataSource.getRepository(SlowmodeUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChannelSlowmode(channelId): Promise<SlowmodeChannel | undefined> {
|
async getChannelSlowmode(channelId): Promise<SlowmodeChannel | null> {
|
||||||
return this.slowmodeChannels.findOne({
|
return this.slowmodeChannels.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
@ -51,11 +52,13 @@ export class GuildSlowmodes extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChannelSlowmodeUser(channelId, userId): Promise<SlowmodeUser | undefined> {
|
async getChannelSlowmodeUser(channelId, userId): Promise<SlowmodeUser | null> {
|
||||||
return this.slowmodeUsers.findOne({
|
return this.slowmodeUsers.findOne({
|
||||||
guild_id: this.guildId,
|
where: {
|
||||||
channel_id: channelId,
|
guild_id: this.guildId,
|
||||||
user_id: userId,
|
channel_id: channelId,
|
||||||
|
user_id: userId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { StarboardMessage } from "./entities/StarboardMessage";
|
import { StarboardMessage } from "./entities/StarboardMessage";
|
||||||
|
|
||||||
export class GuildStarboardMessages extends BaseGuildRepository {
|
export class GuildStarboardMessages extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildStarboardMessages extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.allStarboardMessages = getRepository(StarboardMessage);
|
this.allStarboardMessages = dataSource.getRepository(StarboardMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStarboardMessagesForMessageId(messageId: string) {
|
async getStarboardMessagesForMessageId(messageId: string) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { StarboardReaction } from "./entities/StarboardReaction";
|
import { StarboardReaction } from "./entities/StarboardReaction";
|
||||||
|
|
||||||
export class GuildStarboardReactions extends BaseGuildRepository {
|
export class GuildStarboardReactions extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildStarboardReactions extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.allStarboardReactions = getRepository(StarboardReaction);
|
this.allStarboardReactions = dataSource.getRepository(StarboardReaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllReactionsForMessageId(messageId: string) {
|
async getAllReactionsForMessageId(messageId: string) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { StatValue } from "./entities/StatValue";
|
import { StatValue } from "./entities/StatValue";
|
||||||
|
|
||||||
export class GuildStats extends BaseGuildRepository {
|
export class GuildStats extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildStats extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.stats = getRepository(StatValue);
|
this.stats = dataSource.getRepository(StatValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveValue(source: string, key: string, value: number): Promise<void> {
|
async saveValue(source: string, key: string, value: number): Promise<void> {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Tag } from "./entities/Tag";
|
import { Tag } from "./entities/Tag";
|
||||||
import { TagResponse } from "./entities/TagResponse";
|
import { TagResponse } from "./entities/TagResponse";
|
||||||
|
|
||||||
|
@ -9,8 +10,8 @@ export class GuildTags extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.tags = getRepository(Tag);
|
this.tags = dataSource.getRepository(Tag);
|
||||||
this.tagResponses = getRepository(TagResponse);
|
this.tagResponses = dataSource.getRepository(TagResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
async all(): Promise<Tag[]> {
|
async all(): Promise<Tag[]> {
|
||||||
|
@ -21,7 +22,7 @@ export class GuildTags extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(tag): Promise<Tag | undefined> {
|
async find(tag): Promise<Tag | null> {
|
||||||
return this.tags.findOne({
|
return this.tags.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
@ -61,7 +62,7 @@ export class GuildTags extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findResponseByCommandMessageId(messageId: string): Promise<TagResponse | undefined> {
|
async findResponseByCommandMessageId(messageId: string): Promise<TagResponse | null> {
|
||||||
return this.tagResponses.findOne({
|
return this.tagResponses.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
@ -70,7 +71,7 @@ export class GuildTags extends BaseGuildRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findResponseByResponseMessageId(messageId: string): Promise<TagResponse | undefined> {
|
async findResponseByResponseMessageId(messageId: string): Promise<TagResponse | null> {
|
||||||
return this.tagResponses.findOne({
|
return this.tagResponses.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Tempban } from "./entities/Tempban";
|
import { Tempban } from "./entities/Tempban";
|
||||||
|
|
||||||
export class GuildTempbans extends BaseGuildRepository {
|
export class GuildTempbans extends BaseGuildRepository {
|
||||||
|
@ -8,7 +9,7 @@ export class GuildTempbans extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.tempbans = getRepository(Tempban);
|
this.tempbans = dataSource.getRepository(Tempban);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExpiredTempbans(): Promise<Tempban[]> {
|
async getExpiredTempbans(): Promise<Tempban[]> {
|
||||||
|
@ -20,7 +21,7 @@ export class GuildTempbans extends BaseGuildRepository {
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
async findExistingTempbanForUserId(userId: string): Promise<Tempban | undefined> {
|
async findExistingTempbanForUserId(userId: string): Promise<Tempban | null> {
|
||||||
return this.tempbans.findOne({
|
return this.tempbans.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { VCAlert } from "./entities/VCAlert";
|
import { VCAlert } from "./entities/VCAlert";
|
||||||
|
|
||||||
export class GuildVCAlerts extends BaseGuildRepository {
|
export class GuildVCAlerts extends BaseGuildRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class GuildVCAlerts extends BaseGuildRepository {
|
||||||
|
|
||||||
constructor(guildId) {
|
constructor(guildId) {
|
||||||
super(guildId);
|
super(guildId);
|
||||||
this.allAlerts = getRepository(VCAlert);
|
this.allAlerts = dataSource.getRepository(VCAlert);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOutdatedAlerts(): Promise<VCAlert[]> {
|
async getOutdatedAlerts(): Promise<VCAlert[]> {
|
||||||
|
@ -41,7 +42,9 @@ export class GuildVCAlerts extends BaseGuildRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
find(id: number) {
|
find(id: number) {
|
||||||
return this.allAlerts.findOne({ id });
|
return this.allAlerts.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id) {
|
async delete(id) {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DAYS } from "../utils";
|
import { DAYS } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { MemberCacheItem } from "./entities/MemberCacheItem";
|
import { MemberCacheItem } from "./entities/MemberCacheItem";
|
||||||
|
|
||||||
const STALE_PERIOD = 90 * DAYS;
|
const STALE_PERIOD = 90 * DAYS;
|
||||||
|
@ -11,7 +12,7 @@ export class MemberCache extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.#memberCache = getRepository(MemberCacheItem);
|
this.#memberCache = dataSource.getRepository(MemberCacheItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteStaleData(): Promise<void> {
|
async deleteStaleData(): Promise<void> {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DAYS, DBDateFormat } from "../utils";
|
import { DAYS, DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
import { Mute } from "./entities/Mute";
|
|
||||||
import { MuteTypes } from "./MuteTypes";
|
import { MuteTypes } from "./MuteTypes";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
|
import { Mute } from "./entities/Mute";
|
||||||
|
|
||||||
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS;
|
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS;
|
||||||
|
|
||||||
|
@ -16,10 +17,10 @@ export class Mutes extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.mutes = getRepository(Mute);
|
this.mutes = dataSource.getRepository(Mute);
|
||||||
}
|
}
|
||||||
|
|
||||||
findMute(guildId: string, userId: string): Promise<Mute | undefined> {
|
findMute(guildId: string, userId: string): Promise<Mute | null> {
|
||||||
return this.mutes.findOne({
|
return this.mutes.findOne({
|
||||||
where: {
|
where: {
|
||||||
guild_id: guildId,
|
guild_id: guildId,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { env } from "../env";
|
import { env } from "../env";
|
||||||
import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils";
|
import { DAYS, DBDateFormat, HOURS, MINUTES } from "../utils";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { PhishermanCacheEntry } from "./entities/PhishermanCacheEntry";
|
import { PhishermanCacheEntry } from "./entities/PhishermanCacheEntry";
|
||||||
import { PhishermanKeyCacheEntry } from "./entities/PhishermanKeyCacheEntry";
|
import { PhishermanKeyCacheEntry } from "./entities/PhishermanKeyCacheEntry";
|
||||||
import { PhishermanDomainInfo, PhishermanUnknownDomain } from "./types/phisherman";
|
import { PhishermanDomainInfo, PhishermanUnknownDomain } from "./types/phisherman";
|
||||||
|
@ -39,7 +40,7 @@ const KEY_VALIDITY_LIFETIME = 24 * HOURS;
|
||||||
let cacheRepository: Repository<PhishermanCacheEntry> | null = null;
|
let cacheRepository: Repository<PhishermanCacheEntry> | null = null;
|
||||||
function getCacheRepository(): Repository<PhishermanCacheEntry> {
|
function getCacheRepository(): Repository<PhishermanCacheEntry> {
|
||||||
if (cacheRepository == null) {
|
if (cacheRepository == null) {
|
||||||
cacheRepository = getRepository(PhishermanCacheEntry);
|
cacheRepository = dataSource.getRepository(PhishermanCacheEntry);
|
||||||
}
|
}
|
||||||
return cacheRepository;
|
return cacheRepository;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +48,7 @@ function getCacheRepository(): Repository<PhishermanCacheEntry> {
|
||||||
let keyCacheRepository: Repository<PhishermanKeyCacheEntry> | null = null;
|
let keyCacheRepository: Repository<PhishermanKeyCacheEntry> | null = null;
|
||||||
function getKeyCacheRepository(): Repository<PhishermanKeyCacheEntry> {
|
function getKeyCacheRepository(): Repository<PhishermanKeyCacheEntry> {
|
||||||
if (keyCacheRepository == null) {
|
if (keyCacheRepository == null) {
|
||||||
keyCacheRepository = getRepository(PhishermanKeyCacheEntry);
|
keyCacheRepository = dataSource.getRepository(PhishermanKeyCacheEntry);
|
||||||
}
|
}
|
||||||
return keyCacheRepository;
|
return keyCacheRepository;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +154,9 @@ export async function getPhishermanDomainInfo(domain: string): Promise<Phisherma
|
||||||
}
|
}
|
||||||
|
|
||||||
const dbCache = getCacheRepository();
|
const dbCache = getCacheRepository();
|
||||||
const existingCachedEntry = await dbCache.findOne({ domain });
|
const existingCachedEntry = await dbCache.findOne({
|
||||||
|
where: { domain },
|
||||||
|
});
|
||||||
if (existingCachedEntry) {
|
if (existingCachedEntry) {
|
||||||
return existingCachedEntry.data;
|
return existingCachedEntry.data;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +199,9 @@ export async function phishermanApiKeyIsValid(apiKey: string): Promise<boolean>
|
||||||
|
|
||||||
const keyCache = getKeyCacheRepository();
|
const keyCache = getKeyCacheRepository();
|
||||||
const hash = crypto.createHash("sha256").update(apiKey).digest("hex");
|
const hash = crypto.createHash("sha256").update(apiKey).digest("hex");
|
||||||
const entry = await keyCache.findOne({ hash });
|
const entry = await keyCache.findOne({
|
||||||
|
where: { hash },
|
||||||
|
});
|
||||||
if (entry) {
|
if (entry) {
|
||||||
return entry.is_valid;
|
return entry.is_valid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Reminder } from "./entities/Reminder";
|
import { Reminder } from "./entities/Reminder";
|
||||||
|
|
||||||
export class Reminders extends BaseRepository {
|
export class Reminders extends BaseRepository {
|
||||||
|
@ -9,7 +10,7 @@ export class Reminders extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.reminders = getRepository(Reminder);
|
this.reminders = dataSource.getRepository(Reminder);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRemindersDueSoon(threshold: number): Promise<Reminder[]> {
|
async getRemindersDueSoon(threshold: number): Promise<Reminder[]> {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { ScheduledPost } from "./entities/ScheduledPost";
|
import { ScheduledPost } from "./entities/ScheduledPost";
|
||||||
|
|
||||||
export class ScheduledPosts extends BaseRepository {
|
export class ScheduledPosts extends BaseRepository {
|
||||||
|
@ -9,7 +10,7 @@ export class ScheduledPosts extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.scheduledPosts = getRepository(ScheduledPost);
|
this.scheduledPosts = dataSource.getRepository(ScheduledPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
getScheduledPostsDueSoon(threshold: number): Promise<ScheduledPost[]> {
|
getScheduledPostsDueSoon(threshold: number): Promise<ScheduledPost[]> {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Supporter } from "./entities/Supporter";
|
import { Supporter } from "./entities/Supporter";
|
||||||
|
|
||||||
export class Supporters extends BaseRepository {
|
export class Supporters extends BaseRepository {
|
||||||
|
@ -7,7 +8,7 @@ export class Supporters extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.supporters = getRepository(Supporter);
|
this.supporters = dataSource.getRepository(Supporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll() {
|
getAll() {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Tempban } from "./entities/Tempban";
|
import { Tempban } from "./entities/Tempban";
|
||||||
|
|
||||||
export class Tempbans extends BaseRepository {
|
export class Tempbans extends BaseRepository {
|
||||||
|
@ -9,7 +10,7 @@ export class Tempbans extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.tempbans = getRepository(Tempban);
|
this.tempbans = dataSource.getRepository(Tempban);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSoonExpiringTempbans(threshold: number): Promise<Tempban[]> {
|
getSoonExpiringTempbans(threshold: number): Promise<Tempban[]> {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { getRepository, In, Repository } from "typeorm";
|
import { In, Repository } from "typeorm";
|
||||||
import { isAPI } from "../globals";
|
import { isAPI } from "../globals";
|
||||||
import { MINUTES, SECONDS } from "../utils";
|
import { MINUTES, SECONDS } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
import { cleanupUsernames } from "./cleanup/usernames";
|
import { cleanupUsernames } from "./cleanup/usernames";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { UsernameHistoryEntry } from "./entities/UsernameHistoryEntry";
|
import { UsernameHistoryEntry } from "./entities/UsernameHistoryEntry";
|
||||||
|
|
||||||
const CLEANUP_INTERVAL = 5 * MINUTES;
|
const CLEANUP_INTERVAL = 5 * MINUTES;
|
||||||
|
@ -25,7 +26,7 @@ export class UsernameHistory extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.usernameHistory = getRepository(UsernameHistoryEntry);
|
this.usernameHistory = dataSource.getRepository(UsernameHistoryEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByUserId(userId): Promise<UsernameHistoryEntry[]> {
|
async getByUserId(userId): Promise<UsernameHistoryEntry[]> {
|
||||||
|
@ -40,7 +41,7 @@ export class UsernameHistory extends BaseRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getLastEntry(userId): Promise<UsernameHistoryEntry | undefined> {
|
getLastEntry(userId): Promise<UsernameHistoryEntry | null> {
|
||||||
return this.usernameHistory.findOne({
|
return this.usernameHistory.findOne({
|
||||||
where: {
|
where: {
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { DBDateFormat } from "../utils";
|
import { DBDateFormat } from "../utils";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { VCAlert } from "./entities/VCAlert";
|
import { VCAlert } from "./entities/VCAlert";
|
||||||
|
|
||||||
export class VCAlerts extends BaseRepository {
|
export class VCAlerts extends BaseRepository {
|
||||||
|
@ -9,7 +10,7 @@ export class VCAlerts extends BaseRepository {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.allAlerts = getRepository(VCAlert);
|
this.allAlerts = dataSource.getRepository(VCAlert);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSoonExpiringAlerts(threshold: number): Promise<VCAlert[]> {
|
async getSoonExpiringAlerts(threshold: number): Promise<VCAlert[]> {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
import { decrypt, encrypt } from "../utils/crypt";
|
import { decrypt, encrypt } from "../utils/crypt";
|
||||||
import { BaseRepository } from "./BaseRepository";
|
import { BaseRepository } from "./BaseRepository";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { Webhook } from "./entities/Webhook";
|
import { Webhook } from "./entities/Webhook";
|
||||||
|
|
||||||
export class Webhooks extends BaseRepository {
|
export class Webhooks extends BaseRepository {
|
||||||
repository: Repository<Webhook> = getRepository(Webhook);
|
repository: Repository<Webhook> = dataSource.getRepository(Webhook);
|
||||||
|
|
||||||
protected async _processEntityFromDB(entity) {
|
protected async _processEntityFromDB(entity) {
|
||||||
entity.token = await decrypt(entity.token);
|
entity.token = await decrypt(entity.token);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import { DBDateFormat } from "../../utils";
|
import { DBDateFormat } from "../../utils";
|
||||||
import { connection } from "../db";
|
import { dataSource } from "../dataSource";
|
||||||
import { Config } from "../entities/Config";
|
import { Config } from "../entities/Config";
|
||||||
|
|
||||||
const CLEAN_PER_LOOP = 50;
|
const CLEAN_PER_LOOP = 50;
|
||||||
|
|
||||||
export async function cleanupConfigs() {
|
export async function cleanupConfigs() {
|
||||||
const configRepository = getRepository(Config);
|
const configRepository = dataSource.getRepository(Config);
|
||||||
|
|
||||||
// FIXME: The query below doesn't work on MySQL 8.0. Pending an update.
|
// FIXME: The query below doesn't work on MySQL 8.0. Pending an update.
|
||||||
return;
|
return;
|
||||||
|
@ -18,7 +18,7 @@ export async function cleanupConfigs() {
|
||||||
// >1 month old: 1 config retained per month
|
// >1 month old: 1 config retained per month
|
||||||
const oneMonthCutoff = moment.utc().subtract(30, "days").format(DBDateFormat);
|
const oneMonthCutoff = moment.utc().subtract(30, "days").format(DBDateFormat);
|
||||||
do {
|
do {
|
||||||
rows = await connection.query(
|
rows = await dataSource.query(
|
||||||
`
|
`
|
||||||
WITH _configs
|
WITH _configs
|
||||||
AS (
|
AS (
|
||||||
|
@ -56,7 +56,7 @@ export async function cleanupConfigs() {
|
||||||
// >2 weeks old: 1 config retained per day
|
// >2 weeks old: 1 config retained per day
|
||||||
const twoWeekCutoff = moment.utc().subtract(2, "weeks").format(DBDateFormat);
|
const twoWeekCutoff = moment.utc().subtract(2, "weeks").format(DBDateFormat);
|
||||||
do {
|
do {
|
||||||
rows = await connection.query(
|
rows = await dataSource.query(
|
||||||
`
|
`
|
||||||
WITH _configs
|
WITH _configs
|
||||||
AS (
|
AS (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import { DAYS, DBDateFormat, MINUTES, SECONDS, sleep } from "../../utils";
|
import { DAYS, DBDateFormat, MINUTES, SECONDS, sleep } from "../../utils";
|
||||||
import { connection } from "../db";
|
import { dataSource } from "../dataSource";
|
||||||
import { SavedMessage } from "../entities/SavedMessage";
|
import { SavedMessage } from "../entities/SavedMessage";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@ const CLEAN_PER_LOOP = 100;
|
||||||
export async function cleanupMessages(): Promise<number> {
|
export async function cleanupMessages(): Promise<number> {
|
||||||
let cleaned = 0;
|
let cleaned = 0;
|
||||||
|
|
||||||
const messagesRepository = getRepository(SavedMessage);
|
const messagesRepository = dataSource.getRepository(SavedMessage);
|
||||||
|
|
||||||
const deletedAtThreshold = moment.utc().subtract(DELETED_MESSAGE_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
const deletedAtThreshold = moment.utc().subtract(DELETED_MESSAGE_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
||||||
const postedAtThreshold = moment.utc().subtract(RETENTION_PERIOD, "ms").format(DBDateFormat);
|
const postedAtThreshold = moment.utc().subtract(RETENTION_PERIOD, "ms").format(DBDateFormat);
|
||||||
|
@ -27,7 +27,7 @@ export async function cleanupMessages(): Promise<number> {
|
||||||
// when a message was being inserted at the same time
|
// when a message was being inserted at the same time
|
||||||
let ids: string[];
|
let ids: string[];
|
||||||
do {
|
do {
|
||||||
const deletedMessageRows = await connection.query(
|
const deletedMessageRows = await dataSource.query(
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM messages
|
FROM messages
|
||||||
|
@ -40,7 +40,7 @@ export async function cleanupMessages(): Promise<number> {
|
||||||
[deletedAtThreshold],
|
[deletedAtThreshold],
|
||||||
);
|
);
|
||||||
|
|
||||||
const oldPostedRows = await connection.query(
|
const oldPostedRows = await dataSource.query(
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM messages
|
FROM messages
|
||||||
|
@ -53,7 +53,7 @@ export async function cleanupMessages(): Promise<number> {
|
||||||
[postedAtThreshold],
|
[postedAtThreshold],
|
||||||
);
|
);
|
||||||
|
|
||||||
const oldBotPostedRows = await connection.query(
|
const oldBotPostedRows = await dataSource.query(
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM messages
|
FROM messages
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import { DAYS, DBDateFormat } from "../../utils";
|
import { DAYS, DBDateFormat } from "../../utils";
|
||||||
import { connection } from "../db";
|
import { dataSource } from "../dataSource";
|
||||||
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
|
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
|
||||||
|
|
||||||
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
|
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||||
|
@ -10,13 +10,13 @@ const CLEAN_PER_LOOP = 500;
|
||||||
export async function cleanupNicknames(): Promise<number> {
|
export async function cleanupNicknames(): Promise<number> {
|
||||||
let cleaned = 0;
|
let cleaned = 0;
|
||||||
|
|
||||||
const nicknameHistoryRepository = getRepository(NicknameHistoryEntry);
|
const nicknameHistoryRepository = dataSource.getRepository(NicknameHistoryEntry);
|
||||||
const dateThreshold = moment.utc().subtract(NICKNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
const dateThreshold = moment.utc().subtract(NICKNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
||||||
|
|
||||||
// Clean old nicknames (NICKNAME_RETENTION_PERIOD)
|
// Clean old nicknames (NICKNAME_RETENTION_PERIOD)
|
||||||
let rows;
|
let rows;
|
||||||
do {
|
do {
|
||||||
rows = await connection.query(
|
rows = await dataSource.query(
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM nickname_history
|
FROM nickname_history
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { getRepository, In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import { DAYS, DBDateFormat } from "../../utils";
|
import { DAYS, DBDateFormat } from "../../utils";
|
||||||
import { connection } from "../db";
|
import { dataSource } from "../dataSource";
|
||||||
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
|
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
|
||||||
|
|
||||||
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
|
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
|
||||||
|
@ -10,13 +10,13 @@ const CLEAN_PER_LOOP = 500;
|
||||||
export async function cleanupUsernames(): Promise<number> {
|
export async function cleanupUsernames(): Promise<number> {
|
||||||
let cleaned = 0;
|
let cleaned = 0;
|
||||||
|
|
||||||
const usernameHistoryRepository = getRepository(UsernameHistoryEntry);
|
const usernameHistoryRepository = dataSource.getRepository(UsernameHistoryEntry);
|
||||||
const dateThreshold = moment.utc().subtract(USERNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
const dateThreshold = moment.utc().subtract(USERNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
|
||||||
|
|
||||||
// Clean old usernames (USERNAME_RETENTION_PERIOD)
|
// Clean old usernames (USERNAME_RETENTION_PERIOD)
|
||||||
let rows;
|
let rows;
|
||||||
do {
|
do {
|
||||||
rows = await connection.query(
|
rows = await dataSource.query(
|
||||||
`
|
`
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM username_history
|
FROM username_history
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
const fs = require("fs");
|
import moment from "moment-timezone";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const { backendDir } = require("./dist/backend/src/paths");
|
import { DataSource } from "typeorm";
|
||||||
const { env } = require("./dist/backend/src/env");
|
import { env } from "../env";
|
||||||
|
import { backendDir } from "../paths";
|
||||||
|
|
||||||
const moment = require("moment-timezone");
|
|
||||||
moment.tz.setDefault("UTC");
|
moment.tz.setDefault("UTC");
|
||||||
|
|
||||||
const entities = path.relative(process.cwd(), path.resolve(backendDir, "dist/backend/src/data/entities/*.js"));
|
const entities = path.relative(process.cwd(), path.resolve(backendDir, "dist/backend/src/data/entities/*.js"));
|
||||||
const migrations = path.relative(process.cwd(), path.resolve(backendDir, "dist/backend/src/migrations/*.js"));
|
const migrations = path.relative(process.cwd(), path.resolve(backendDir, "dist/backend/src/migrations/*.js"));
|
||||||
const migrationsDir = path.relative(process.cwd(), path.resolve(backendDir, "src/migrations"));
|
|
||||||
|
|
||||||
module.exports = {
|
export const dataSource = new DataSource({
|
||||||
type: "mysql",
|
type: "mysql",
|
||||||
host: env.DB_HOST,
|
host: env.DB_HOST,
|
||||||
port: env.DB_PORT,
|
port: env.DB_PORT,
|
||||||
|
@ -43,7 +42,4 @@ module.exports = {
|
||||||
|
|
||||||
// Migrations
|
// Migrations
|
||||||
migrations: [migrations],
|
migrations: [migrations],
|
||||||
cli: {
|
});
|
||||||
migrationsDir,
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,33 +1,15 @@
|
||||||
import path from "path";
|
|
||||||
import { Connection, createConnection } from "typeorm";
|
|
||||||
import { SimpleError } from "../SimpleError";
|
import { SimpleError } from "../SimpleError";
|
||||||
import { backendDir } from "../paths";
|
import { dataSource } from "./dataSource";
|
||||||
import { QueryLogger } from "./queryLogger";
|
|
||||||
|
|
||||||
const ormconfigPath = path.join(backendDir, "ormconfig.js");
|
let connectionPromise: Promise<void>;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
||||||
const connectionOptions = require(ormconfigPath);
|
|
||||||
|
|
||||||
let connectionPromise: Promise<Connection>;
|
|
||||||
|
|
||||||
export let connection: Connection;
|
|
||||||
|
|
||||||
export function connect() {
|
export function connect() {
|
||||||
if (!connectionPromise) {
|
if (!connectionPromise) {
|
||||||
connectionPromise = createConnection({
|
connectionPromise = dataSource.initialize().then(async (initializedDataSource) => {
|
||||||
...(connectionOptions as any),
|
const tzResult = await initializedDataSource.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz");
|
||||||
logging: ["query", "error"],
|
if (tzResult[0].tz !== "00:00:00") {
|
||||||
logger: new QueryLogger(),
|
throw new SimpleError(`Database timezone must be UTC (detected ${tzResult[0].tz})`);
|
||||||
}).then((newConnection) => {
|
}
|
||||||
// Verify the DB timezone is set to UTC
|
|
||||||
return newConnection.query("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) AS tz").then((r) => {
|
|
||||||
if (r[0].tz !== "00:00:00") {
|
|
||||||
throw new SimpleError(`Database timezone must be UTC (detected ${r[0].tz})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
connection = newConnection;
|
|
||||||
return newConnection;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import { getRepository, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
|
import { dataSource } from "./dataSource";
|
||||||
import { SavedMessage } from "./entities/SavedMessage";
|
import { SavedMessage } from "./entities/SavedMessage";
|
||||||
|
|
||||||
let repository: Repository<SavedMessage>;
|
let repository: Repository<SavedMessage>;
|
||||||
|
|
||||||
export async function getChannelIdFromMessageId(messageId: string): Promise<string | null> {
|
export async function getChannelIdFromMessageId(messageId: string): Promise<string | null> {
|
||||||
if (!repository) {
|
if (!repository) {
|
||||||
repository = getRepository(SavedMessage);
|
repository = dataSource.getRepository(SavedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedMessage = await repository.findOne(messageId);
|
const savedMessage = await repository.findOne({ where: { id: messageId } });
|
||||||
if (savedMessage) {
|
if (savedMessage) {
|
||||||
return savedMessage.channel_id;
|
return savedMessage.channel_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { Configs } from "./data/Configs";
|
||||||
import { GuildLogs } from "./data/GuildLogs";
|
import { GuildLogs } from "./data/GuildLogs";
|
||||||
import { LogType } from "./data/LogType";
|
import { LogType } from "./data/LogType";
|
||||||
import { hasPhishermanMasterAPIKey } from "./data/Phisherman";
|
import { hasPhishermanMasterAPIKey } from "./data/Phisherman";
|
||||||
|
import { dataSource } from "./data/dataSource";
|
||||||
import { connect } from "./data/db";
|
import { connect } from "./data/db";
|
||||||
import { runExpiredArchiveDeletionLoop } from "./data/loops/expiredArchiveDeletionLoop";
|
import { runExpiredArchiveDeletionLoop } from "./data/loops/expiredArchiveDeletionLoop";
|
||||||
import { runExpiredMemberCacheDeletionLoop } from "./data/loops/expiredMemberCacheDeletionLoop";
|
import { runExpiredMemberCacheDeletionLoop } from "./data/loops/expiredMemberCacheDeletionLoop";
|
||||||
|
@ -445,7 +446,7 @@ connect().then(async (connection) => {
|
||||||
// Force exit after 10sec
|
// Force exit after 10sec
|
||||||
setTimeout(() => process.exit(code), 10 * SECONDS);
|
setTimeout(() => process.exit(code), 10 * SECONDS);
|
||||||
await bot.stop();
|
await bot.stop();
|
||||||
await connection.close();
|
await dataSource.destroy();
|
||||||
logger.info("Done! Exiting now.");
|
logger.info("Done! Exiting now.");
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let guild: AllowedGuild | undefined;
|
let guild: AllowedGuild | null = null;
|
||||||
if (args.guildId) {
|
if (args.guildId) {
|
||||||
guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
|
|
|
@ -208,8 +208,8 @@ export async function muteUser(
|
||||||
|
|
||||||
// Create/update a case
|
// Create/update a case
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||||
let theCase: Case | undefined =
|
let theCase: Case | null =
|
||||||
existingMute && existingMute.case_id ? await pluginData.state.cases.find(existingMute.case_id) : undefined;
|
existingMute && existingMute.case_id ? await pluginData.state.cases.find(existingMute.case_id) : null;
|
||||||
|
|
||||||
if (theCase) {
|
if (theCase) {
|
||||||
// Update old case
|
// Update old case
|
||||||
|
|
|
@ -6,11 +6,8 @@ import { LogType } from "../../../data/LogType";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||||
import { humanizeDurationShort } from "../../../humanizeDurationShort";
|
import { humanizeDurationShort } from "../../../humanizeDurationShort";
|
||||||
import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||||
import { allowTimeout } from "../../../RegExpRunner";
|
|
||||||
import { chunkArray, DAYS, getInviteCodesInString, noop, SECONDS } from "../../../utils";
|
|
||||||
import { utilityCmd, UtilityPluginType } from "../types";
|
|
||||||
import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin";
|
import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin";
|
||||||
import { DAYS, SECONDS, getInviteCodesInString, noop } from "../../../utils";
|
import { DAYS, SECONDS, chunkArray, getInviteCodesInString, noop } from "../../../utils";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { UtilityPluginType, utilityCmd } from "../types";
|
import { UtilityPluginType, utilityCmd } from "../types";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue