From c23239c0dabedfe15bb7a6d9d0d91358c59fb2d1 Mon Sep 17 00:00:00 2001 From: Divlo Date: Tue, 1 Mar 2022 23:00:49 +0100 Subject: [PATCH] fix(services): realtime edge cases --- .eslintrc.json | 3 +- package-lock.json | 250 +++++++++--------- package.json | 6 +- .../[channelId]/__test__/delete.test.ts | 6 + .../channels/[channelId]/__test__/put.test.ts | 6 + src/services/channels/[channelId]/delete.ts | 19 +- src/services/channels/[channelId]/put.ts | 19 +- .../guilds/[guildId]/__test__/delete.test.ts | 12 +- .../guilds/[guildId]/__test__/get.test.ts | 8 + .../guilds/[guildId]/__test__/put.test.ts | 9 +- .../[guildId]/channels/__test__/post.test.ts | 6 + .../guilds/[guildId]/channels/post.ts | 19 +- src/services/guilds/[guildId]/delete.ts | 22 +- src/services/guilds/[guildId]/get.ts | 22 +- src/services/guilds/[guildId]/icon/put.ts | 28 +- src/services/guilds/[guildId]/put.ts | 22 +- 16 files changed, 289 insertions(+), 168 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index da7847b..8f3e44a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,6 +12,7 @@ "prettier/prettier": "error", "import/extensions": ["error", "always"], "unicorn/prevent-abbreviations": "error", - "@typescript-eslint/await-thenable": "off" + "@typescript-eslint/await-thenable": "off", + "@typescript-eslint/no-misused-promises": "off" } } diff --git a/package-lock.json b/package-lock.json index 689ef77..59626fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "devDependencies": { "@commitlint/cli": "16.2.1", "@commitlint/config-conventional": "16.2.1", - "@saithodev/semantic-release-backmerge": "2.1.1", + "@saithodev/semantic-release-backmerge": "2.1.2", "@swc/cli": "0.1.55", "@swc/core": "1.2.146", "@swc/jest": "0.2.20", @@ -49,7 +49,7 @@ "@types/ms": "0.7.31", "@types/node": "17.0.21", "@types/nodemailer": "6.4.4", - "@typescript-eslint/eslint-plugin": "5.12.1", + "@typescript-eslint/eslint-plugin": "5.13.0", "concurrently": "7.0.0", "cross-env": "7.0.3", "editorconfig-checker": "4.0.2", @@ -72,7 +72,7 @@ "prisma": "3.10.0", "rimraf": "3.0.2", "semantic-release": "19.0.2", - "typescript": "4.5.5" + "typescript": "4.6.2" }, "engines": { "node": ">=16.0.0", @@ -1588,9 +1588,9 @@ "integrity": "sha512-cVYs5gyQH/qyut24hUvDznCfPrWiNMKNfPb9WmEoiU6ihlkscIbCfkmuKTtspVLWRdl0LqjYEC7vfnPv17HWhw==" }, "node_modules/@saithodev/semantic-release-backmerge": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@saithodev/semantic-release-backmerge/-/semantic-release-backmerge-2.1.1.tgz", - "integrity": "sha512-GUMOHJ8/q1V3bAXlvT3+ImveEyJt+NvRSrlJIbQda8o8c/QN9JiK9yP+aCMTjm1tQK/gp1c+/TeyniYC2nPRlg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@saithodev/semantic-release-backmerge/-/semantic-release-backmerge-2.1.2.tgz", + "integrity": "sha512-fNd8cmijjFIMp4GcdTAcug/7tr4k+8bAyvSsbLOnfyKCWyq42lg14vFZOryLiyLUAe8gpPlI7XzDPWyFTR5zug==", "dev": true, "dependencies": { "@semantic-release/error": "^2.2.0 || ^3.0.0", @@ -1691,9 +1691,9 @@ } }, "node_modules/@semantic-release/npm": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-9.0.0.tgz", - "integrity": "sha512-hj2jqayS2SPUmFtCMCOQMX975uMDfRoymj1HvMSwYdaoI6hVZvhrTFPBgJeM85O0C+G3IFviAUar5gel/1VGDQ==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-9.0.1.tgz", + "integrity": "sha512-I5nVZklxBzfMFwemhRNbSrkiN/dsH3c7K9+KSk6jUnq0rdLFUuJt7EBsysq4Ir3moajQgFkfEryEHPqiKJj20g==", "dev": true, "dependencies": { "@semantic-release/error": "^3.0.0", @@ -2420,14 +2420,14 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.1.tgz", - "integrity": "sha512-M499lqa8rnNK7mUv74lSFFttuUsubIRdAbHcVaP93oFcKkEmHmLqy2n7jM9C8DVmFMYK61ExrZU6dLYhQZmUpw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.13.0.tgz", + "integrity": "sha512-vLktb2Uec81fxm/cfz2Hd6QaWOs8qdmVAZXLdOBX6JFJDhf6oDZpMzZ4/LZ6SFM/5DgDcxIMIvy3F+O9yZBuiQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/type-utils": "5.12.1", - "@typescript-eslint/utils": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/type-utils": "5.13.0", + "@typescript-eslint/utils": "5.13.0", "debug": "^4.3.2", "functional-red-black-tree": "^1.0.1", "ignore": "^5.1.8", @@ -2453,15 +2453,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.12.1.tgz", - "integrity": "sha512-6LuVUbe7oSdHxUWoX/m40Ni8gsZMKCi31rlawBHt7VtW15iHzjbpj2WLiToG2758KjtCCiLRKZqfrOdl3cNKuw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.13.0.tgz", + "integrity": "sha512-GdrU4GvBE29tm2RqWOM0P5QfCtgCyN4hXICj/X9ibKED16136l9ZpoJvCL5pSKtmJzA+NRDzQ312wWMejCVVfg==", "dev": true, "peer": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/typescript-estree": "5.13.0", "debug": "^4.3.2" }, "engines": { @@ -2481,13 +2481,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.12.1.tgz", - "integrity": "sha512-J0Wrh5xS6XNkd4TkOosxdpObzlYfXjAFIm9QxYLCPOcHVv1FyyFCPom66uIh8uBr0sZCrtS+n19tzufhwab8ZQ==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.13.0.tgz", + "integrity": "sha512-T4N8UvKYDSfVYdmJq7g2IPJYCRzwtp74KyDZytkR4OL3NRupvswvmJQJ4CX5tDSurW2cvCc1Ia1qM7d0jpa7IA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1" + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/visitor-keys": "5.13.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2498,12 +2498,12 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.12.1.tgz", - "integrity": "sha512-Gh8feEhsNLeCz6aYqynh61Vsdy+tiNNkQtc+bN3IvQvRqHkXGUhYkUi+ePKzP0Mb42se7FDb+y2SypTbpbR/Sg==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.13.0.tgz", + "integrity": "sha512-/nz7qFizaBM1SuqAKb7GLkcNn2buRdDgZraXlkhz+vUGiN1NZ9LzkA595tHHeduAiS2MsHqMNhE2zNzGdw43Yg==", "dev": true, "dependencies": { - "@typescript-eslint/utils": "5.12.1", + "@typescript-eslint/utils": "5.13.0", "debug": "^4.3.2", "tsutils": "^3.21.0" }, @@ -2524,9 +2524,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.12.1.tgz", - "integrity": "sha512-hfcbq4qVOHV1YRdhkDldhV9NpmmAu2vp6wuFODL71Y0Ixak+FLeEU4rnPxgmZMnGreGEghlEucs9UZn5KOfHJA==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.13.0.tgz", + "integrity": "sha512-LmE/KO6DUy0nFY/OoQU0XelnmDt+V8lPQhh8MOVa7Y5k2gGRd6U9Kp3wAjhB4OHg57tUO0nOnwYQhRRyEAyOyg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2537,13 +2537,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.12.1.tgz", - "integrity": "sha512-ahOdkIY9Mgbza7L9sIi205Pe1inCkZWAHE1TV1bpxlU4RZNPtXaDZfiiFWcL9jdxvW1hDYZJXrFm+vlMkXRbBw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz", + "integrity": "sha512-Q9cQow0DeLjnp5DuEDjLZ6JIkwGx3oYZe+BfcNuw/POhtpcxMTy18Icl6BJqTSd+3ftsrfuVb7mNHRZf7xiaNA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/visitor-keys": "5.13.0", "debug": "^4.3.2", "globby": "^11.0.4", "is-glob": "^4.0.3", @@ -2564,15 +2564,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.12.1.tgz", - "integrity": "sha512-Qq9FIuU0EVEsi8fS6pG+uurbhNTtoYr4fq8tKjBupsK5Bgbk2I32UGm0Sh+WOyjOPgo/5URbxxSNV6HYsxV4MQ==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.13.0.tgz", + "integrity": "sha512-+9oHlPWYNl6AwwoEt5TQryEHwiKRVjz7Vk6kaBeD3/kwHE5YqTGHtm/JZY8Bo9ITOeKutFaXnBlMgSATMJALUQ==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/typescript-estree": "5.13.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, @@ -2588,12 +2588,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.12.1.tgz", - "integrity": "sha512-l1KSLfupuwrXx6wc0AuOmC7Ko5g14ZOQ86wJJqRbdLbXLK02pK/DPiDDqCc7BqqiiA04/eAA6ayL0bgOrAkH7A==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.13.0.tgz", + "integrity": "sha512-HLKEAS/qA1V7d9EzcpLFykTePmOQqOFim8oCvhY3pZgQ8Hi38hYpHd9e5GN6nQBFQNecNhws5wkS9Y5XIO0s/g==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", + "@typescript-eslint/types": "5.13.0", "eslint-visitor-keys": "^3.0.0" }, "engines": { @@ -4122,13 +4122,13 @@ } }, "node_modules/cosmiconfig-typescript-loader": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-1.0.5.tgz", - "integrity": "sha512-FL/YR1nb8hyN0bAcP3MBaIoZravfZtVsN/RuPnoo6UVjqIrDxSNIpXHCGgJe0ZWy5yImpyD6jq5wCJ5f1nUv8g==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-1.0.6.tgz", + "integrity": "sha512-2nEotziYJWtNtoTjKbchj9QrdTT6DBxCvqjNKoDKARw+e2yZmTQCa07uRrykLIZuvSgp69YXLH89UHc0WhdMfQ==", "dev": true, "dependencies": { "cosmiconfig": "^7", - "ts-node": "^10.5.0" + "ts-node": "^10.6.0" }, "engines": { "node": ">=12", @@ -4637,9 +4637,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.73", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.73.tgz", - "integrity": "sha512-RlCffXkE/LliqfA5m29+dVDPB2r72y2D2egMMfIy3Le8ODrxjuZNVo4NIC2yPL01N4xb4nZQLwzi6Z5tGIGLnA==", + "version": "1.4.75", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.75.tgz", + "integrity": "sha512-LxgUNeu3BVU7sXaKjUDD9xivocQLxFtq6wgERrutdY/yIOps3ODOZExK1jg8DTEg4U8TUCb5MLGeWFOYuxjF3Q==", "dev": true }, "node_modules/emittery": { @@ -6502,9 +6502,9 @@ } }, "node_modules/has-symbols": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz", - "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true, "engines": { "node": ">= 0.4" @@ -15141,9 +15141,9 @@ } }, "node_modules/ts-node": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz", - "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==", + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.6.0.tgz", + "integrity": "sha512-CJen6+dfOXolxudBQXnVjRVvYTmTWbyz7cn+xq2XTsvnaXbHqr4gXSCNbS2Jj8yTZMuGwUoBESLaOkLascVVvg==", "dev": true, "dependencies": { "@cspotcode/source-map-support": "0.7.0", @@ -15306,9 +15306,9 @@ } }, "node_modules/typescript": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", - "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz", + "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -17099,9 +17099,9 @@ "integrity": "sha512-cVYs5gyQH/qyut24hUvDznCfPrWiNMKNfPb9WmEoiU6ihlkscIbCfkmuKTtspVLWRdl0LqjYEC7vfnPv17HWhw==" }, "@saithodev/semantic-release-backmerge": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@saithodev/semantic-release-backmerge/-/semantic-release-backmerge-2.1.1.tgz", - "integrity": "sha512-GUMOHJ8/q1V3bAXlvT3+ImveEyJt+NvRSrlJIbQda8o8c/QN9JiK9yP+aCMTjm1tQK/gp1c+/TeyniYC2nPRlg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@saithodev/semantic-release-backmerge/-/semantic-release-backmerge-2.1.2.tgz", + "integrity": "sha512-fNd8cmijjFIMp4GcdTAcug/7tr4k+8bAyvSsbLOnfyKCWyq42lg14vFZOryLiyLUAe8gpPlI7XzDPWyFTR5zug==", "dev": true, "requires": { "@semantic-release/error": "^2.2.0 || ^3.0.0", @@ -17183,9 +17183,9 @@ } }, "@semantic-release/npm": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-9.0.0.tgz", - "integrity": "sha512-hj2jqayS2SPUmFtCMCOQMX975uMDfRoymj1HvMSwYdaoI6hVZvhrTFPBgJeM85O0C+G3IFviAUar5gel/1VGDQ==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@semantic-release/npm/-/npm-9.0.1.tgz", + "integrity": "sha512-I5nVZklxBzfMFwemhRNbSrkiN/dsH3c7K9+KSk6jUnq0rdLFUuJt7EBsysq4Ir3moajQgFkfEryEHPqiKJj20g==", "dev": true, "requires": { "@semantic-release/error": "^3.0.0", @@ -17699,14 +17699,14 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.1.tgz", - "integrity": "sha512-M499lqa8rnNK7mUv74lSFFttuUsubIRdAbHcVaP93oFcKkEmHmLqy2n7jM9C8DVmFMYK61ExrZU6dLYhQZmUpw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.13.0.tgz", + "integrity": "sha512-vLktb2Uec81fxm/cfz2Hd6QaWOs8qdmVAZXLdOBX6JFJDhf6oDZpMzZ4/LZ6SFM/5DgDcxIMIvy3F+O9yZBuiQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/type-utils": "5.12.1", - "@typescript-eslint/utils": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/type-utils": "5.13.0", + "@typescript-eslint/utils": "5.13.0", "debug": "^4.3.2", "functional-red-black-tree": "^1.0.1", "ignore": "^5.1.8", @@ -17716,53 +17716,53 @@ } }, "@typescript-eslint/parser": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.12.1.tgz", - "integrity": "sha512-6LuVUbe7oSdHxUWoX/m40Ni8gsZMKCi31rlawBHt7VtW15iHzjbpj2WLiToG2758KjtCCiLRKZqfrOdl3cNKuw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.13.0.tgz", + "integrity": "sha512-GdrU4GvBE29tm2RqWOM0P5QfCtgCyN4hXICj/X9ibKED16136l9ZpoJvCL5pSKtmJzA+NRDzQ312wWMejCVVfg==", "dev": true, "peer": true, "requires": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/typescript-estree": "5.13.0", "debug": "^4.3.2" } }, "@typescript-eslint/scope-manager": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.12.1.tgz", - "integrity": "sha512-J0Wrh5xS6XNkd4TkOosxdpObzlYfXjAFIm9QxYLCPOcHVv1FyyFCPom66uIh8uBr0sZCrtS+n19tzufhwab8ZQ==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.13.0.tgz", + "integrity": "sha512-T4N8UvKYDSfVYdmJq7g2IPJYCRzwtp74KyDZytkR4OL3NRupvswvmJQJ4CX5tDSurW2cvCc1Ia1qM7d0jpa7IA==", "dev": true, "requires": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1" + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/visitor-keys": "5.13.0" } }, "@typescript-eslint/type-utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.12.1.tgz", - "integrity": "sha512-Gh8feEhsNLeCz6aYqynh61Vsdy+tiNNkQtc+bN3IvQvRqHkXGUhYkUi+ePKzP0Mb42se7FDb+y2SypTbpbR/Sg==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.13.0.tgz", + "integrity": "sha512-/nz7qFizaBM1SuqAKb7GLkcNn2buRdDgZraXlkhz+vUGiN1NZ9LzkA595tHHeduAiS2MsHqMNhE2zNzGdw43Yg==", "dev": true, "requires": { - "@typescript-eslint/utils": "5.12.1", + "@typescript-eslint/utils": "5.13.0", "debug": "^4.3.2", "tsutils": "^3.21.0" } }, "@typescript-eslint/types": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.12.1.tgz", - "integrity": "sha512-hfcbq4qVOHV1YRdhkDldhV9NpmmAu2vp6wuFODL71Y0Ixak+FLeEU4rnPxgmZMnGreGEghlEucs9UZn5KOfHJA==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.13.0.tgz", + "integrity": "sha512-LmE/KO6DUy0nFY/OoQU0XelnmDt+V8lPQhh8MOVa7Y5k2gGRd6U9Kp3wAjhB4OHg57tUO0nOnwYQhRRyEAyOyg==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.12.1.tgz", - "integrity": "sha512-ahOdkIY9Mgbza7L9sIi205Pe1inCkZWAHE1TV1bpxlU4RZNPtXaDZfiiFWcL9jdxvW1hDYZJXrFm+vlMkXRbBw==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz", + "integrity": "sha512-Q9cQow0DeLjnp5DuEDjLZ6JIkwGx3oYZe+BfcNuw/POhtpcxMTy18Icl6BJqTSd+3ftsrfuVb7mNHRZf7xiaNA==", "dev": true, "requires": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/visitor-keys": "5.13.0", "debug": "^4.3.2", "globby": "^11.0.4", "is-glob": "^4.0.3", @@ -17771,26 +17771,26 @@ } }, "@typescript-eslint/utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.12.1.tgz", - "integrity": "sha512-Qq9FIuU0EVEsi8fS6pG+uurbhNTtoYr4fq8tKjBupsK5Bgbk2I32UGm0Sh+WOyjOPgo/5URbxxSNV6HYsxV4MQ==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.13.0.tgz", + "integrity": "sha512-+9oHlPWYNl6AwwoEt5TQryEHwiKRVjz7Vk6kaBeD3/kwHE5YqTGHtm/JZY8Bo9ITOeKutFaXnBlMgSATMJALUQ==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", + "@typescript-eslint/scope-manager": "5.13.0", + "@typescript-eslint/types": "5.13.0", + "@typescript-eslint/typescript-estree": "5.13.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" } }, "@typescript-eslint/visitor-keys": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.12.1.tgz", - "integrity": "sha512-l1KSLfupuwrXx6wc0AuOmC7Ko5g14ZOQ86wJJqRbdLbXLK02pK/DPiDDqCc7BqqiiA04/eAA6ayL0bgOrAkH7A==", + "version": "5.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.13.0.tgz", + "integrity": "sha512-HLKEAS/qA1V7d9EzcpLFykTePmOQqOFim8oCvhY3pZgQ8Hi38hYpHd9e5GN6nQBFQNecNhws5wkS9Y5XIO0s/g==", "dev": true, "requires": { - "@typescript-eslint/types": "5.12.1", + "@typescript-eslint/types": "5.13.0", "eslint-visitor-keys": "^3.0.0" } }, @@ -18962,13 +18962,13 @@ } }, "cosmiconfig-typescript-loader": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-1.0.5.tgz", - "integrity": "sha512-FL/YR1nb8hyN0bAcP3MBaIoZravfZtVsN/RuPnoo6UVjqIrDxSNIpXHCGgJe0ZWy5yImpyD6jq5wCJ5f1nUv8g==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-1.0.6.tgz", + "integrity": "sha512-2nEotziYJWtNtoTjKbchj9QrdTT6DBxCvqjNKoDKARw+e2yZmTQCa07uRrykLIZuvSgp69YXLH89UHc0WhdMfQ==", "dev": true, "requires": { "cosmiconfig": "^7", - "ts-node": "^10.5.0" + "ts-node": "^10.6.0" } }, "create-require": { @@ -19363,9 +19363,9 @@ } }, "electron-to-chromium": { - "version": "1.4.73", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.73.tgz", - "integrity": "sha512-RlCffXkE/LliqfA5m29+dVDPB2r72y2D2egMMfIy3Le8ODrxjuZNVo4NIC2yPL01N4xb4nZQLwzi6Z5tGIGLnA==", + "version": "1.4.75", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.75.tgz", + "integrity": "sha512-LxgUNeu3BVU7sXaKjUDD9xivocQLxFtq6wgERrutdY/yIOps3ODOZExK1jg8DTEg4U8TUCb5MLGeWFOYuxjF3Q==", "dev": true }, "emittery": { @@ -20803,9 +20803,9 @@ "dev": true }, "has-symbols": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz", - "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true }, "has-tostringtag": { @@ -27173,9 +27173,9 @@ "requires": {} }, "ts-node": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.5.0.tgz", - "integrity": "sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw==", + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.6.0.tgz", + "integrity": "sha512-CJen6+dfOXolxudBQXnVjRVvYTmTWbyz7cn+xq2XTsvnaXbHqr4gXSCNbS2Jj8yTZMuGwUoBESLaOkLascVVvg==", "dev": true, "requires": { "@cspotcode/source-map-support": "0.7.0", @@ -27293,9 +27293,9 @@ } }, "typescript": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", - "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz", + "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==", "dev": true }, "uc.micro": { diff --git a/package.json b/package.json index ed8a6d2..25a990e 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "devDependencies": { "@commitlint/cli": "16.2.1", "@commitlint/config-conventional": "16.2.1", - "@saithodev/semantic-release-backmerge": "2.1.1", + "@saithodev/semantic-release-backmerge": "2.1.2", "@swc/cli": "0.1.55", "@swc/core": "1.2.146", "@swc/jest": "0.2.20", @@ -71,7 +71,7 @@ "@types/ms": "0.7.31", "@types/node": "17.0.21", "@types/nodemailer": "6.4.4", - "@typescript-eslint/eslint-plugin": "5.12.1", + "@typescript-eslint/eslint-plugin": "5.13.0", "concurrently": "7.0.0", "cross-env": "7.0.3", "editorconfig-checker": "4.0.2", @@ -94,6 +94,6 @@ "prisma": "3.10.0", "rimraf": "3.0.2", "semantic-release": "19.0.2", - "typescript": "4.5.5" + "typescript": "4.6.2" } } diff --git a/src/services/channels/[channelId]/__test__/delete.test.ts b/src/services/channels/[channelId]/__test__/delete.test.ts index f025940..8adb8bd 100644 --- a/src/services/channels/[channelId]/__test__/delete.test.ts +++ b/src/services/channels/[channelId]/__test__/delete.test.ts @@ -6,10 +6,15 @@ import { memberExample } from '../../../../models/Member.js' describe('DELETE /channels/[channelId]', () => { it('succeeds', async () => { + const defaultChannelId = 5 prismaMock.channel.findUnique.mockResolvedValue(channelExample) prismaMock.member.findFirst.mockResolvedValue(memberExample) prismaMock.channel.count.mockResolvedValue(2) prismaMock.channel.delete.mockResolvedValue(channelExample) + prismaMock.channel.findFirst.mockResolvedValue({ + ...channelExample, + id: defaultChannelId + }) const { accessToken } = await authenticateUserTest() const response = await application.inject({ method: 'DELETE', @@ -23,6 +28,7 @@ describe('DELETE /channels/[channelId]', () => { expect(responseJson.id).toEqual(channelExample.id) expect(responseJson.name).toEqual(channelExample.name) expect(responseJson.guildId).toEqual(channelExample.guildId) + expect(responseJson.defaultChannelId).toEqual(defaultChannelId) }) it('fails if there is only one channel', async () => { diff --git a/src/services/channels/[channelId]/__test__/put.test.ts b/src/services/channels/[channelId]/__test__/put.test.ts index 94e0825..463647c 100644 --- a/src/services/channels/[channelId]/__test__/put.test.ts +++ b/src/services/channels/[channelId]/__test__/put.test.ts @@ -6,9 +6,14 @@ import { memberExample } from '../../../../models/Member.js' describe('PUT /channels/[channelId]', () => { it('succeeds', async () => { + const defaultChannelId = 5 prismaMock.channel.findUnique.mockResolvedValue(channelExample) prismaMock.member.findFirst.mockResolvedValue(memberExample) prismaMock.channel.update.mockResolvedValue(channelExample) + prismaMock.channel.findFirst.mockResolvedValue({ + ...channelExample, + id: defaultChannelId + }) const { accessToken } = await authenticateUserTest() const response = await application.inject({ method: 'PUT', @@ -23,6 +28,7 @@ describe('PUT /channels/[channelId]', () => { expect(responseJson.id).toEqual(channelExample.id) expect(responseJson.name).toEqual(channelExample.name) expect(responseJson.guildId).toEqual(channelExample.guildId) + expect(responseJson.defaultChannelId).toEqual(defaultChannelId) }) it('fails if the channel is not found', async () => { diff --git a/src/services/channels/[channelId]/delete.ts b/src/services/channels/[channelId]/delete.ts index a3951cc..6b3c43a 100644 --- a/src/services/channels/[channelId]/delete.ts +++ b/src/services/channels/[channelId]/delete.ts @@ -22,7 +22,10 @@ const deleteServiceSchema: FastifySchema = { ] as Array<{ [key: string]: [] }>, params: parametersSchema, response: { - 200: Type.Object(channelSchema), + 200: Type.Object({ + ...channelSchema, + defaultChannelId: channelSchema.id + }), 400: fastifyErrors[400], 401: fastifyErrors[401], 403: fastifyErrors[403], @@ -72,16 +75,26 @@ export const deleteChannelService: FastifyPluginAsync = async (fastify) => { const channel = await prisma.channel.delete({ where: { id: channelId } }) + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: member.guildId } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() + } + const item = { + ...channel, + defaultChannelId: defaultChannel.id + } await fastify.io.emitToMembers({ event: 'channels', guildId: member.guildId, payload: { action: 'delete', - item: channel + item } }) reply.statusCode = 200 - return channel + return item } }) } diff --git a/src/services/channels/[channelId]/put.ts b/src/services/channels/[channelId]/put.ts index 6101cf2..a1b2b83 100644 --- a/src/services/channels/[channelId]/put.ts +++ b/src/services/channels/[channelId]/put.ts @@ -29,7 +29,10 @@ const putServiceSchema: FastifySchema = { params: parametersSchema, body: bodyPutServiceSchema, response: { - 200: Type.Object(channelSchema), + 200: Type.Object({ + ...channelSchema, + defaultChannelId: channelSchema.id + }), 400: fastifyErrors[400], 401: fastifyErrors[401], 403: fastifyErrors[403], @@ -74,16 +77,26 @@ export const putChannelService: FastifyPluginAsync = async (fastify) => { where: { id: channelId }, data: { name } }) + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: member.guildId } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() + } + const item = { + ...channel, + defaultChannelId: defaultChannel.id + } await fastify.io.emitToMembers({ event: 'channels', guildId: member.guildId, payload: { action: 'update', - item: channel + item } }) reply.statusCode = 200 - return channel + return item } }) } diff --git a/src/services/guilds/[guildId]/__test__/delete.test.ts b/src/services/guilds/[guildId]/__test__/delete.test.ts index 267b8fb..70f5f24 100644 --- a/src/services/guilds/[guildId]/__test__/delete.test.ts +++ b/src/services/guilds/[guildId]/__test__/delete.test.ts @@ -8,8 +8,9 @@ describe('DELETE /guilds/[guildId]', () => { it('succeeds and delete the guild', async () => { prismaMock.member.findFirst.mockResolvedValue({ ...memberExample, - isOwner: true - }) + isOwner: true, + guild: guildExample + } as any) prismaMock.guild.delete.mockResolvedValue(guildExample) const { accessToken } = await authenticateUserTest() const response = await application.inject({ @@ -41,8 +42,9 @@ describe('DELETE /guilds/[guildId]', () => { it('fails if the user is not the owner', async () => { prismaMock.member.findFirst.mockResolvedValue({ ...memberExample, - isOwner: false - }) + isOwner: false, + guild: guildExample + } as any) const { accessToken } = await authenticateUserTest() const response = await application.inject({ method: 'DELETE', @@ -52,7 +54,7 @@ describe('DELETE /guilds/[guildId]', () => { } }) const responseJson = response.json() - expect(response.statusCode).toEqual(403) + expect(response.statusCode).toEqual(400) expect(responseJson.message).toEqual('You should be an owner of the guild') }) }) diff --git a/src/services/guilds/[guildId]/__test__/get.test.ts b/src/services/guilds/[guildId]/__test__/get.test.ts index 22eb711..6b94844 100644 --- a/src/services/guilds/[guildId]/__test__/get.test.ts +++ b/src/services/guilds/[guildId]/__test__/get.test.ts @@ -4,14 +4,20 @@ import { prismaMock } from '../../../../__test__/setup.js' import { memberExample } from '../../../../models/Member.js' import { guildExample } from '../../../../models/Guild.js' import { userExample } from '../../../../models/User.js' +import { channelExample } from '../../../../models/Channel.js' describe('GET /guilds/[guildId]', () => { it('succeeds', async () => { + const defaultChannelId = 5 prismaMock.member.findFirst.mockResolvedValue({ ...memberExample, guild: guildExample, user: userExample } as any) + prismaMock.channel.findFirst.mockResolvedValue({ + ...channelExample, + id: defaultChannelId + }) const { accessToken, user } = await authenticateUserTest() const response = await application.inject({ method: 'GET', @@ -25,7 +31,9 @@ describe('GET /guilds/[guildId]', () => { expect(responseJson.member.isOwner).toEqual(memberExample.isOwner) expect(responseJson.member.user.name).toEqual(user.name) expect(responseJson.member.user.email).toBeNull() + expect(responseJson.guild.id).toEqual(guildExample.id) expect(responseJson.guild.name).toEqual(guildExample.name) + expect(responseJson.guild.defaultChannelId).toEqual(defaultChannelId) }) it('fails with not found guild', async () => { diff --git a/src/services/guilds/[guildId]/__test__/put.test.ts b/src/services/guilds/[guildId]/__test__/put.test.ts index 63a46a7..cd10bea 100644 --- a/src/services/guilds/[guildId]/__test__/put.test.ts +++ b/src/services/guilds/[guildId]/__test__/put.test.ts @@ -3,9 +3,11 @@ import { authenticateUserTest } from '../../../../__test__/utils/authenticateUse import { prismaMock } from '../../../../__test__/setup.js' import { guildExample } from '../../../../models/Guild.js' import { memberExample } from '../../../../models/Member.js' +import { channelExample } from '../../../../models/Channel.js' describe('PUT /guilds/[guildId]', () => { it('succeeds and edit the guild', async () => { + const defaultChannelId = 5 const newName = 'New guild name' const newDescription = 'New guild description' prismaMock.member.findFirst.mockResolvedValue({ @@ -18,6 +20,10 @@ describe('PUT /guilds/[guildId]', () => { name: newName, description: newDescription }) + prismaMock.channel.findFirst.mockResolvedValue({ + ...channelExample, + id: defaultChannelId + }) const { accessToken } = await authenticateUserTest() const response = await application.inject({ method: 'PUT', @@ -34,6 +40,7 @@ describe('PUT /guilds/[guildId]', () => { expect(response.statusCode).toEqual(200) expect(responseJson.name).toEqual(newName) expect(responseJson.description).toEqual(newDescription) + expect(responseJson.defaultChannelId).toEqual(defaultChannelId) }) it("fails if the guild doesn't exist", async () => { @@ -76,7 +83,7 @@ describe('PUT /guilds/[guildId]', () => { } }) const responseJson = response.json() - expect(response.statusCode).toEqual(403) + expect(response.statusCode).toEqual(400) expect(responseJson.message).toEqual('You should be an owner of the guild') }) }) diff --git a/src/services/guilds/[guildId]/channels/__test__/post.test.ts b/src/services/guilds/[guildId]/channels/__test__/post.test.ts index a023a4e..cf07f9d 100644 --- a/src/services/guilds/[guildId]/channels/__test__/post.test.ts +++ b/src/services/guilds/[guildId]/channels/__test__/post.test.ts @@ -7,8 +7,13 @@ import { guildExample } from '../../../../../models/Guild.js' describe('POST /guilds/[guildId]/channels', () => { it('succeeds', async () => { + const defaultChannelId = 5 prismaMock.member.findFirst.mockResolvedValue(memberExample) prismaMock.channel.create.mockResolvedValue(channelExample) + prismaMock.channel.findFirst.mockResolvedValue({ + ...channelExample, + id: defaultChannelId + }) const { accessToken } = await authenticateUserTest() const response = await application.inject({ method: 'POST', @@ -23,6 +28,7 @@ describe('POST /guilds/[guildId]/channels', () => { expect(responseJson.id).toEqual(channelExample.id) expect(responseJson.name).toEqual(channelExample.name) expect(responseJson.guildId).toEqual(channelExample.guildId) + expect(responseJson.defaultChannelId).toEqual(defaultChannelId) }) it('fails if the member is not found', async () => { diff --git a/src/services/guilds/[guildId]/channels/post.ts b/src/services/guilds/[guildId]/channels/post.ts index e7691ce..2b651dd 100644 --- a/src/services/guilds/[guildId]/channels/post.ts +++ b/src/services/guilds/[guildId]/channels/post.ts @@ -30,7 +30,10 @@ const postChannelServiceSchema: FastifySchema = { body: bodyPostServiceSchema, params: parametersSchema, response: { - 201: Type.Object(channelSchema), + 201: Type.Object({ + ...channelSchema, + defaultChannelId: channelSchema.id + }), 400: fastifyErrors[400], 401: fastifyErrors[401], 403: fastifyErrors[403], @@ -71,16 +74,26 @@ export const postChannelService: FastifyPluginAsync = async (fastify) => { guildId } }) + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: member.guildId } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() + } + const item = { + ...channel, + defaultChannelId: defaultChannel.id + } await fastify.io.emitToMembers({ event: 'channels', guildId, payload: { action: 'create', - item: channel + item } }) reply.statusCode = 201 - return channel + return item } }) } diff --git a/src/services/guilds/[guildId]/delete.ts b/src/services/guilds/[guildId]/delete.ts index cc01c88..46c29c2 100644 --- a/src/services/guilds/[guildId]/delete.ts +++ b/src/services/guilds/[guildId]/delete.ts @@ -46,23 +46,29 @@ export const deleteGuildByIdService: FastifyPluginAsync = async (fastify) => { } const { guildId } = request.params const member = await prisma.member.findFirst({ - where: { guildId, userId: request.user.current.id } + where: { guildId, userId: request.user.current.id }, + include: { + guild: true + } }) - if (member == null) { + if (member == null || member.guild == null) { throw fastify.httpErrors.notFound('Member not found') } if (!member.isOwner) { - throw fastify.httpErrors.forbidden( + throw fastify.httpErrors.badRequest( 'You should be an owner of the guild' ) } - const guild = await prisma.guild.delete({ - where: { id: member.guildId } - }) await fastify.io.emitToMembers({ event: 'guilds', - guildId: guild.id, - payload: { action: 'delete', item: guild } + guildId: member.guildId, + payload: { + action: 'delete', + item: member.guild + } + }) + const guild = await prisma.guild.delete({ + where: { id: member.guildId } }) reply.statusCode = 200 return guild diff --git a/src/services/guilds/[guildId]/get.ts b/src/services/guilds/[guildId]/get.ts index 3f1a940..0587a07 100644 --- a/src/services/guilds/[guildId]/get.ts +++ b/src/services/guilds/[guildId]/get.ts @@ -7,6 +7,7 @@ import authenticateUser from '../../../tools/plugins/authenticateUser.js' import { guildSchema } from '../../../models/Guild.js' import { memberSchema } from '../../../models/Member.js' import { userPublicWithoutSettingsSchema } from '../../../models/User.js' +import { channelSchema } from '../../../models/Channel.js' const parametersSchema = Type.Object({ guildId: guildSchema.id @@ -25,7 +26,10 @@ const getServiceSchema: FastifySchema = { params: parametersSchema, response: { 200: Type.Object({ - guild: Type.Object(guildSchema), + guild: Type.Object({ + ...guildSchema, + defaultChannelId: channelSchema.id + }), member: Type.Object({ ...memberSchema, user: Type.Object(userPublicWithoutSettingsSchema) @@ -76,9 +80,17 @@ export const getGuildMemberByIdService: FastifyPluginAsync = async ( if (member == null) { throw fastify.httpErrors.notFound('Member not found') } - reply.statusCode = 200 - return { - guild: member.guild, + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: member.guildId } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() + } + const item = { + guild: { + ...member.guild, + defaultChannelId: defaultChannel.id + }, member: { ...member, user: { @@ -87,6 +99,8 @@ export const getGuildMemberByIdService: FastifyPluginAsync = async ( } } } + reply.statusCode = 200 + return item } }) } diff --git a/src/services/guilds/[guildId]/icon/put.ts b/src/services/guilds/[guildId]/icon/put.ts index 32a473f..82f803d 100644 --- a/src/services/guilds/[guildId]/icon/put.ts +++ b/src/services/guilds/[guildId]/icon/put.ts @@ -11,6 +11,7 @@ import { maximumImageSize, supportedImageMimetype } from '../../../../tools/configurations/index.js' +import { channelSchema } from '../../../../models/Channel.js' const parametersSchema = Type.Object({ guildId: guildSchema.id @@ -31,9 +32,8 @@ const putServiceSchema: FastifySchema = { params: parametersSchema, response: { 200: Type.Object({ - guild: Type.Object({ - icon: Type.String() - }) + ...guildSchema, + defaultChannelId: channelSchema.id }), 400: fastifyErrors[400], 401: fastifyErrors[401], @@ -75,12 +75,24 @@ export const putGuildIconById: FastifyPluginAsync = async (fastify) => { where: { id: guildId }, data: { icon: file.pathToStoreInDatabase } }) - reply.statusCode = 200 - return { - guild: { - icon: file.pathToStoreInDatabase - } + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: guild.id } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() } + const item = { + ...guild, + icon: file.pathToStoreInDatabase, + defaultChannelId: defaultChannel.id + } + await fastify.io.emitToMembers({ + event: 'guilds', + guildId: guild.id, + payload: { action: 'update', item } + }) + reply.statusCode = 200 + return item } }) } diff --git a/src/services/guilds/[guildId]/put.ts b/src/services/guilds/[guildId]/put.ts index 2182ed2..dce0d64 100644 --- a/src/services/guilds/[guildId]/put.ts +++ b/src/services/guilds/[guildId]/put.ts @@ -6,6 +6,7 @@ import { fastifyErrors } from '../../../models/utils.js' import authenticateUser from '../../../tools/plugins/authenticateUser.js' import { guildSchema } from '../../../models/Guild.js' import { parseStringNullish } from '../../../tools/utils/parseStringNullish.js' +import { channelSchema } from '../../../models/Channel.js' const parametersSchema = Type.Object({ guildId: guildSchema.id @@ -31,7 +32,10 @@ const putServiceSchema: FastifySchema = { body: bodyPutServiceSchema, params: parametersSchema, response: { - 200: Type.Object(guildSchema), + 200: Type.Object({ + ...guildSchema, + defaultChannelId: channelSchema.id + }), 400: fastifyErrors[400], 401: fastifyErrors[401], 403: fastifyErrors[403], @@ -66,7 +70,7 @@ export const putGuildByIdService: FastifyPluginAsync = async (fastify) => { throw fastify.httpErrors.notFound('Member not found') } if (!member.isOwner) { - throw fastify.httpErrors.forbidden( + throw fastify.httpErrors.badRequest( 'You should be an owner of the guild' ) } @@ -77,13 +81,23 @@ export const putGuildByIdService: FastifyPluginAsync = async (fastify) => { description: parseStringNullish(member.guild.description, description) } }) + const defaultChannel = await prisma.channel.findFirst({ + where: { guildId: guild.id } + }) + if (defaultChannel == null) { + throw fastify.httpErrors.internalServerError() + } + const item = { + ...guild, + defaultChannelId: defaultChannel.id + } await fastify.io.emitToMembers({ event: 'guilds', guildId: guild.id, - payload: { action: 'update', item: guild } + payload: { action: 'update', item } }) reply.statusCode = 200 - return guild + return item } }) }