From 2a33150b6001872e0c13f1a369ddbd1e4a5e0b3d Mon Sep 17 00:00:00 2001 From: "amplication[bot]" Date: Sat, 11 Jan 2025 19:24:42 +0000 Subject: [PATCH] Amplication build # cm5skr2oj000110kqtzuau1c7 Build URL: [https://app.amplication.com/ckyrgxlfa135491801s6vj2ygjn4/ckyrgxqh2135618801s6xmf6elb7/ckyrgxqh2135618801s6xmf6elb7/builds/cm5skr2oj000110kqtzuau1c7](https://app.amplication.com/ckyrgxlfa135491801s6vj2ygjn4/ckyrgxqh2135618801s6xmf6elb7/ckyrgxqh2135618801s6xmf6elb7/builds/cm5skr2oj000110kqtzuau1c7) --- .amplication/ignored/admin-ui/Dockerfile | 2 +- .../ignored/admin-ui/src/post/PostEdit.tsx | 13 ++-- .../ignored/admin-ui/src/post/PostList.tsx | 12 +--- admin-ui/.env | 2 +- admin-ui/README.md | 2 +- admin-ui/configuration/nginx.conf | 2 +- admin-ui/index.html | 21 ++++++ admin-ui/package.json | 67 +++++++------------ admin-ui/public/index.html | 44 ------------ admin-ui/src/App.tsx | 15 +---- admin-ui/src/Login.tsx | 41 +----------- admin-ui/src/LoginForm.tsx | 48 +++++++++++++ admin-ui/src/author/AuthorCreate.tsx | 13 ++-- admin-ui/src/author/AuthorEdit.tsx | 13 ++-- admin-ui/src/author/AuthorList.tsx | 12 +--- admin-ui/src/author/AuthorShow.tsx | 2 +- .../src/data-provider/graphqlDataProvider.ts | 2 +- admin-ui/src/index.tsx | 15 +---- admin-ui/src/pages/Dashboard.tsx | 4 +- admin-ui/src/post/PostCreate.tsx | 13 ++-- admin-ui/src/story/StoryList.tsx | 12 +--- admin-ui/src/tag/TagCreate.tsx | 13 ++-- admin-ui/src/tag/TagEdit.tsx | 13 ++-- admin-ui/src/tag/TagList.tsx | 12 +--- admin-ui/src/theme/theme.ts | 4 +- admin-ui/src/user/RolesOptions.ts | 1 - admin-ui/src/user/UserList.tsx | 12 +--- admin-ui/src/vite-env.d.ts | 1 + admin-ui/vite.config.ts | 14 ++++ server/.env | 10 +-- server/README.md | 2 +- server/docker-compose.yml | 2 +- server/nest-cli.json | 6 +- server/package.json | 7 +- server/src/auth/IAuthStrategy.ts | 1 + server/src/auth/acl.module.ts | 3 +- server/src/auth/gqlDefaultAuth.guard.ts | 2 - server/src/auth/token.service.ts | 4 +- server/src/author/base/Author.ts | 13 +++- server/src/author/base/AuthorCreateInput.ts | 12 +++- server/src/author/base/AuthorUpdateInput.ts | 12 +++- server/src/author/base/author.service.base.ts | 37 ++++------ server/src/post/base/Post.ts | 7 ++ server/src/post/base/PostCreateInput.ts | 7 ++ server/src/post/base/PostUpdateInput.ts | 7 ++ server/src/post/base/post.service.base.ts | 39 ++++------- server/src/story/base/Story.ts | 16 ++++- server/src/story/base/StoryCreateInput.ts | 16 ++++- server/src/story/base/StoryUpdateInput.ts | 16 ++++- server/src/story/base/story.service.base.ts | 30 +++------ server/src/tag/base/Tag.ts | 10 ++- server/src/tag/base/TagCreateInput.ts | 9 ++- server/src/tag/base/TagUpdateInput.ts | 9 ++- server/src/tag/base/tag.service.base.ts | 37 +++------- .../src/tests/auth/jwt/jwt.strategy.spec.ts | 4 +- server/src/user/base/User.ts | 4 +- server/src/user/base/UserCreateInput.ts | 4 +- server/src/user/base/UserUpdateInput.ts | 4 +- server/src/user/base/user.service.base.ts | 30 +++------ 59 files changed, 387 insertions(+), 398 deletions(-) create mode 100644 admin-ui/index.html delete mode 100644 admin-ui/public/index.html create mode 100644 admin-ui/src/LoginForm.tsx create mode 100644 admin-ui/src/vite-env.d.ts create mode 100644 admin-ui/vite.config.ts diff --git a/.amplication/ignored/admin-ui/Dockerfile b/.amplication/ignored/admin-ui/Dockerfile index 9c43e40..0911e21 100644 --- a/.amplication/ignored/admin-ui/Dockerfile +++ b/.amplication/ignored/admin-ui/Dockerfile @@ -44,7 +44,7 @@ RUN chown -R nginx:nginx /var/run/nginx.pid \ USER nginx # expose a specific port on the docker container -ENV PORT=80 +ENV PORT=3001 EXPOSE ${PORT} # start the server using the previously build application diff --git a/.amplication/ignored/admin-ui/src/post/PostEdit.tsx b/.amplication/ignored/admin-ui/src/post/PostEdit.tsx index 11692ac..c426973 100644 --- a/.amplication/ignored/admin-ui/src/post/PostEdit.tsx +++ b/.amplication/ignored/admin-ui/src/post/PostEdit.tsx @@ -30,13 +30,12 @@ export const PostEdit = (props: EditProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/.amplication/ignored/admin-ui/src/post/PostList.tsx b/.amplication/ignored/admin-ui/src/post/PostList.tsx index 8096151..ad21d9a 100644 --- a/.amplication/ignored/admin-ui/src/post/PostList.tsx +++ b/.amplication/ignored/admin-ui/src/post/PostList.tsx @@ -15,14 +15,8 @@ import { AUTHOR_TITLE_FIELD } from "../author/AuthorTitle"; export const PostList = (props: ListProps): React.ReactElement => { return ( - } - > - + }> + @@ -36,7 +30,7 @@ export const PostList = (props: ListProps): React.ReactElement => { - + {" "} ); diff --git a/admin-ui/.env b/admin-ui/.env index 4eef91c..e96bc90 100644 --- a/admin-ui/.env +++ b/admin-ui/.env @@ -1,2 +1,2 @@ PORT=3001 -REACT_APP_SERVER_URL=http://localhost:3000 \ No newline at end of file +VITE_REACT_APP_SERVER_URL=http://localhost:3000 \ No newline at end of file diff --git a/admin-ui/README.md b/admin-ui/README.md index 03abb2a..cc7c387 100644 --- a/admin-ui/README.md +++ b/admin-ui/README.md @@ -1,6 +1,6 @@

- amplication-logo + amplication-logo

diff --git a/admin-ui/configuration/nginx.conf b/admin-ui/configuration/nginx.conf index 88dad6e..c907b5c 100644 --- a/admin-ui/configuration/nginx.conf +++ b/admin-ui/configuration/nginx.conf @@ -1,7 +1,7 @@ server_tokens off; server { - listen 8080; + listen 3001; server_name localhost; location / { root /usr/share/nginx/html; diff --git a/admin-ui/index.html b/admin-ui/index.html new file mode 100644 index 0000000..11ef7c7 --- /dev/null +++ b/admin-ui/index.html @@ -0,0 +1,21 @@ + + + + + + + + + + Amplication Blog + + + +
+ + + diff --git a/admin-ui/package.json b/admin-ui/package.json index 8f291cd..cbb4da9 100644 --- a/admin-ui/package.json +++ b/admin-ui/package.json @@ -3,58 +3,39 @@ "private": true, "dependencies": { "@apollo/client": "3.6.9", - "@material-ui/core": "4.12.4", "graphql": "15.6.1", "lodash": "4.17.21", "pluralize": "8.0.0", - "ra-data-graphql-amplication": "0.0.14", - "react": "16.14.0", - "react-admin": "3.19.12", - "react-dom": "16.14.0", - "react-scripts": "5.0.0", - "sass": "^1.39.0", - "web-vitals": "1.1.2" - }, - "overrides": { - "react-scripts": { - "@svgr/webpack": "6.5.1" - } + "ra-data-graphql-amplication": "1.0.2", + "react": "^18.3.0", + "react-admin": "^5.1.0", + "react-dom": "^18.3.0", + "sass": "^1.39.0" }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject", + "start": "vite", + "build": "vite build", + "serve": "vite preview", + "type-check": "tsc --noEmit", + "lint": "eslint --fix --ext .js,.jsx,.ts,.tsx ./src", + "format": "prettier --write ./src", "package:container": "docker build ." }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, "devDependencies": { - "@testing-library/jest-dom": "5.14.1", - "@testing-library/react": "11.2.7", - "@testing-library/user-event": "13.2.0", - "@types/jest": "26.0.16", "@types/lodash": "4.14.178", - "@types/node": "12.20.16", - "@types/react": "16.14.11", - "@types/react-dom": "17.0.0", + "@types/node": "^20.10.7", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", + "@typescript-eslint/eslint-plugin": "^5.60.1", + "@typescript-eslint/parser": "^5.60.1", + "@vitejs/plugin-react": "^4.0.1", + "eslint": "^8.43.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", + "prettier": "^2.8.8", "type-fest": "0.13.1", - "typescript": "4.3.5" + "typescript": "^5.1.6", + "vite": "^4.3.9" } } \ No newline at end of file diff --git a/admin-ui/public/index.html b/admin-ui/public/index.html deleted file mode 100644 index 38cbd65..0000000 --- a/admin-ui/public/index.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - Amplication Blog - - - -
- - - diff --git a/admin-ui/src/App.tsx b/admin-ui/src/App.tsx index ae7a792..393aa63 100644 --- a/admin-ui/src/App.tsx +++ b/admin-ui/src/App.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import { Admin, DataProvider, Resource } from "react-admin"; -import buildGraphQLProvider from "./data-provider/graphqlDataProvider"; +import dataProvider from "./data-provider/graphqlDataProvider"; import { theme } from "./theme/theme"; import Login from "./Login"; import "./App.scss"; @@ -28,19 +28,6 @@ import { StoryShow } from "./story/StoryShow"; import { jwtAuthProvider } from "./auth-provider/ra-auth-jwt"; const App = (): React.ReactElement => { - const [dataProvider, setDataProvider] = useState(null); - useEffect(() => { - buildGraphQLProvider - .then((provider: any) => { - setDataProvider(() => provider); - }) - .catch((error: any) => { - console.log(error); - }); - }, []); - if (!dataProvider) { - return
Loading
; - } return (
{ - const [username, setUsername] = useState(""); - const [password, setPassword] = useState(""); - const login = useLogin(); - const notify = useNotify(); const BASE_URI = process.env.REACT_APP_SERVER_URL; - const submit = (e: any) => { - e.preventDefault(); - login({ username, password }).catch(() => - notify("Invalid username or password") - ); - }; return ( @@ -54,31 +43,7 @@ const Login = ({ theme }: any) => { Sign in to a React-Admin client with ready-made forms for creating and editing all the data models of your application
-
- - - -
+
{ + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const login = useLogin(); + const notify = useNotify(); + const BASE_URI = process.env.REACT_APP_SERVER_URL; + const submit = (e: any) => { + e.preventDefault(); + login({ username, password }).catch(() => + notify("Invalid username or password") + ); + }; + + return ( +
+ + + +
+ ); +}; + +export default LoginForm; diff --git a/admin-ui/src/author/AuthorCreate.tsx b/admin-ui/src/author/AuthorCreate.tsx index 3f93478..61d3edb 100644 --- a/admin-ui/src/author/AuthorCreate.tsx +++ b/admin-ui/src/author/AuthorCreate.tsx @@ -17,13 +17,12 @@ export const AuthorCreate = (props: CreateProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/admin-ui/src/author/AuthorEdit.tsx b/admin-ui/src/author/AuthorEdit.tsx index 1dbeecb..bd22478 100644 --- a/admin-ui/src/author/AuthorEdit.tsx +++ b/admin-ui/src/author/AuthorEdit.tsx @@ -17,13 +17,12 @@ export const AuthorEdit = (props: EditProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/admin-ui/src/author/AuthorList.tsx b/admin-ui/src/author/AuthorList.tsx index 2c9be98..3eb5309 100644 --- a/admin-ui/src/author/AuthorList.tsx +++ b/admin-ui/src/author/AuthorList.tsx @@ -4,14 +4,8 @@ import Pagination from "../Components/Pagination"; export const AuthorList = (props: ListProps): React.ReactElement => { return ( - } - > - + }> + @@ -19,7 +13,7 @@ export const AuthorList = (props: ListProps): React.ReactElement => { - + {" "} ); diff --git a/admin-ui/src/author/AuthorShow.tsx b/admin-ui/src/author/AuthorShow.tsx index 5235d64..f5d8696 100644 --- a/admin-ui/src/author/AuthorShow.tsx +++ b/admin-ui/src/author/AuthorShow.tsx @@ -27,7 +27,7 @@ export const AuthorShow = (props: ShowProps): React.ReactElement => { - + - , - document.getElementById("root") + ); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); diff --git a/admin-ui/src/pages/Dashboard.tsx b/admin-ui/src/pages/Dashboard.tsx index 39c4d18..29776bc 100644 --- a/admin-ui/src/pages/Dashboard.tsx +++ b/admin-ui/src/pages/Dashboard.tsx @@ -1,6 +1,6 @@ import * as React from "react"; -import Card from "@material-ui/core/Card"; -import CardContent from "@material-ui/core/CardContent"; +import Card from "@mui/material/Card"; +import CardContent from "@mui/material/CardContent"; import { Title } from "react-admin"; const Dashboard = () => ( diff --git a/admin-ui/src/post/PostCreate.tsx b/admin-ui/src/post/PostCreate.tsx index 2fab91f..0569159 100644 --- a/admin-ui/src/post/PostCreate.tsx +++ b/admin-ui/src/post/PostCreate.tsx @@ -30,13 +30,12 @@ export const PostCreate = (props: CreateProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/admin-ui/src/story/StoryList.tsx b/admin-ui/src/story/StoryList.tsx index 3d5c735..19a4d39 100644 --- a/admin-ui/src/story/StoryList.tsx +++ b/admin-ui/src/story/StoryList.tsx @@ -11,14 +11,8 @@ import Pagination from "../Components/Pagination"; export const StoryList = (props: ListProps): React.ReactElement => { return ( - } - > - + }> + @@ -31,7 +25,7 @@ export const StoryList = (props: ListProps): React.ReactElement => { - + {" "} ); diff --git a/admin-ui/src/tag/TagCreate.tsx b/admin-ui/src/tag/TagCreate.tsx index 741833b..969b65a 100644 --- a/admin-ui/src/tag/TagCreate.tsx +++ b/admin-ui/src/tag/TagCreate.tsx @@ -16,13 +16,12 @@ export const TagCreate = (props: CreateProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/admin-ui/src/tag/TagEdit.tsx b/admin-ui/src/tag/TagEdit.tsx index 7159f64..28303e6 100644 --- a/admin-ui/src/tag/TagEdit.tsx +++ b/admin-ui/src/tag/TagEdit.tsx @@ -16,13 +16,12 @@ export const TagEdit = (props: EditProps): React.ReactElement => { - value && value.map((v: any) => ({ id: v }))} - format={(value: any) => value && value.map((v: any) => v.id)} - > - + + value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> diff --git a/admin-ui/src/tag/TagList.tsx b/admin-ui/src/tag/TagList.tsx index 9592f7a..b729fbb 100644 --- a/admin-ui/src/tag/TagList.tsx +++ b/admin-ui/src/tag/TagList.tsx @@ -4,19 +4,13 @@ import Pagination from "../Components/Pagination"; export const TagList = (props: ListProps): React.ReactElement => { return ( - } - > - + }> + - + {" "} ); diff --git a/admin-ui/src/theme/theme.ts b/admin-ui/src/theme/theme.ts index 56a1153..bcfca0e 100644 --- a/admin-ui/src/theme/theme.ts +++ b/admin-ui/src/theme/theme.ts @@ -1,7 +1,7 @@ import { defaultTheme } from "react-admin"; -import { createTheme, ThemeOptions } from "@material-ui/core/styles"; +import { createTheme, ThemeOptions } from "@mui/material/styles"; import { merge } from "lodash"; -import createPalette from "@material-ui/core/styles/createPalette"; +import createPalette from "@mui/material/styles/createPalette"; const palette = createPalette( merge({}, defaultTheme.palette, { diff --git a/admin-ui/src/user/RolesOptions.ts b/admin-ui/src/user/RolesOptions.ts index 2f12fcf..5e30fe9 100644 --- a/admin-ui/src/user/RolesOptions.ts +++ b/admin-ui/src/user/RolesOptions.ts @@ -1,4 +1,3 @@ -//@ts-ignore import { ROLES } from "./roles"; declare interface Role { diff --git a/admin-ui/src/user/UserList.tsx b/admin-ui/src/user/UserList.tsx index aa820f4..c5adf63 100644 --- a/admin-ui/src/user/UserList.tsx +++ b/admin-ui/src/user/UserList.tsx @@ -4,21 +4,15 @@ import Pagination from "../Components/Pagination"; export const UserList = (props: ListProps): React.ReactElement => { return ( - } - > - + }> + - + {" "} ); diff --git a/admin-ui/src/vite-env.d.ts b/admin-ui/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/admin-ui/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/admin-ui/vite.config.ts b/admin-ui/vite.config.ts new file mode 100644 index 0000000..cf64d08 --- /dev/null +++ b/admin-ui/vite.config.ts @@ -0,0 +1,14 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], + define: { + "process.env": process.env, + }, + server: { + host: true, + }, + base: "./", +}); diff --git a/server/.env b/server/.env index 0cc8cc2..c1e11ce 100644 --- a/server/.env +++ b/server/.env @@ -1,10 +1,10 @@ BCRYPT_SALT=10 COMPOSE_PROJECT_NAME=amp_ckyrgxqh2135618801s6xmf6elb7 -PORT=3000 -DB_URL=postgres://admin:admin@localhost:5432/my-db -DB_USER=admin +DB_NAME=my-db DB_PASSWORD=admin DB_PORT=5432 -DB_NAME=my-db +DB_URL=postgres://admin:admin@localhost:5432/my-db +DB_USER=admin +JWT_EXPIRATION=2d JWT_SECRET_KEY=Change_ME!!! -JWT_EXPIRATION=2d \ No newline at end of file +PORT=3000 \ No newline at end of file diff --git a/server/README.md b/server/README.md index 6db8e75..bca0445 100644 --- a/server/README.md +++ b/server/README.md @@ -1,6 +1,6 @@

- amplication-logo + amplication-logo

diff --git a/server/docker-compose.yml b/server/docker-compose.yml index 189f745..2a466f3 100644 --- a/server/docker-compose.yml +++ b/server/docker-compose.yml @@ -9,9 +9,9 @@ services: - ${PORT}:3000 environment: BCRYPT_SALT: ${BCRYPT_SALT} - DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME} JWT_SECRET_KEY: ${JWT_SECRET_KEY} JWT_EXPIRATION: ${JWT_EXPIRATION} + DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME} depends_on: - migrate restart: on-failure diff --git a/server/nest-cli.json b/server/nest-cli.json index fe51713..b7b60ae 100644 --- a/server/nest-cli.json +++ b/server/nest-cli.json @@ -1,6 +1,10 @@ { "sourceRoot": "src", "compilerOptions": { - "assets": ["swagger"] + "assets": [ + { + "include": "swagger/**/*" + } + ] } } diff --git a/server/package.json b/server/package.json index 6ee9cc7..93b6bd3 100644 --- a/server/package.json +++ b/server/package.json @@ -44,7 +44,7 @@ "passport-http": "0.3.0", "passport-jwt": "4.0.1", "reflect-metadata": "0.1.13", - "ts-node": "10.9.1", + "ts-node": "10.9.2", "type-fest": "2.19.0", "validator": "13.11.0" }, @@ -64,11 +64,14 @@ "prisma": "^5.4.2", "supertest": "^6.3.3", "ts-jest": "^29.1.1", - "typescript": "^5.2.2" + "typescript": "^5.4.3" }, "jest": { "preset": "ts-jest", "testEnvironment": "node", + "moduleNameMapper": { + "@app/custom-validators": "/src/validators" + }, "modulePathIgnorePatterns": ["/dist/"] } } diff --git a/server/src/auth/IAuthStrategy.ts b/server/src/auth/IAuthStrategy.ts index 5db10cf..7406267 100644 --- a/server/src/auth/IAuthStrategy.ts +++ b/server/src/auth/IAuthStrategy.ts @@ -1,5 +1,6 @@ import { UserInfo } from "./UserInfo"; export interface IAuthStrategy { + // eslint-disable-next-line @typescript-eslint/no-explicit-any validate: (...any: any) => Promise; } diff --git a/server/src/auth/acl.module.ts b/server/src/auth/acl.module.ts index eb90005..040e7e5 100644 --- a/server/src/auth/acl.module.ts +++ b/server/src/auth/acl.module.ts @@ -1,6 +1,5 @@ import { AccessControlModule, RolesBuilder } from "nest-access-control"; -// @ts-ignore -// eslint-disable-next-line import/no-unresolved + import grants from "../grants.json"; // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/server/src/auth/gqlDefaultAuth.guard.ts b/server/src/auth/gqlDefaultAuth.guard.ts index 0455177..abebd93 100644 --- a/server/src/auth/gqlDefaultAuth.guard.ts +++ b/server/src/auth/gqlDefaultAuth.guard.ts @@ -1,8 +1,6 @@ import { ExecutionContext } from "@nestjs/common"; import { GqlExecutionContext } from "@nestjs/graphql"; import type { Request } from "express"; -// @ts-ignore -// eslint-disable-next-line import { DefaultAuthGuard } from "./defaultAuth.guard"; export class GqlDefaultAuthGuard extends DefaultAuthGuard { diff --git a/server/src/auth/token.service.ts b/server/src/auth/token.service.ts index b102b72..2ee079c 100644 --- a/server/src/auth/token.service.ts +++ b/server/src/auth/token.service.ts @@ -1,7 +1,5 @@ -//@ts-ignore import { ITokenService } from "./ITokenService"; -// eslint-disable-next-line import/no-unresolved -//@ts-ignore + import { TokenServiceBase } from "./base/token.service.base"; export class TokenService extends TokenServiceBase implements ITokenService {} diff --git a/server/src/author/base/Author.ts b/server/src/author/base/Author.ts index c3beaee..2bdb62d 100644 --- a/server/src/author/base/Author.ts +++ b/server/src/author/base/Author.ts @@ -11,7 +11,13 @@ https://docs.amplication.com/how-to/custom-code */ import { ObjectType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsDate, IsString, IsOptional, ValidateNested } from "class-validator"; +import { + IsDate, + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; import { Type } from "class-transformer"; import { Post } from "../../post/base/Post"; @@ -30,6 +36,7 @@ class Author { type: String, }) @IsString() + @MaxLength(1000) @Field(() => String) firstName!: string; @@ -46,6 +53,7 @@ class Author { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -66,6 +74,7 @@ class Author { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -77,6 +86,7 @@ class Author { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -88,6 +98,7 @@ class Author { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/author/base/AuthorCreateInput.ts b/server/src/author/base/AuthorCreateInput.ts index f90fb84..4489abd 100644 --- a/server/src/author/base/AuthorCreateInput.ts +++ b/server/src/author/base/AuthorCreateInput.ts @@ -11,7 +11,12 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, ValidateNested } from "class-validator"; +import { + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; import { PostCreateNestedManyWithoutAuthorsInput } from "./PostCreateNestedManyWithoutAuthorsInput"; import { Type } from "class-transformer"; @@ -22,6 +27,7 @@ class AuthorCreateInput { type: String, }) @IsString() + @MaxLength(1000) @Field(() => String) firstName!: string; @@ -30,6 +36,7 @@ class AuthorCreateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -53,6 +60,7 @@ class AuthorCreateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -64,6 +72,7 @@ class AuthorCreateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -75,6 +84,7 @@ class AuthorCreateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/author/base/AuthorUpdateInput.ts b/server/src/author/base/AuthorUpdateInput.ts index b82974a..f5c2086 100644 --- a/server/src/author/base/AuthorUpdateInput.ts +++ b/server/src/author/base/AuthorUpdateInput.ts @@ -11,7 +11,12 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, ValidateNested } from "class-validator"; +import { + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; import { PostUpdateManyWithoutAuthorsInput } from "./PostUpdateManyWithoutAuthorsInput"; import { Type } from "class-transformer"; @@ -22,6 +27,7 @@ class AuthorUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -33,6 +39,7 @@ class AuthorUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -56,6 +63,7 @@ class AuthorUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -67,6 +75,7 @@ class AuthorUpdateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -78,6 +87,7 @@ class AuthorUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/author/base/author.service.base.ts b/server/src/author/base/author.service.base.ts index ad3ae34..1910a23 100644 --- a/server/src/author/base/author.service.base.ts +++ b/server/src/author/base/author.service.base.ts @@ -10,52 +10,41 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; - import { Prisma, - Author, // @ts-ignore - Post, + Author as PrismaAuthor, + Post as PrismaPost, } from "@prisma/client"; export class AuthorServiceBase { constructor(protected readonly prisma: PrismaService) {} - async count( - args: Prisma.SelectSubset - ): Promise { + async count(args: Omit): Promise { return this.prisma.author.count(args); } - async authors( - args: Prisma.SelectSubset - ): Promise { + async authors(args: Prisma.AuthorFindManyArgs): Promise { return this.prisma.author.findMany(args); } - async author( - args: Prisma.SelectSubset - ): Promise { + async author( + args: Prisma.AuthorFindUniqueArgs + ): Promise { return this.prisma.author.findUnique(args); } - async createAuthor( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.author.create(args); + async createAuthor(args: Prisma.AuthorCreateArgs): Promise { + return this.prisma.author.create(args); } - async updateAuthor( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.author.update(args); + async updateAuthor(args: Prisma.AuthorUpdateArgs): Promise { + return this.prisma.author.update(args); } - async deleteAuthor( - args: Prisma.SelectSubset - ): Promise { + async deleteAuthor(args: Prisma.AuthorDeleteArgs): Promise { return this.prisma.author.delete(args); } async findPosts( parentId: string, args: Prisma.PostFindManyArgs - ): Promise { + ): Promise { return this.prisma.author .findUniqueOrThrow({ where: { id: parentId }, diff --git a/server/src/post/base/Post.ts b/server/src/post/base/Post.ts index 8d1d7d2..af68ab5 100644 --- a/server/src/post/base/Post.ts +++ b/server/src/post/base/Post.ts @@ -15,6 +15,7 @@ import { Author } from "../../author/base/Author"; import { ValidateNested, IsString, + MaxLength, IsDate, IsBoolean, IsOptional, @@ -37,6 +38,7 @@ class Post { type: String, }) @IsString() + @MaxLength(99999999) @Field(() => String) content!: string; @@ -64,6 +66,7 @@ class Post { type: String, }) @IsString() + @MaxLength(5000) @Field(() => String) featuredImage!: string; @@ -80,6 +83,7 @@ class Post { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -91,6 +95,7 @@ class Post { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -113,6 +118,7 @@ class Post { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -133,6 +139,7 @@ class Post { type: String, }) @IsString() + @MaxLength(500) @Field(() => String) title!: string; diff --git a/server/src/post/base/PostCreateInput.ts b/server/src/post/base/PostCreateInput.ts index 9ebb375..5cd5741 100644 --- a/server/src/post/base/PostCreateInput.ts +++ b/server/src/post/base/PostCreateInput.ts @@ -15,6 +15,7 @@ import { AuthorWhereUniqueInput } from "../../author/base/AuthorWhereUniqueInput import { ValidateNested, IsString, + MaxLength, IsBoolean, IsOptional, IsDate, @@ -38,6 +39,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(99999999) @Field(() => String) content!: string; @@ -57,6 +59,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(5000) @Field(() => String) featuredImage!: string; @@ -65,6 +68,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -76,6 +80,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -98,6 +103,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -121,6 +127,7 @@ class PostCreateInput { type: String, }) @IsString() + @MaxLength(500) @Field(() => String) title!: string; } diff --git a/server/src/post/base/PostUpdateInput.ts b/server/src/post/base/PostUpdateInput.ts index 88fa888..f6e1179 100644 --- a/server/src/post/base/PostUpdateInput.ts +++ b/server/src/post/base/PostUpdateInput.ts @@ -16,6 +16,7 @@ import { ValidateNested, IsOptional, IsString, + MaxLength, IsBoolean, IsDate, } from "class-validator"; @@ -41,6 +42,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(99999999) @IsOptional() @Field(() => String, { nullable: true, @@ -63,6 +65,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(5000) @IsOptional() @Field(() => String, { nullable: true, @@ -74,6 +77,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -85,6 +89,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -107,6 +112,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, @@ -130,6 +136,7 @@ class PostUpdateInput { type: String, }) @IsString() + @MaxLength(500) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/post/base/post.service.base.ts b/server/src/post/base/post.service.base.ts index 4ff5ed1..b53b671 100644 --- a/server/src/post/base/post.service.base.ts +++ b/server/src/post/base/post.service.base.ts @@ -10,53 +10,40 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; - import { Prisma, - Post, // @ts-ignore - Tag, // @ts-ignore - Author, + Post as PrismaPost, + Tag as PrismaTag, + Author as PrismaAuthor, } from "@prisma/client"; export class PostServiceBase { constructor(protected readonly prisma: PrismaService) {} - async count( - args: Prisma.SelectSubset - ): Promise { + async count(args: Omit): Promise { return this.prisma.post.count(args); } - async posts( - args: Prisma.SelectSubset - ): Promise { + async posts(args: Prisma.PostFindManyArgs): Promise { return this.prisma.post.findMany(args); } - async post( - args: Prisma.SelectSubset - ): Promise { + async post(args: Prisma.PostFindUniqueArgs): Promise { return this.prisma.post.findUnique(args); } - async createPost( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.post.create(args); + async createPost(args: Prisma.PostCreateArgs): Promise { + return this.prisma.post.create(args); } - async updatePost( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.post.update(args); + async updatePost(args: Prisma.PostUpdateArgs): Promise { + return this.prisma.post.update(args); } - async deletePost( - args: Prisma.SelectSubset - ): Promise { + async deletePost(args: Prisma.PostDeleteArgs): Promise { return this.prisma.post.delete(args); } async findTags( parentId: string, args: Prisma.TagFindManyArgs - ): Promise { + ): Promise { return this.prisma.post .findUniqueOrThrow({ where: { id: parentId }, @@ -64,7 +51,7 @@ export class PostServiceBase { .tags(args); } - async getAuthor(parentId: string): Promise { + async getAuthor(parentId: string): Promise { return this.prisma.post .findUnique({ where: { id: parentId }, diff --git a/server/src/story/base/Story.ts b/server/src/story/base/Story.ts index 3feefd8..bee68fd 100644 --- a/server/src/story/base/Story.ts +++ b/server/src/story/base/Story.ts @@ -11,7 +11,13 @@ https://docs.amplication.com/how-to/custom-code */ import { ObjectType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsDate, IsOptional, IsBoolean } from "class-validator"; +import { + IsString, + MaxLength, + IsDate, + IsOptional, + IsBoolean, +} from "class-validator"; import { Type } from "class-transformer"; @ObjectType() @@ -21,6 +27,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) content!: string; @@ -37,6 +44,7 @@ class Story { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -59,6 +67,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) featuredImage!: string; @@ -75,6 +84,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -86,6 +96,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -108,6 +119,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -119,6 +131,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) tag!: string; @@ -127,6 +140,7 @@ class Story { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) title!: string; diff --git a/server/src/story/base/StoryCreateInput.ts b/server/src/story/base/StoryCreateInput.ts index 4590422..d030291 100644 --- a/server/src/story/base/StoryCreateInput.ts +++ b/server/src/story/base/StoryCreateInput.ts @@ -11,7 +11,13 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, IsBoolean, IsDate } from "class-validator"; +import { + IsString, + MaxLength, + IsOptional, + IsBoolean, + IsDate, +} from "class-validator"; import { Type } from "class-transformer"; @InputType() @@ -21,6 +27,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) content!: string; @@ -29,6 +36,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -51,6 +59,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) featuredImage!: string; @@ -59,6 +68,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -70,6 +80,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -92,6 +103,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -103,6 +115,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) tag!: string; @@ -111,6 +124,7 @@ class StoryCreateInput { type: String, }) @IsString() + @MaxLength(256) @Field(() => String) title!: string; } diff --git a/server/src/story/base/StoryUpdateInput.ts b/server/src/story/base/StoryUpdateInput.ts index aa1dfef..89b4079 100644 --- a/server/src/story/base/StoryUpdateInput.ts +++ b/server/src/story/base/StoryUpdateInput.ts @@ -11,7 +11,13 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, IsBoolean, IsDate } from "class-validator"; +import { + IsString, + MaxLength, + IsOptional, + IsBoolean, + IsDate, +} from "class-validator"; import { Type } from "class-transformer"; @InputType() @@ -21,6 +27,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -32,6 +39,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -54,6 +62,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -65,6 +74,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -76,6 +86,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -98,6 +109,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -109,6 +121,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -120,6 +133,7 @@ class StoryUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/story/base/story.service.base.ts b/server/src/story/base/story.service.base.ts index ab3a389..9a097fe 100644 --- a/server/src/story/base/story.service.base.ts +++ b/server/src/story/base/story.service.base.ts @@ -10,40 +10,28 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; -import { Prisma, Story } from "@prisma/client"; +import { Prisma, Story as PrismaStory } from "@prisma/client"; export class StoryServiceBase { constructor(protected readonly prisma: PrismaService) {} - async count( - args: Prisma.SelectSubset - ): Promise { + async count(args: Omit): Promise { return this.prisma.story.count(args); } - async stories( - args: Prisma.SelectSubset - ): Promise { + async stories(args: Prisma.StoryFindManyArgs): Promise { return this.prisma.story.findMany(args); } - async story( - args: Prisma.SelectSubset - ): Promise { + async story(args: Prisma.StoryFindUniqueArgs): Promise { return this.prisma.story.findUnique(args); } - async createStory( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.story.create(args); + async createStory(args: Prisma.StoryCreateArgs): Promise { + return this.prisma.story.create(args); } - async updateStory( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.story.update(args); + async updateStory(args: Prisma.StoryUpdateArgs): Promise { + return this.prisma.story.update(args); } - async deleteStory( - args: Prisma.SelectSubset - ): Promise { + async deleteStory(args: Prisma.StoryDeleteArgs): Promise { return this.prisma.story.delete(args); } } diff --git a/server/src/tag/base/Tag.ts b/server/src/tag/base/Tag.ts index 5656491..b7e44c3 100644 --- a/server/src/tag/base/Tag.ts +++ b/server/src/tag/base/Tag.ts @@ -11,7 +11,13 @@ https://docs.amplication.com/how-to/custom-code */ import { ObjectType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsDate, IsString, ValidateNested, IsOptional } from "class-validator"; +import { + IsDate, + IsString, + MaxLength, + ValidateNested, + IsOptional, +} from "class-validator"; import { Type } from "class-transformer"; import { Post } from "../../post/base/Post"; @@ -38,6 +44,7 @@ class Tag { type: String, }) @IsString() + @MaxLength(1000) @Field(() => String) name!: string; @@ -55,6 +62,7 @@ class Tag { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/tag/base/TagCreateInput.ts b/server/src/tag/base/TagCreateInput.ts index b5f1e9f..247baec 100644 --- a/server/src/tag/base/TagCreateInput.ts +++ b/server/src/tag/base/TagCreateInput.ts @@ -11,7 +11,12 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, ValidateNested, IsOptional } from "class-validator"; +import { + IsString, + MaxLength, + ValidateNested, + IsOptional, +} from "class-validator"; import { PostCreateNestedManyWithoutTagsInput } from "./PostCreateNestedManyWithoutTagsInput"; import { Type } from "class-transformer"; @@ -22,6 +27,7 @@ class TagCreateInput { type: String, }) @IsString() + @MaxLength(1000) @Field(() => String) name!: string; @@ -42,6 +48,7 @@ class TagCreateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/tag/base/TagUpdateInput.ts b/server/src/tag/base/TagUpdateInput.ts index 2a15891..f27f41c 100644 --- a/server/src/tag/base/TagUpdateInput.ts +++ b/server/src/tag/base/TagUpdateInput.ts @@ -11,7 +11,12 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional, ValidateNested } from "class-validator"; +import { + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; import { PostUpdateManyWithoutTagsInput } from "./PostUpdateManyWithoutTagsInput"; import { Type } from "class-transformer"; @@ -22,6 +27,7 @@ class TagUpdateInput { type: String, }) @IsString() + @MaxLength(1000) @IsOptional() @Field(() => String, { nullable: true, @@ -45,6 +51,7 @@ class TagUpdateInput { type: String, }) @IsString() + @MaxLength(100) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/tag/base/tag.service.base.ts b/server/src/tag/base/tag.service.base.ts index 971e0df..325b5a7 100644 --- a/server/src/tag/base/tag.service.base.ts +++ b/server/src/tag/base/tag.service.base.ts @@ -10,52 +10,35 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; - -import { - Prisma, - Tag, // @ts-ignore - Post, -} from "@prisma/client"; +import { Prisma, Tag as PrismaTag, Post as PrismaPost } from "@prisma/client"; export class TagServiceBase { constructor(protected readonly prisma: PrismaService) {} - async count( - args: Prisma.SelectSubset - ): Promise { + async count(args: Omit): Promise { return this.prisma.tag.count(args); } - async tags( - args: Prisma.SelectSubset - ): Promise { + async tags(args: Prisma.TagFindManyArgs): Promise { return this.prisma.tag.findMany(args); } - async tag( - args: Prisma.SelectSubset - ): Promise { + async tag(args: Prisma.TagFindUniqueArgs): Promise { return this.prisma.tag.findUnique(args); } - async createTag( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.tag.create(args); + async createTag(args: Prisma.TagCreateArgs): Promise { + return this.prisma.tag.create(args); } - async updateTag( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.tag.update(args); + async updateTag(args: Prisma.TagUpdateArgs): Promise { + return this.prisma.tag.update(args); } - async deleteTag( - args: Prisma.SelectSubset - ): Promise { + async deleteTag(args: Prisma.TagDeleteArgs): Promise { return this.prisma.tag.delete(args); } async findPosts( parentId: string, args: Prisma.PostFindManyArgs - ): Promise { + ): Promise { return this.prisma.tag .findUniqueOrThrow({ where: { id: parentId }, diff --git a/server/src/tests/auth/jwt/jwt.strategy.spec.ts b/server/src/tests/auth/jwt/jwt.strategy.spec.ts index 2f5d1a3..36bbb24 100644 --- a/server/src/tests/auth/jwt/jwt.strategy.spec.ts +++ b/server/src/tests/auth/jwt/jwt.strategy.spec.ts @@ -12,7 +12,9 @@ describe("Testing the jwtStrategyBase.validate()", () => { it("should throw UnauthorizedException where there is no user", async () => { //ARRANGE userService.user - .calledWith({ where: { username: TEST_USER.username } }) + .calledWith({ + where: { username: TEST_USER.username }, + }) .mockReturnValue(Promise.resolve(null)); //ACT const result = jwtStrategy.validate({ diff --git a/server/src/user/base/User.ts b/server/src/user/base/User.ts index 0ed8084..348fd32 100644 --- a/server/src/user/base/User.ts +++ b/server/src/user/base/User.ts @@ -11,7 +11,7 @@ https://docs.amplication.com/how-to/custom-code */ import { ObjectType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsDate, IsString, IsOptional } from "class-validator"; +import { IsDate, IsString, MaxLength, IsOptional } from "class-validator"; import { Type } from "class-transformer"; import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; @@ -32,6 +32,7 @@ class User { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -51,6 +52,7 @@ class User { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/user/base/UserCreateInput.ts b/server/src/user/base/UserCreateInput.ts index 617155a..a98430e 100644 --- a/server/src/user/base/UserCreateInput.ts +++ b/server/src/user/base/UserCreateInput.ts @@ -11,7 +11,7 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional } from "class-validator"; +import { IsString, MaxLength, IsOptional } from "class-validator"; import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; import { InputJsonValue } from "../../types"; @@ -23,6 +23,7 @@ class UserCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -34,6 +35,7 @@ class UserCreateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/user/base/UserUpdateInput.ts b/server/src/user/base/UserUpdateInput.ts index 0a9ab93..aefeb3f 100644 --- a/server/src/user/base/UserUpdateInput.ts +++ b/server/src/user/base/UserUpdateInput.ts @@ -11,7 +11,7 @@ https://docs.amplication.com/how-to/custom-code */ import { InputType, Field } from "@nestjs/graphql"; import { ApiProperty } from "@nestjs/swagger"; -import { IsString, IsOptional } from "class-validator"; +import { IsString, MaxLength, IsOptional } from "class-validator"; import { IsJSONValue } from "../../validators"; import { GraphQLJSON } from "graphql-type-json"; import { InputJsonValue } from "../../types"; @@ -23,6 +23,7 @@ class UserUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, @@ -34,6 +35,7 @@ class UserUpdateInput { type: String, }) @IsString() + @MaxLength(256) @IsOptional() @Field(() => String, { nullable: true, diff --git a/server/src/user/base/user.service.base.ts b/server/src/user/base/user.service.base.ts index d23387f..6a749c5 100644 --- a/server/src/user/base/user.service.base.ts +++ b/server/src/user/base/user.service.base.ts @@ -10,7 +10,7 @@ https://docs.amplication.com/how-to/custom-code ------------------------------------------------------------------------------ */ import { PrismaService } from "../../prisma/prisma.service"; -import { Prisma, User } from "@prisma/client"; +import { Prisma, User as PrismaUser } from "@prisma/client"; import { PasswordService } from "../../auth/password.service"; import { transformStringFieldUpdateInput } from "../../prisma.util"; @@ -20,26 +20,18 @@ export class UserServiceBase { protected readonly passwordService: PasswordService ) {} - async count( - args: Prisma.SelectSubset - ): Promise { + async count(args: Omit): Promise { return this.prisma.user.count(args); } - async users( - args: Prisma.SelectSubset - ): Promise { + async users(args: Prisma.UserFindManyArgs): Promise { return this.prisma.user.findMany(args); } - async user( - args: Prisma.SelectSubset - ): Promise { + async user(args: Prisma.UserFindUniqueArgs): Promise { return this.prisma.user.findUnique(args); } - async createUser( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.user.create({ + async createUser(args: Prisma.UserCreateArgs): Promise { + return this.prisma.user.create({ ...args, data: { @@ -48,10 +40,8 @@ export class UserServiceBase { }, }); } - async updateUser( - args: Prisma.SelectSubset - ): Promise { - return this.prisma.user.update({ + async updateUser(args: Prisma.UserUpdateArgs): Promise { + return this.prisma.user.update({ ...args, data: { @@ -66,9 +56,7 @@ export class UserServiceBase { }, }); } - async deleteUser( - args: Prisma.SelectSubset - ): Promise { + async deleteUser(args: Prisma.UserDeleteArgs): Promise { return this.prisma.user.delete(args); } }