diff --git a/apps/cloud-provider-connector-admin/.dockerignore b/apps/cloud-provider-connector-admin/.dockerignore new file mode 100644 index 00000000..1194b4f9 --- /dev/null +++ b/apps/cloud-provider-connector-admin/.dockerignore @@ -0,0 +1,7 @@ +.dockerignore +docker-compose.yml +Dockerfile +build/ +node_modules +.env +.gitignore diff --git a/apps/cloud-provider-connector-admin/.env b/apps/cloud-provider-connector-admin/.env new file mode 100644 index 00000000..e96bc900 --- /dev/null +++ b/apps/cloud-provider-connector-admin/.env @@ -0,0 +1,2 @@ +PORT=3001 +VITE_REACT_APP_SERVER_URL=http://localhost:3000 \ No newline at end of file diff --git a/apps/cloud-provider-connector-admin/.gitignore b/apps/cloud-provider-connector-admin/.gitignore new file mode 100644 index 00000000..590b2e05 --- /dev/null +++ b/apps/cloud-provider-connector-admin/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/apps/cloud-provider-connector-admin/Dockerfile b/apps/cloud-provider-connector-admin/Dockerfile new file mode 100644 index 00000000..0911e21f --- /dev/null +++ b/apps/cloud-provider-connector-admin/Dockerfile @@ -0,0 +1,51 @@ +# multi-stage: base (build) +FROM node:18.13.0-slim AS base + +# instantiate environment variable +ARG REACT_APP_SERVER_URL=http://localhost:3000 + +# set the environment variable that points to the server +ENV REACT_APP_SERVER_URL=$REACT_APP_SERVER_URL + +# create directory where the application will be built +WORKDIR /app + +# copy over the dependency manifests, both the package.json +# and the package-lock.json are copied over +COPY package*.json ./ + +# installs packages and their dependencies +RUN npm install + +# copy over the code base +COPY . . + +# create the bundle of the application +RUN npm run build + +# multi-stage: production (runtime) +FROM nginx:1.22-alpine AS production + +# copy over the bundled code from the build stage +COPY --from=base /app/build /usr/share/nginx/html +COPY --from=base /app/configuration/nginx.conf /etc/nginx/conf.d/default.conf + +# create a new process indication file +RUN touch /var/run/nginx.pid + +# change ownership of nginx related directories and files +RUN chown -R nginx:nginx /var/run/nginx.pid \ + /usr/share/nginx/html \ + /var/cache/nginx \ + /var/log/nginx \ + /etc/nginx/conf.d + +# set user to the created non-privileged user +USER nginx + +# expose a specific port on the docker container +ENV PORT=3001 +EXPOSE ${PORT} + +# start the server using the previously build application +ENTRYPOINT [ "nginx", "-g", "daemon off;" ] diff --git a/apps/cloud-provider-connector-admin/README.md b/apps/cloud-provider-connector-admin/README.md new file mode 100644 index 00000000..cc7c3873 --- /dev/null +++ b/apps/cloud-provider-connector-admin/README.md @@ -0,0 +1,47 @@ +

+ + amplication-logo + +

+ +# Introduction + +This service was generated with Amplication. It serves as the client-side for the generated server component. The client-side consist of a React application with ready-made forms for creating and editing the different data models of the application. It is pre-conffigured to work with the server and comes with the boilerplate and foundation for the client - i.e., routing, navigation, authentication, permissions, menu, breadcrumbs, error handling and much more. Additional information about the admin component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site. This side of the generated project was bootstrapped with [create-react-app](https://github.com/facebook/create-react-app) and built with [react-admin](https://marmelab.com/react-admin/). + + +

+ +

+ +# Getting started + +## Step 1: Configuration + +Configuration for the client component can be provided through the use of environment variables. These can be passed to the application via the use of the `.env` file in the base directory of the generated service. Below a table can be found which show the different variables that can be passed. These values are provided default values after generation, change them to the desired values. + +| Variable | Description | Value | +| -------------------- | ------------------------------------------------ | ------------------------------ | +| PORT | the port on which to run the client | 3001 | +| REACT_APP_SERVER_URL | the url on which the server component is running | http://localhost:[server-port] | + +> **Note** +> Amplication generates default values and stores them under the .env file. It is advised to use some form of secrets manager/vault solution when using in production. + + +## Step 2: Scripts + +After configuration of the client the next step would be to run the application. Before running the client side of the component, make sure that the different pre-requisites are met - i.e., npm, docker. Make sure that the server-side of the application is running. + +```sh +# installation of the dependencies +$ npm install + +# starts the application in development mode - available by default under http://localhost:3001 with a pre-configured user with the username "admin" and password "admin" +$ npm run start + +# builds the application in production mode - available under 'build' +$ npm run build + +# removes the single build dependency from the project +$ npm run eject +``` diff --git a/apps/cloud-provider-connector-admin/configuration/nginx.conf b/apps/cloud-provider-connector-admin/configuration/nginx.conf new file mode 100644 index 00000000..c907b5ce --- /dev/null +++ b/apps/cloud-provider-connector-admin/configuration/nginx.conf @@ -0,0 +1,11 @@ +server_tokens off; + +server { + listen 3001; + server_name localhost; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri /index.html; + } +} \ No newline at end of file diff --git a/apps/cloud-provider-connector-admin/index.html b/apps/cloud-provider-connector-admin/index.html new file mode 100644 index 00000000..4f4d7b1a --- /dev/null +++ b/apps/cloud-provider-connector-admin/index.html @@ -0,0 +1,17 @@ + + + + + + + + + + Cloud Provider Connector + + + +
+ + + diff --git a/apps/cloud-provider-connector-admin/package.json b/apps/cloud-provider-connector-admin/package.json new file mode 100644 index 00000000..dbd0cf66 --- /dev/null +++ b/apps/cloud-provider-connector-admin/package.json @@ -0,0 +1,41 @@ +{ + "name": "@cloud-provider-connector/admin", + "private": true, + "dependencies": { + "@apollo/client": "3.6.9", + "graphql": "15.6.1", + "lodash": "4.17.21", + "pluralize": "8.0.0", + "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": "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 ." + }, + "devDependencies": { + "@types/lodash": "4.14.178", + "@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": "^5.1.6", + "vite": "^4.3.9" + } +} \ No newline at end of file diff --git a/apps/cloud-provider-connector-admin/public/favicon.ico b/apps/cloud-provider-connector-admin/public/favicon.ico new file mode 100644 index 00000000..fcbdcf2d Binary files /dev/null and b/apps/cloud-provider-connector-admin/public/favicon.ico differ diff --git a/apps/cloud-provider-connector-admin/public/logo192.png b/apps/cloud-provider-connector-admin/public/logo192.png new file mode 100644 index 00000000..1918ff2e Binary files /dev/null and b/apps/cloud-provider-connector-admin/public/logo192.png differ diff --git a/apps/cloud-provider-connector-admin/public/logo512.png b/apps/cloud-provider-connector-admin/public/logo512.png new file mode 100644 index 00000000..7e7dc74f Binary files /dev/null and b/apps/cloud-provider-connector-admin/public/logo512.png differ diff --git a/apps/cloud-provider-connector-admin/public/manifest.json b/apps/cloud-provider-connector-admin/public/manifest.json new file mode 100644 index 00000000..2cb422d6 --- /dev/null +++ b/apps/cloud-provider-connector-admin/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "Cloud Provider Connector", + "name": "Cloud Provider Connector", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} \ No newline at end of file diff --git a/apps/cloud-provider-connector-admin/public/robots.txt b/apps/cloud-provider-connector-admin/public/robots.txt new file mode 100644 index 00000000..e9e57dc4 --- /dev/null +++ b/apps/cloud-provider-connector-admin/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/apps/cloud-provider-connector-admin/src/App.scss b/apps/cloud-provider-connector-admin/src/App.scss new file mode 100644 index 00000000..4c1cbb06 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/App.scss @@ -0,0 +1,59 @@ +// .App { +// .MuiAppBar-colorSecondary { +// background-color: black; + +// .RaAppBar-menuButton-13 { +// background-color: yellow; +// } +// } + +// .MuiDrawer-paper { +// background-color: red; + +// .MuiListItemIcon-root { +// color: white; +// } +// } + +// .MuiButton-textPrimary { +// background-color: purple; +// margin: 0 0.5rem; +// color: white; +// padding: 0.5rem 1rem; + +// &:hover { +// background-color: blue; +// } +// } + +// .MuiTableRow-head { +// .MuiTableCell-head { +// background-color: black; +// color: white; +// } + +// .MuiTableSortLabel-root { +// &:hover { +// color: red; + +// .MuiTableSortLabel-icon { +// color: red !important; +// } +// } +// .MuiTableSortLabel-icon { +// color: white !important; +// } +// } +// .MuiTableSortLabel-active { +// color: green; + +// .MuiTableSortLabel-icon { +// color: green !important; +// } +// } +// } + +// .MuiFormLabel-root { +// color: magenta; +// } +// } diff --git a/apps/cloud-provider-connector-admin/src/App.tsx b/apps/cloud-provider-connector-admin/src/App.tsx new file mode 100644 index 00000000..4baff5bc --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/App.tsx @@ -0,0 +1,92 @@ +import React, { useEffect, useState } from "react"; +import { Admin, DataProvider, Resource } from "react-admin"; +import dataProvider from "./data-provider/graphqlDataProvider"; +import { theme } from "./theme/theme"; +import Login from "./Login"; +import "./App.scss"; +import Dashboard from "./pages/Dashboard"; +import { AzureConnectionList } from "./azureConnection/AzureConnectionList"; +import { AzureConnectionCreate } from "./azureConnection/AzureConnectionCreate"; +import { AzureConnectionEdit } from "./azureConnection/AzureConnectionEdit"; +import { AzureConnectionShow } from "./azureConnection/AzureConnectionShow"; +import { AwsConnectionList } from "./awsConnection/AwsConnectionList"; +import { AwsConnectionCreate } from "./awsConnection/AwsConnectionCreate"; +import { AwsConnectionEdit } from "./awsConnection/AwsConnectionEdit"; +import { AwsConnectionShow } from "./awsConnection/AwsConnectionShow"; +import { GcpConnectionList } from "./gcpConnection/GcpConnectionList"; +import { GcpConnectionCreate } from "./gcpConnection/GcpConnectionCreate"; +import { GcpConnectionEdit } from "./gcpConnection/GcpConnectionEdit"; +import { GcpConnectionShow } from "./gcpConnection/GcpConnectionShow"; +import { InstanceTemplateList } from "./instanceTemplate/InstanceTemplateList"; +import { InstanceTemplateCreate } from "./instanceTemplate/InstanceTemplateCreate"; +import { InstanceTemplateEdit } from "./instanceTemplate/InstanceTemplateEdit"; +import { InstanceTemplateShow } from "./instanceTemplate/InstanceTemplateShow"; +import { ProviderLogList } from "./providerLog/ProviderLogList"; +import { ProviderLogCreate } from "./providerLog/ProviderLogCreate"; +import { ProviderLogEdit } from "./providerLog/ProviderLogEdit"; +import { ProviderLogShow } from "./providerLog/ProviderLogShow"; +import { RegionList } from "./region/RegionList"; +import { RegionCreate } from "./region/RegionCreate"; +import { RegionEdit } from "./region/RegionEdit"; +import { RegionShow } from "./region/RegionShow"; +import { jwtAuthProvider } from "./auth-provider/ra-auth-jwt"; + +const App = (): React.ReactElement => { + return ( +
+ + + + + + + + +
+ ); +}; + +export default App; diff --git a/apps/cloud-provider-connector-admin/src/Components/Pagination.tsx b/apps/cloud-provider-connector-admin/src/Components/Pagination.tsx new file mode 100644 index 00000000..2de2ebf3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/Components/Pagination.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import { Pagination as RAPagination, PaginationProps } from "react-admin"; + +const PAGINATION_OPTIONS = [10, 25, 50, 100, 200]; + +const Pagination = (props: PaginationProps) => ( + +); + +export default Pagination; diff --git a/apps/cloud-provider-connector-admin/src/Login.tsx b/apps/cloud-provider-connector-admin/src/Login.tsx new file mode 100644 index 00000000..dbd6a85b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/Login.tsx @@ -0,0 +1,82 @@ +import * as React from "react"; +import { useState } from "react"; +import { useLogin, useNotify, Notification, defaultTheme } from "react-admin"; +import { Button, createTheme, ThemeProvider } from "@mui/material"; +import "./login.scss"; +import LoginForm from "./LoginForm"; + +const CLASS_NAME = "login-page"; + +const Login = ({ theme }: any) => { + const BASE_URI = process.env.REACT_APP_SERVER_URL; + + return ( + +
+
+
+ GraphQL API +

Connect via GraphQL

+
+ Connect to the server using GraphQL API with a complete and + understandable description of the data in your API +
+ +
+
+ React-Admin +

Admin UI

+
+ Sign in to a React-Admin client with ready-made forms for creating + and editing all the data models of your application +
+ +
+
+ REST API +

Connect via REST API

+
+ Connect to the server using REST API with a built-in Swagger + documentation +
+ +
+ + +
+
+ Read + + Amplication docs + + to learn more +
+
+
+ ); +}; + +export default Login; diff --git a/apps/cloud-provider-connector-admin/src/LoginForm.tsx b/apps/cloud-provider-connector-admin/src/LoginForm.tsx new file mode 100644 index 00000000..92d48da1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/LoginForm.tsx @@ -0,0 +1,48 @@ +import { useState } from "react"; +import { useLogin, useNotify } from "react-admin"; +import { Button } from "@mui/material"; +import "./login.scss"; + +const LoginForm = ({ theme }: any) => { + 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/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnection.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnection.ts new file mode 100644 index 00000000..9d8df423 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnection.ts @@ -0,0 +1,10 @@ +export type AwsConnection = { + accessKeyId: string | null; + createdAt: Date; + id: string; + region: string | null; + secretAccessKey: string | null; + sessionToken: string | null; + updatedAt: Date; + userProfile: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCountArgs.ts new file mode 100644 index 00000000..38eea6f3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCountArgs.ts @@ -0,0 +1,5 @@ +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; + +export type AwsConnectionCountArgs = { + where?: AwsConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCreateInput.ts new file mode 100644 index 00000000..f18ccbae --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionCreateInput.ts @@ -0,0 +1,7 @@ +export type AwsConnectionCreateInput = { + accessKeyId?: string | null; + region?: string | null; + secretAccessKey?: string | null; + sessionToken?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindManyArgs.ts new file mode 100644 index 00000000..3320c618 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindManyArgs.ts @@ -0,0 +1,9 @@ +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; +import { AwsConnectionOrderByInput } from "./AwsConnectionOrderByInput"; + +export type AwsConnectionFindManyArgs = { + where?: AwsConnectionWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..4ef760e7 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; + +export type AwsConnectionFindUniqueArgs = { + where: AwsConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionListRelationFilter.ts new file mode 100644 index 00000000..831b8a64 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionListRelationFilter.ts @@ -0,0 +1,7 @@ +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; + +export type AwsConnectionListRelationFilter = { + every?: AwsConnectionWhereInput; + some?: AwsConnectionWhereInput; + none?: AwsConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionOrderByInput.ts new file mode 100644 index 00000000..06d478d1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionOrderByInput.ts @@ -0,0 +1,12 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type AwsConnectionOrderByInput = { + accessKeyId?: SortOrder; + createdAt?: SortOrder; + id?: SortOrder; + region?: SortOrder; + secretAccessKey?: SortOrder; + sessionToken?: SortOrder; + updatedAt?: SortOrder; + userProfile?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionUpdateInput.ts new file mode 100644 index 00000000..14c8aea1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionUpdateInput.ts @@ -0,0 +1,7 @@ +export type AwsConnectionUpdateInput = { + accessKeyId?: string | null; + region?: string | null; + secretAccessKey?: string | null; + sessionToken?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereInput.ts new file mode 100644 index 00000000..2e7dcd3a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereInput.ts @@ -0,0 +1,11 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; + +export type AwsConnectionWhereInput = { + accessKeyId?: StringNullableFilter; + id?: StringFilter; + region?: StringNullableFilter; + secretAccessKey?: StringNullableFilter; + sessionToken?: StringNullableFilter; + userProfile?: StringNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..8c46c04b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/AwsConnectionWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type AwsConnectionWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/CreateAwsConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/CreateAwsConnectionArgs.ts new file mode 100644 index 00000000..f138e55b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/CreateAwsConnectionArgs.ts @@ -0,0 +1,5 @@ +import { AwsConnectionCreateInput } from "./AwsConnectionCreateInput"; + +export type CreateAwsConnectionArgs = { + data: AwsConnectionCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/DeleteAwsConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/DeleteAwsConnectionArgs.ts new file mode 100644 index 00000000..08124922 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/DeleteAwsConnectionArgs.ts @@ -0,0 +1,5 @@ +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; + +export type DeleteAwsConnectionArgs = { + where: AwsConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/awsConnection/UpdateAwsConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/awsConnection/UpdateAwsConnectionArgs.ts new file mode 100644 index 00000000..59b45a54 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/awsConnection/UpdateAwsConnectionArgs.ts @@ -0,0 +1,7 @@ +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; +import { AwsConnectionUpdateInput } from "./AwsConnectionUpdateInput"; + +export type UpdateAwsConnectionArgs = { + where: AwsConnectionWhereUniqueInput; + data: AwsConnectionUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnection.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnection.ts new file mode 100644 index 00000000..2b31aa2a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnection.ts @@ -0,0 +1,11 @@ +export type AzureConnection = { + clientId: string | null; + clientSecret: string | null; + createdAt: Date; + id: string; + region: string | null; + subscriptionId: string | null; + tenantId: string | null; + updatedAt: Date; + userProfile: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCountArgs.ts new file mode 100644 index 00000000..fe0c3d33 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCountArgs.ts @@ -0,0 +1,5 @@ +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; + +export type AzureConnectionCountArgs = { + where?: AzureConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCreateInput.ts new file mode 100644 index 00000000..97bedbfd --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionCreateInput.ts @@ -0,0 +1,8 @@ +export type AzureConnectionCreateInput = { + clientId?: string | null; + clientSecret?: string | null; + region?: string | null; + subscriptionId?: string | null; + tenantId?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindManyArgs.ts new file mode 100644 index 00000000..2d1632fb --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindManyArgs.ts @@ -0,0 +1,9 @@ +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; +import { AzureConnectionOrderByInput } from "./AzureConnectionOrderByInput"; + +export type AzureConnectionFindManyArgs = { + where?: AzureConnectionWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..39e7e295 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; + +export type AzureConnectionFindUniqueArgs = { + where: AzureConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionListRelationFilter.ts new file mode 100644 index 00000000..1e0af158 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionListRelationFilter.ts @@ -0,0 +1,7 @@ +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; + +export type AzureConnectionListRelationFilter = { + every?: AzureConnectionWhereInput; + some?: AzureConnectionWhereInput; + none?: AzureConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionOrderByInput.ts new file mode 100644 index 00000000..57c4b7fa --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionOrderByInput.ts @@ -0,0 +1,13 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type AzureConnectionOrderByInput = { + clientId?: SortOrder; + clientSecret?: SortOrder; + createdAt?: SortOrder; + id?: SortOrder; + region?: SortOrder; + subscriptionId?: SortOrder; + tenantId?: SortOrder; + updatedAt?: SortOrder; + userProfile?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionUpdateInput.ts new file mode 100644 index 00000000..58f113bb --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionUpdateInput.ts @@ -0,0 +1,8 @@ +export type AzureConnectionUpdateInput = { + clientId?: string | null; + clientSecret?: string | null; + region?: string | null; + subscriptionId?: string | null; + tenantId?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereInput.ts new file mode 100644 index 00000000..67647a39 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereInput.ts @@ -0,0 +1,12 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; + +export type AzureConnectionWhereInput = { + clientId?: StringNullableFilter; + clientSecret?: StringNullableFilter; + id?: StringFilter; + region?: StringNullableFilter; + subscriptionId?: StringNullableFilter; + tenantId?: StringNullableFilter; + userProfile?: StringNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..9200416a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/AzureConnectionWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type AzureConnectionWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/CreateAzureConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/CreateAzureConnectionArgs.ts new file mode 100644 index 00000000..bd97ba6f --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/CreateAzureConnectionArgs.ts @@ -0,0 +1,5 @@ +import { AzureConnectionCreateInput } from "./AzureConnectionCreateInput"; + +export type CreateAzureConnectionArgs = { + data: AzureConnectionCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/DeleteAzureConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/DeleteAzureConnectionArgs.ts new file mode 100644 index 00000000..3d777430 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/DeleteAzureConnectionArgs.ts @@ -0,0 +1,5 @@ +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; + +export type DeleteAzureConnectionArgs = { + where: AzureConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/azureConnection/UpdateAzureConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/azureConnection/UpdateAzureConnectionArgs.ts new file mode 100644 index 00000000..a2037772 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/azureConnection/UpdateAzureConnectionArgs.ts @@ -0,0 +1,7 @@ +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; +import { AzureConnectionUpdateInput } from "./AzureConnectionUpdateInput"; + +export type UpdateAzureConnectionArgs = { + where: AzureConnectionWhereUniqueInput; + data: AzureConnectionUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/CreateGcpConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/CreateGcpConnectionArgs.ts new file mode 100644 index 00000000..77f79dd8 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/CreateGcpConnectionArgs.ts @@ -0,0 +1,5 @@ +import { GcpConnectionCreateInput } from "./GcpConnectionCreateInput"; + +export type CreateGcpConnectionArgs = { + data: GcpConnectionCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/DeleteGcpConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/DeleteGcpConnectionArgs.ts new file mode 100644 index 00000000..b4cdd4e9 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/DeleteGcpConnectionArgs.ts @@ -0,0 +1,5 @@ +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; + +export type DeleteGcpConnectionArgs = { + where: GcpConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnection.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnection.ts new file mode 100644 index 00000000..ebf53374 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnection.ts @@ -0,0 +1,9 @@ +export type GcpConnection = { + createdAt: Date; + id: string; + projectId: string | null; + region: string | null; + serviceAccountJson: string | null; + updatedAt: Date; + userProfile: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCountArgs.ts new file mode 100644 index 00000000..40f41b25 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCountArgs.ts @@ -0,0 +1,5 @@ +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; + +export type GcpConnectionCountArgs = { + where?: GcpConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCreateInput.ts new file mode 100644 index 00000000..6890406e --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionCreateInput.ts @@ -0,0 +1,6 @@ +export type GcpConnectionCreateInput = { + projectId?: string | null; + region?: string | null; + serviceAccountJson?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindManyArgs.ts new file mode 100644 index 00000000..8c1bf1b0 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindManyArgs.ts @@ -0,0 +1,9 @@ +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; +import { GcpConnectionOrderByInput } from "./GcpConnectionOrderByInput"; + +export type GcpConnectionFindManyArgs = { + where?: GcpConnectionWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..01eab511 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; + +export type GcpConnectionFindUniqueArgs = { + where: GcpConnectionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionListRelationFilter.ts new file mode 100644 index 00000000..f64f9fa9 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionListRelationFilter.ts @@ -0,0 +1,7 @@ +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; + +export type GcpConnectionListRelationFilter = { + every?: GcpConnectionWhereInput; + some?: GcpConnectionWhereInput; + none?: GcpConnectionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionOrderByInput.ts new file mode 100644 index 00000000..8eeaacd1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionOrderByInput.ts @@ -0,0 +1,11 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type GcpConnectionOrderByInput = { + createdAt?: SortOrder; + id?: SortOrder; + projectId?: SortOrder; + region?: SortOrder; + serviceAccountJson?: SortOrder; + updatedAt?: SortOrder; + userProfile?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionUpdateInput.ts new file mode 100644 index 00000000..e3a95e1b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionUpdateInput.ts @@ -0,0 +1,6 @@ +export type GcpConnectionUpdateInput = { + projectId?: string | null; + region?: string | null; + serviceAccountJson?: string | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereInput.ts new file mode 100644 index 00000000..5ead558a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereInput.ts @@ -0,0 +1,10 @@ +import { StringFilter } from "../../util/StringFilter"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; + +export type GcpConnectionWhereInput = { + id?: StringFilter; + projectId?: StringNullableFilter; + region?: StringNullableFilter; + serviceAccountJson?: StringNullableFilter; + userProfile?: StringNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..9c289662 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/GcpConnectionWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type GcpConnectionWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/gcpConnection/UpdateGcpConnectionArgs.ts b/apps/cloud-provider-connector-admin/src/api/gcpConnection/UpdateGcpConnectionArgs.ts new file mode 100644 index 00000000..f0fd517b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/gcpConnection/UpdateGcpConnectionArgs.ts @@ -0,0 +1,7 @@ +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; +import { GcpConnectionUpdateInput } from "./GcpConnectionUpdateInput"; + +export type UpdateGcpConnectionArgs = { + where: GcpConnectionWhereUniqueInput; + data: GcpConnectionUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/CreateInstanceTemplateArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/CreateInstanceTemplateArgs.ts new file mode 100644 index 00000000..f42ec19b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/CreateInstanceTemplateArgs.ts @@ -0,0 +1,5 @@ +import { InstanceTemplateCreateInput } from "./InstanceTemplateCreateInput"; + +export type CreateInstanceTemplateArgs = { + data: InstanceTemplateCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/DeleteInstanceTemplateArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/DeleteInstanceTemplateArgs.ts new file mode 100644 index 00000000..636e5b2d --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/DeleteInstanceTemplateArgs.ts @@ -0,0 +1,5 @@ +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; + +export type DeleteInstanceTemplateArgs = { + where: InstanceTemplateWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplate.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplate.ts new file mode 100644 index 00000000..3c669d97 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplate.ts @@ -0,0 +1,14 @@ +import { Region } from "../region/Region"; + +export type InstanceTemplate = { + cpu: number | null; + createdAt: Date; + hasGpu: boolean | null; + id: string; + memoryGb: number | null; + name: string | null; + provider: string | null; + region?: Region | null; + storageGb: number | null; + updatedAt: Date; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCountArgs.ts new file mode 100644 index 00000000..1e2ed4b0 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCountArgs.ts @@ -0,0 +1,5 @@ +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; + +export type InstanceTemplateCountArgs = { + where?: InstanceTemplateWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCreateInput.ts new file mode 100644 index 00000000..6fcc56df --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateCreateInput.ts @@ -0,0 +1,11 @@ +import { RegionWhereUniqueInput } from "../region/RegionWhereUniqueInput"; + +export type InstanceTemplateCreateInput = { + cpu?: number | null; + hasGpu?: boolean | null; + memoryGb?: number | null; + name?: string | null; + provider?: string | null; + region?: RegionWhereUniqueInput | null; + storageGb?: number | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindManyArgs.ts new file mode 100644 index 00000000..a08f4a54 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindManyArgs.ts @@ -0,0 +1,9 @@ +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; +import { InstanceTemplateOrderByInput } from "./InstanceTemplateOrderByInput"; + +export type InstanceTemplateFindManyArgs = { + where?: InstanceTemplateWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindUniqueArgs.ts new file mode 100644 index 00000000..46a44912 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; + +export type InstanceTemplateFindUniqueArgs = { + where: InstanceTemplateWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateListRelationFilter.ts new file mode 100644 index 00000000..bb2ad7aa --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateListRelationFilter.ts @@ -0,0 +1,7 @@ +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; + +export type InstanceTemplateListRelationFilter = { + every?: InstanceTemplateWhereInput; + some?: InstanceTemplateWhereInput; + none?: InstanceTemplateWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateOrderByInput.ts new file mode 100644 index 00000000..d91fe329 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateOrderByInput.ts @@ -0,0 +1,14 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type InstanceTemplateOrderByInput = { + cpu?: SortOrder; + createdAt?: SortOrder; + hasGpu?: SortOrder; + id?: SortOrder; + memoryGb?: SortOrder; + name?: SortOrder; + provider?: SortOrder; + regionId?: SortOrder; + storageGb?: SortOrder; + updatedAt?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateUpdateInput.ts new file mode 100644 index 00000000..babb82f0 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateUpdateInput.ts @@ -0,0 +1,11 @@ +import { RegionWhereUniqueInput } from "../region/RegionWhereUniqueInput"; + +export type InstanceTemplateUpdateInput = { + cpu?: number | null; + hasGpu?: boolean | null; + memoryGb?: number | null; + name?: string | null; + provider?: string | null; + region?: RegionWhereUniqueInput | null; + storageGb?: number | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereInput.ts new file mode 100644 index 00000000..7913f7b8 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereInput.ts @@ -0,0 +1,16 @@ +import { IntNullableFilter } from "../../util/IntNullableFilter"; +import { BooleanNullableFilter } from "../../util/BooleanNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { RegionWhereUniqueInput } from "../region/RegionWhereUniqueInput"; + +export type InstanceTemplateWhereInput = { + cpu?: IntNullableFilter; + hasGpu?: BooleanNullableFilter; + id?: StringFilter; + memoryGb?: IntNullableFilter; + name?: StringNullableFilter; + provider?: StringNullableFilter; + region?: RegionWhereUniqueInput; + storageGb?: IntNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereUniqueInput.ts new file mode 100644 index 00000000..a87f9d66 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/InstanceTemplateWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type InstanceTemplateWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/instanceTemplate/UpdateInstanceTemplateArgs.ts b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/UpdateInstanceTemplateArgs.ts new file mode 100644 index 00000000..e4d66747 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/instanceTemplate/UpdateInstanceTemplateArgs.ts @@ -0,0 +1,7 @@ +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; +import { InstanceTemplateUpdateInput } from "./InstanceTemplateUpdateInput"; + +export type UpdateInstanceTemplateArgs = { + where: InstanceTemplateWhereUniqueInput; + data: InstanceTemplateUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/CreateProviderLogArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/CreateProviderLogArgs.ts new file mode 100644 index 00000000..63a2aa29 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/CreateProviderLogArgs.ts @@ -0,0 +1,5 @@ +import { ProviderLogCreateInput } from "./ProviderLogCreateInput"; + +export type CreateProviderLogArgs = { + data: ProviderLogCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/DeleteProviderLogArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/DeleteProviderLogArgs.ts new file mode 100644 index 00000000..cb86c869 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/DeleteProviderLogArgs.ts @@ -0,0 +1,5 @@ +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; + +export type DeleteProviderLogArgs = { + where: ProviderLogWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLog.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLog.ts new file mode 100644 index 00000000..fa7d6d08 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLog.ts @@ -0,0 +1,14 @@ +import { JsonValue } from "type-fest"; + +export type ProviderLog = { + action: string | null; + createdAt: Date; + id: string; + provider: string | null; + request: JsonValue; + response: JsonValue; + status: string | null; + timestamp: Date | null; + updatedAt: Date; + userProfile: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCountArgs.ts new file mode 100644 index 00000000..2d6732a9 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCountArgs.ts @@ -0,0 +1,5 @@ +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; + +export type ProviderLogCountArgs = { + where?: ProviderLogWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCreateInput.ts new file mode 100644 index 00000000..6c5b5526 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogCreateInput.ts @@ -0,0 +1,11 @@ +import { InputJsonValue } from "../../types"; + +export type ProviderLogCreateInput = { + action?: string | null; + provider?: string | null; + request?: InputJsonValue; + response?: InputJsonValue; + status?: string | null; + timestamp?: Date | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindManyArgs.ts new file mode 100644 index 00000000..fd54ce6a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindManyArgs.ts @@ -0,0 +1,9 @@ +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; +import { ProviderLogOrderByInput } from "./ProviderLogOrderByInput"; + +export type ProviderLogFindManyArgs = { + where?: ProviderLogWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindUniqueArgs.ts new file mode 100644 index 00000000..77311b82 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; + +export type ProviderLogFindUniqueArgs = { + where: ProviderLogWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogListRelationFilter.ts new file mode 100644 index 00000000..4c03b91a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogListRelationFilter.ts @@ -0,0 +1,7 @@ +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; + +export type ProviderLogListRelationFilter = { + every?: ProviderLogWhereInput; + some?: ProviderLogWhereInput; + none?: ProviderLogWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogOrderByInput.ts new file mode 100644 index 00000000..7b4e80cd --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogOrderByInput.ts @@ -0,0 +1,14 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type ProviderLogOrderByInput = { + action?: SortOrder; + createdAt?: SortOrder; + id?: SortOrder; + provider?: SortOrder; + request?: SortOrder; + response?: SortOrder; + status?: SortOrder; + timestamp?: SortOrder; + updatedAt?: SortOrder; + userProfile?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogUpdateInput.ts new file mode 100644 index 00000000..40523178 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogUpdateInput.ts @@ -0,0 +1,11 @@ +import { InputJsonValue } from "../../types"; + +export type ProviderLogUpdateInput = { + action?: string | null; + provider?: string | null; + request?: InputJsonValue; + response?: InputJsonValue; + status?: string | null; + timestamp?: Date | null; + userProfile?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereInput.ts new file mode 100644 index 00000000..9b74f082 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereInput.ts @@ -0,0 +1,15 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { JsonFilter } from "../../util/JsonFilter"; +import { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +export type ProviderLogWhereInput = { + action?: StringNullableFilter; + id?: StringFilter; + provider?: StringNullableFilter; + request?: JsonFilter; + response?: JsonFilter; + status?: StringNullableFilter; + timestamp?: DateTimeNullableFilter; + userProfile?: StringNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereUniqueInput.ts new file mode 100644 index 00000000..631ac136 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/ProviderLogWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type ProviderLogWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/providerLog/UpdateProviderLogArgs.ts b/apps/cloud-provider-connector-admin/src/api/providerLog/UpdateProviderLogArgs.ts new file mode 100644 index 00000000..b4beba1f --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/providerLog/UpdateProviderLogArgs.ts @@ -0,0 +1,7 @@ +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; +import { ProviderLogUpdateInput } from "./ProviderLogUpdateInput"; + +export type UpdateProviderLogArgs = { + where: ProviderLogWhereUniqueInput; + data: ProviderLogUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/CreateRegionArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/CreateRegionArgs.ts new file mode 100644 index 00000000..6d325273 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/CreateRegionArgs.ts @@ -0,0 +1,5 @@ +import { RegionCreateInput } from "./RegionCreateInput"; + +export type CreateRegionArgs = { + data: RegionCreateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/DeleteRegionArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/DeleteRegionArgs.ts new file mode 100644 index 00000000..0618713d --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/DeleteRegionArgs.ts @@ -0,0 +1,5 @@ +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; + +export type DeleteRegionArgs = { + where: RegionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts b/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts new file mode 100644 index 00000000..34d6aff1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts @@ -0,0 +1,5 @@ +import { InstanceTemplateWhereUniqueInput } from "../instanceTemplate/InstanceTemplateWhereUniqueInput"; + +export type InstanceTemplateCreateNestedManyWithoutRegionsInput = { + connect?: Array; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateUpdateManyWithoutRegionsInput.ts b/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateUpdateManyWithoutRegionsInput.ts new file mode 100644 index 00000000..89feadcd --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/InstanceTemplateUpdateManyWithoutRegionsInput.ts @@ -0,0 +1,7 @@ +import { InstanceTemplateWhereUniqueInput } from "../instanceTemplate/InstanceTemplateWhereUniqueInput"; + +export type InstanceTemplateUpdateManyWithoutRegionsInput = { + connect?: Array; + disconnect?: Array; + set?: Array; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/Region.ts b/apps/cloud-provider-connector-admin/src/api/region/Region.ts new file mode 100644 index 00000000..0a02b85f --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/Region.ts @@ -0,0 +1,11 @@ +import { InstanceTemplate } from "../instanceTemplate/InstanceTemplate"; + +export type Region = { + createdAt: Date; + description: string | null; + id: string; + instanceTemplates?: Array; + name: string | null; + provider: string | null; + updatedAt: Date; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionCountArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionCountArgs.ts new file mode 100644 index 00000000..64f5e01e --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionCountArgs.ts @@ -0,0 +1,5 @@ +import { RegionWhereInput } from "./RegionWhereInput"; + +export type RegionCountArgs = { + where?: RegionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionCreateInput.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionCreateInput.ts new file mode 100644 index 00000000..b418ada3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionCreateInput.ts @@ -0,0 +1,8 @@ +import { InstanceTemplateCreateNestedManyWithoutRegionsInput } from "./InstanceTemplateCreateNestedManyWithoutRegionsInput"; + +export type RegionCreateInput = { + description?: string | null; + instanceTemplates?: InstanceTemplateCreateNestedManyWithoutRegionsInput; + name?: string | null; + provider?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionFindManyArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionFindManyArgs.ts new file mode 100644 index 00000000..1229a9d5 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionFindManyArgs.ts @@ -0,0 +1,9 @@ +import { RegionWhereInput } from "./RegionWhereInput"; +import { RegionOrderByInput } from "./RegionOrderByInput"; + +export type RegionFindManyArgs = { + where?: RegionWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionFindUniqueArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionFindUniqueArgs.ts new file mode 100644 index 00000000..7eff6591 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; + +export type RegionFindUniqueArgs = { + where: RegionWhereUniqueInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionListRelationFilter.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionListRelationFilter.ts new file mode 100644 index 00000000..4d7e6d97 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionListRelationFilter.ts @@ -0,0 +1,7 @@ +import { RegionWhereInput } from "./RegionWhereInput"; + +export type RegionListRelationFilter = { + every?: RegionWhereInput; + some?: RegionWhereInput; + none?: RegionWhereInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionOrderByInput.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionOrderByInput.ts new file mode 100644 index 00000000..95d3d1ab --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionOrderByInput.ts @@ -0,0 +1,10 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type RegionOrderByInput = { + createdAt?: SortOrder; + description?: SortOrder; + id?: SortOrder; + name?: SortOrder; + provider?: SortOrder; + updatedAt?: SortOrder; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionUpdateInput.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionUpdateInput.ts new file mode 100644 index 00000000..9970cde9 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionUpdateInput.ts @@ -0,0 +1,8 @@ +import { InstanceTemplateUpdateManyWithoutRegionsInput } from "./InstanceTemplateUpdateManyWithoutRegionsInput"; + +export type RegionUpdateInput = { + description?: string | null; + instanceTemplates?: InstanceTemplateUpdateManyWithoutRegionsInput; + name?: string | null; + provider?: string | null; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionWhereInput.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionWhereInput.ts new file mode 100644 index 00000000..077de038 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionWhereInput.ts @@ -0,0 +1,11 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { InstanceTemplateListRelationFilter } from "../instanceTemplate/InstanceTemplateListRelationFilter"; + +export type RegionWhereInput = { + description?: StringNullableFilter; + id?: StringFilter; + instanceTemplates?: InstanceTemplateListRelationFilter; + name?: StringNullableFilter; + provider?: StringNullableFilter; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/RegionWhereUniqueInput.ts b/apps/cloud-provider-connector-admin/src/api/region/RegionWhereUniqueInput.ts new file mode 100644 index 00000000..09a9e979 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/RegionWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type RegionWhereUniqueInput = { + id: string; +}; diff --git a/apps/cloud-provider-connector-admin/src/api/region/UpdateRegionArgs.ts b/apps/cloud-provider-connector-admin/src/api/region/UpdateRegionArgs.ts new file mode 100644 index 00000000..7b56b436 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/api/region/UpdateRegionArgs.ts @@ -0,0 +1,7 @@ +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; +import { RegionUpdateInput } from "./RegionUpdateInput"; + +export type UpdateRegionArgs = { + where: RegionWhereUniqueInput; + data: RegionUpdateInput; +}; diff --git a/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-http.ts b/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-http.ts new file mode 100644 index 00000000..c6eeba8c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-http.ts @@ -0,0 +1,78 @@ +import { gql } from "@apollo/client/core"; +import { AuthProvider } from "react-admin"; +import { + CREDENTIALS_LOCAL_STORAGE_ITEM, + USER_DATA_LOCAL_STORAGE_ITEM, +} from "../constants"; +import { Credentials, LoginMutateResult } from "../types"; +import { apolloClient } from "../data-provider/graphqlDataProvider"; + +const LOGIN = gql` + mutation login($username: String!, $password: String!) { + login(credentials: { username: $username, password: $password }) { + username + roles + } + } +`; + +export const httpAuthProvider: AuthProvider = { + login: async (credentials: Credentials) => { + const userData = await apolloClient.mutate({ + mutation: LOGIN, + variables: { + ...credentials, + }, + }); + + if (userData && userData.data?.login.username) { + localStorage.setItem( + CREDENTIALS_LOCAL_STORAGE_ITEM, + createBasicAuthorizationHeader( + credentials.username, + credentials.password + ) + ); + localStorage.setItem( + USER_DATA_LOCAL_STORAGE_ITEM, + JSON.stringify(userData.data) + ); + return Promise.resolve(); + } + return Promise.reject(); + }, + logout: () => { + localStorage.removeItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + return Promise.resolve(); + }, + checkError: ({ status }: any) => { + if (status === 401 || status === 403) { + localStorage.removeItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + return Promise.reject(); + } + return Promise.resolve(); + }, + checkAuth: () => { + return localStorage.getItem(CREDENTIALS_LOCAL_STORAGE_ITEM) + ? Promise.resolve() + : Promise.reject(); + }, + getPermissions: () => Promise.reject("Unknown method"), + getIdentity: () => { + const str = localStorage.getItem(USER_DATA_LOCAL_STORAGE_ITEM); + const userData: LoginMutateResult = JSON.parse(str || ""); + + return Promise.resolve({ + id: userData.login.username, + fullName: userData.login.username, + avatar: undefined, + }); + }, +}; + +function createBasicAuthorizationHeader( + username: string, + password: string +): string { + return `Basic ${btoa(`${username}:${password}`)}`; +} diff --git a/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-jwt.ts b/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-jwt.ts new file mode 100644 index 00000000..c8bcafc0 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/auth-provider/ra-auth-jwt.ts @@ -0,0 +1,72 @@ +import { gql } from "@apollo/client/core"; +import { AuthProvider } from "react-admin"; +import { + CREDENTIALS_LOCAL_STORAGE_ITEM, + USER_DATA_LOCAL_STORAGE_ITEM, +} from "../constants"; +import { Credentials, LoginMutateResult } from "../types"; +import { apolloClient } from "../data-provider/graphqlDataProvider"; + +const LOGIN = gql` + mutation login($username: String!, $password: String!) { + login(credentials: { username: $username, password: $password }) { + username + accessToken + } + } +`; + +export const jwtAuthProvider: AuthProvider = { + login: async (credentials: Credentials) => { + const userData = await apolloClient.mutate({ + mutation: LOGIN, + variables: { + ...credentials, + }, + }); + + if (userData && userData.data?.login.username) { + localStorage.setItem( + CREDENTIALS_LOCAL_STORAGE_ITEM, + createBearerAuthorizationHeader(userData.data.login?.accessToken) + ); + localStorage.setItem( + USER_DATA_LOCAL_STORAGE_ITEM, + JSON.stringify(userData.data) + ); + return Promise.resolve(); + } + return Promise.reject(); + }, + logout: () => { + localStorage.removeItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + return Promise.resolve(); + }, + checkError: ({ status }: any) => { + if (status === 401 || status === 403) { + localStorage.removeItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + return Promise.reject(); + } + return Promise.resolve(); + }, + checkAuth: () => { + return localStorage.getItem(CREDENTIALS_LOCAL_STORAGE_ITEM) + ? Promise.resolve() + : Promise.reject(); + }, + getPermissions: () => Promise.reject("Unknown method"), + getIdentity: () => { + const str = localStorage.getItem(USER_DATA_LOCAL_STORAGE_ITEM); + const userData: LoginMutateResult = JSON.parse(str || ""); + + return Promise.resolve({ + id: userData.login.username, + fullName: userData.login.username, + avatar: undefined, + }); + }, +}; + +export function createBearerAuthorizationHeader(accessToken: string) { + return `Bearer ${accessToken}`; +} diff --git a/apps/cloud-provider-connector-admin/src/auth.ts b/apps/cloud-provider-connector-admin/src/auth.ts new file mode 100644 index 00000000..498b026b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/auth.ts @@ -0,0 +1,34 @@ +import { EventEmitter } from "events"; +import { CREDENTIALS_LOCAL_STORAGE_ITEM } from "./constants"; +import { Credentials } from "./types"; + +const eventEmitter = new EventEmitter(); + +export function isAuthenticated(): boolean { + return Boolean(getCredentials()); +} + +export function listen(listener: (authenticated: boolean) => void): void { + eventEmitter.on("change", () => { + listener(isAuthenticated()); + }); +} + +export function setCredentials(credentials: Credentials) { + localStorage.setItem( + CREDENTIALS_LOCAL_STORAGE_ITEM, + JSON.stringify(credentials) + ); +} + +export function getCredentials(): Credentials | null { + const raw = localStorage.getItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + if (raw === null) { + return null; + } + return JSON.parse(raw); +} + +export function removeCredentials(): void { + localStorage.removeItem(CREDENTIALS_LOCAL_STORAGE_ITEM); +} diff --git a/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionCreate.tsx b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionCreate.tsx new file mode 100644 index 00000000..d030fcbd --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionCreate.tsx @@ -0,0 +1,16 @@ +import * as React from "react"; +import { Create, SimpleForm, CreateProps, TextInput } from "react-admin"; + +export const AwsConnectionCreate = (props: CreateProps): React.ReactElement => { + return ( + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionEdit.tsx b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionEdit.tsx new file mode 100644 index 00000000..f08fcf04 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionEdit.tsx @@ -0,0 +1,16 @@ +import * as React from "react"; +import { Edit, SimpleForm, EditProps, TextInput } from "react-admin"; + +export const AwsConnectionEdit = (props: EditProps): React.ReactElement => { + return ( + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionList.tsx b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionList.tsx new file mode 100644 index 00000000..81e519ae --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionList.tsx @@ -0,0 +1,25 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, TextField, DateField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const AwsConnectionList = (props: ListProps): React.ReactElement => { + return ( + } + > + + + + + + + + + {" "} + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionShow.tsx b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionShow.tsx new file mode 100644 index 00000000..fe5b1a44 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionShow.tsx @@ -0,0 +1,25 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + TextField, + DateField, +} from "react-admin"; + +export const AwsConnectionShow = (props: ShowProps): React.ReactElement => { + return ( + + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionTitle.ts b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionTitle.ts new file mode 100644 index 00000000..051dacb8 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/awsConnection/AwsConnectionTitle.ts @@ -0,0 +1,7 @@ +import { AwsConnection as TAwsConnection } from "../api/awsConnection/AwsConnection"; + +export const AWSCONNECTION_TITLE_FIELD = "accessKeyId"; + +export const AwsConnectionTitle = (record: TAwsConnection): string => { + return record.accessKeyId?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionCreate.tsx b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionCreate.tsx new file mode 100644 index 00000000..d89f27d6 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionCreate.tsx @@ -0,0 +1,19 @@ +import * as React from "react"; +import { Create, SimpleForm, CreateProps, TextInput } from "react-admin"; + +export const AzureConnectionCreate = ( + props: CreateProps +): React.ReactElement => { + return ( + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionEdit.tsx b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionEdit.tsx new file mode 100644 index 00000000..a4494c25 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionEdit.tsx @@ -0,0 +1,17 @@ +import * as React from "react"; +import { Edit, SimpleForm, EditProps, TextInput } from "react-admin"; + +export const AzureConnectionEdit = (props: EditProps): React.ReactElement => { + return ( + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionList.tsx b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionList.tsx new file mode 100644 index 00000000..374223d5 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionList.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, TextField, DateField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const AzureConnectionList = (props: ListProps): React.ReactElement => { + return ( + } + > + + + + + + + + + + {" "} + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionShow.tsx b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionShow.tsx new file mode 100644 index 00000000..05abdd9c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionShow.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + TextField, + DateField, +} from "react-admin"; + +export const AzureConnectionShow = (props: ShowProps): React.ReactElement => { + return ( + + + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionTitle.ts b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionTitle.ts new file mode 100644 index 00000000..fb281cde --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/azureConnection/AzureConnectionTitle.ts @@ -0,0 +1,7 @@ +import { AzureConnection as TAzureConnection } from "../api/azureConnection/AzureConnection"; + +export const AZURECONNECTION_TITLE_FIELD = "clientId"; + +export const AzureConnectionTitle = (record: TAzureConnection): string => { + return record.clientId?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/constants.ts b/apps/cloud-provider-connector-admin/src/constants.ts new file mode 100644 index 00000000..4b3ca4bb --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/constants.ts @@ -0,0 +1,2 @@ +export const CREDENTIALS_LOCAL_STORAGE_ITEM = "credentials"; +export const USER_DATA_LOCAL_STORAGE_ITEM = "userData"; diff --git a/apps/cloud-provider-connector-admin/src/data-provider/graphqlDataProvider.ts b/apps/cloud-provider-connector-admin/src/data-provider/graphqlDataProvider.ts new file mode 100644 index 00000000..2deee266 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/data-provider/graphqlDataProvider.ts @@ -0,0 +1,28 @@ +import buildGraphQLProvider from "ra-data-graphql-amplication"; +import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client"; +import { setContext } from "@apollo/client/link/context"; +import { CREDENTIALS_LOCAL_STORAGE_ITEM } from "../constants"; + +const httpLink = createHttpLink({ + uri: `${import.meta.env.VITE_REACT_APP_SERVER_URL}/graphql`, +}); + +// eslint-disable-next-line @typescript-eslint/naming-convention +const authLink = setContext((_, { headers }) => { + const token = localStorage.getItem(CREDENTIALS_LOCAL_STORAGE_ITEM); + return { + headers: { + ...headers, + authorization: token ? token : "", + }, + }; +}); + +export const apolloClient = new ApolloClient({ + cache: new InMemoryCache(), + link: authLink.concat(httpLink), +}); + +export default buildGraphQLProvider({ + client: apolloClient, +}); diff --git a/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionCreate.tsx b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionCreate.tsx new file mode 100644 index 00000000..932d1cf2 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionCreate.tsx @@ -0,0 +1,19 @@ +import * as React from "react"; +import { Create, SimpleForm, CreateProps, TextInput } from "react-admin"; + +export const GcpConnectionCreate = (props: CreateProps): React.ReactElement => { + return ( + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionEdit.tsx b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionEdit.tsx new file mode 100644 index 00000000..9f427139 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionEdit.tsx @@ -0,0 +1,19 @@ +import * as React from "react"; +import { Edit, SimpleForm, EditProps, TextInput } from "react-admin"; + +export const GcpConnectionEdit = (props: EditProps): React.ReactElement => { + return ( + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionList.tsx b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionList.tsx new file mode 100644 index 00000000..6dc6b3d8 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionList.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, DateField, TextField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const GcpConnectionList = (props: ListProps): React.ReactElement => { + return ( + } + > + + + + + + + + {" "} + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionShow.tsx b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionShow.tsx new file mode 100644 index 00000000..50e584e7 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionShow.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + DateField, + TextField, +} from "react-admin"; + +export const GcpConnectionShow = (props: ShowProps): React.ReactElement => { + return ( + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionTitle.ts b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionTitle.ts new file mode 100644 index 00000000..847d3903 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/gcpConnection/GcpConnectionTitle.ts @@ -0,0 +1,7 @@ +import { GcpConnection as TGcpConnection } from "../api/gcpConnection/GcpConnection"; + +export const GCPCONNECTION_TITLE_FIELD = "projectId"; + +export const GcpConnectionTitle = (record: TGcpConnection): string => { + return record.projectId?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/index.css b/apps/cloud-provider-connector-admin/src/index.css new file mode 100644 index 00000000..86868480 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/index.css @@ -0,0 +1,26 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +#root { + height: 100vh; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} + +.amp-breadcrumbs { + padding: var(--default-spacing); +} + +.entity-id { + color: var(--primary); + text-decoration: underline; +} diff --git a/apps/cloud-provider-connector-admin/src/index.tsx b/apps/cloud-provider-connector-admin/src/index.tsx new file mode 100644 index 00000000..7467839c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/index.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import ReactDOM from "react-dom/client"; +import "./index.css"; +import App from "./App"; + +ReactDOM.createRoot(document.getElementById("root")!).render( + + + +); diff --git a/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateCreate.tsx b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateCreate.tsx new file mode 100644 index 00000000..ad2ddac5 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateCreate.tsx @@ -0,0 +1,34 @@ +import * as React from "react"; + +import { + Create, + SimpleForm, + CreateProps, + NumberInput, + BooleanInput, + TextInput, + ReferenceInput, + SelectInput, +} from "react-admin"; + +import { RegionTitle } from "../region/RegionTitle"; + +export const InstanceTemplateCreate = ( + props: CreateProps +): React.ReactElement => { + return ( + + + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateEdit.tsx b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateEdit.tsx new file mode 100644 index 00000000..1981e5e3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateEdit.tsx @@ -0,0 +1,32 @@ +import * as React from "react"; + +import { + Edit, + SimpleForm, + EditProps, + NumberInput, + BooleanInput, + TextInput, + ReferenceInput, + SelectInput, +} from "react-admin"; + +import { RegionTitle } from "../region/RegionTitle"; + +export const InstanceTemplateEdit = (props: EditProps): React.ReactElement => { + return ( + + + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateList.tsx b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateList.tsx new file mode 100644 index 00000000..9c672f64 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateList.tsx @@ -0,0 +1,40 @@ +import * as React from "react"; + +import { + List, + Datagrid, + ListProps, + TextField, + DateField, + BooleanField, + ReferenceField, +} from "react-admin"; + +import Pagination from "../Components/Pagination"; +import { REGION_TITLE_FIELD } from "../region/RegionTitle"; + +export const InstanceTemplateList = (props: ListProps): React.ReactElement => { + return ( + } + > + + + + + + + + + + + + + {" "} + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateShow.tsx b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateShow.tsx new file mode 100644 index 00000000..9dd16f47 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateShow.tsx @@ -0,0 +1,34 @@ +import * as React from "react"; + +import { + Show, + SimpleShowLayout, + ShowProps, + TextField, + DateField, + BooleanField, + ReferenceField, +} from "react-admin"; + +import { REGION_TITLE_FIELD } from "../region/RegionTitle"; + +export const InstanceTemplateShow = (props: ShowProps): React.ReactElement => { + return ( + + + + + + + + + + + + + + + + + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateTitle.ts b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateTitle.ts new file mode 100644 index 00000000..7d304715 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/instanceTemplate/InstanceTemplateTitle.ts @@ -0,0 +1,7 @@ +import { InstanceTemplate as TInstanceTemplate } from "../api/instanceTemplate/InstanceTemplate"; + +export const INSTANCETEMPLATE_TITLE_FIELD = "name"; + +export const InstanceTemplateTitle = (record: TInstanceTemplate): string => { + return record.name?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/login.scss b/apps/cloud-provider-connector-admin/src/login.scss new file mode 100644 index 00000000..667d8d2b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/login.scss @@ -0,0 +1,119 @@ +:root { + --surface: #15192c; /*dark: black100 */ + --white: #15192c; /*dark: black100 */ + + --black100: #ffffff; /*dark: white */ + --black90: #b7bac7; /*dark: black10 */ + --black80: #a3a8b8; /*dark: black20 */ + --black60: #80869d; /*dark: black30 */ + --black40: #686f8c; /*dark: black40 */ + --black30: #515873; /*dark: black50 */ + --black20: #444b66; /*dark: black60 */ + --black10: #373d57; /*dark: black70 */ + --black5: #2c3249; /*dark: black80 */ + --black2: #22273c; /*dark: black90 */ + + --primary: #7950ed; +} + +.login-page { + height: 100vh; + width: 100%; + background-color: var(--surface); + color: var(--black100); + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + + &__wrapper { + display: flex; + align-items: stretch; + justify-content: center; + flex-direction: row; + } + + &__box { + text-align: center; + width: 340px; + background-color: var(--black2); + border-radius: var(--small-border-radius); + margin: 1rem; + padding: 1rem; + border: 1px solid var(--black10); + display: flex; + flex-direction: column; + align-items: center; + justify-content: stretch; + + h2 { + font-size: 18px; + } + img { + width: 48px; + } + + &__message { + color: var(--black80); + font-size: 14px; + line-height: 22px; + } + + button, + .MuiButton-contained { + box-sizing: border-box; + background-color: var(--primary); + width: 300px; + margin-top: 0.5rem; + margin-bottom: 1rem; + margin-top: auto; + &:hover, + &:active, + &:focus { + background-color: var(--primary); + } + } + } + + form { + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; + margin-top: 2rem; + + label { + span { + display: block; + text-align: left; + font-size: 12px; + color: var(--black60); + } + } + + input { + box-sizing: border-box; + background-color: var(--white); + border: 1px solid var(--black10); + padding: 0.5rem; + margin-bottom: 1rem; + outline: none; + border-radius: var(--small-border-radius); + width: 300px; + color: var(--black100); + &:hover, + &:active, + &:focus { + border: 1px solid var(--black100); + } + } + } + + &__read-more { + color: var(--black80); + a { + color: var(--black100); + text-decoration: none; + } + } +} diff --git a/apps/cloud-provider-connector-admin/src/pages/Dashboard.tsx b/apps/cloud-provider-connector-admin/src/pages/Dashboard.tsx new file mode 100644 index 00000000..29776bc2 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/pages/Dashboard.tsx @@ -0,0 +1,12 @@ +import * as React from "react"; +import Card from "@mui/material/Card"; +import CardContent from "@mui/material/CardContent"; +import { Title } from "react-admin"; +const Dashboard = () => ( + + + <CardContent>Welcome</CardContent> + </Card> +); + +export default Dashboard; diff --git a/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogCreate.tsx b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogCreate.tsx new file mode 100644 index 00000000..e832e8d5 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogCreate.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Create, + SimpleForm, + CreateProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const ProviderLogCreate = (props: CreateProps): React.ReactElement => { + return ( + <Create {...props}> + <SimpleForm> + <TextInput label="action" source="action" /> + <TextInput label="provider" source="provider" /> + <div /> + <div /> + <TextInput label="status" source="status" /> + <DateTimeInput label="timestamp" source="timestamp" /> + <TextInput label="userProfile" source="userProfile" /> + </SimpleForm> + </Create> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogEdit.tsx b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogEdit.tsx new file mode 100644 index 00000000..4e56c53c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogEdit.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Edit, + SimpleForm, + EditProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const ProviderLogEdit = (props: EditProps): React.ReactElement => { + return ( + <Edit {...props}> + <SimpleForm> + <TextInput label="action" source="action" /> + <TextInput label="provider" source="provider" /> + <div /> + <div /> + <TextInput label="status" source="status" /> + <DateTimeInput label="timestamp" source="timestamp" /> + <TextInput label="userProfile" source="userProfile" /> + </SimpleForm> + </Edit> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogList.tsx b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogList.tsx new file mode 100644 index 00000000..f0345790 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogList.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, TextField, DateField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const ProviderLogList = (props: ListProps): React.ReactElement => { + return ( + <List + {...props} + title={"ProviderLogs"} + perPage={50} + pagination={<Pagination />} + > + <Datagrid rowClick="show" bulkActionButtons={false}> + <TextField label="action" source="action" /> + <DateField source="createdAt" label="Created At" /> + <TextField label="ID" source="id" /> + <TextField label="provider" source="provider" /> + <TextField label="request" source="request" /> + <TextField label="response" source="response" /> + <TextField label="status" source="status" /> + <TextField label="timestamp" source="timestamp" /> + <DateField source="updatedAt" label="Updated At" /> + <TextField label="userProfile" source="userProfile" />{" "} + </Datagrid> + </List> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogShow.tsx b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogShow.tsx new file mode 100644 index 00000000..e2f4e330 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogShow.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + TextField, + DateField, +} from "react-admin"; + +export const ProviderLogShow = (props: ShowProps): React.ReactElement => { + return ( + <Show {...props}> + <SimpleShowLayout> + <TextField label="action" source="action" /> + <DateField source="createdAt" label="Created At" /> + <TextField label="ID" source="id" /> + <TextField label="provider" source="provider" /> + <TextField label="request" source="request" /> + <TextField label="response" source="response" /> + <TextField label="status" source="status" /> + <TextField label="timestamp" source="timestamp" /> + <DateField source="updatedAt" label="Updated At" /> + <TextField label="userProfile" source="userProfile" /> + </SimpleShowLayout> + </Show> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogTitle.ts b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogTitle.ts new file mode 100644 index 00000000..c6c9341a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/providerLog/ProviderLogTitle.ts @@ -0,0 +1,7 @@ +import { ProviderLog as TProviderLog } from "../api/providerLog/ProviderLog"; + +export const PROVIDERLOG_TITLE_FIELD = "action"; + +export const ProviderLogTitle = (record: TProviderLog): string => { + return record.action?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/region/RegionCreate.tsx b/apps/cloud-provider-connector-admin/src/region/RegionCreate.tsx new file mode 100644 index 00000000..9649f141 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/region/RegionCreate.tsx @@ -0,0 +1,34 @@ +import * as React from "react"; + +import { + Create, + SimpleForm, + CreateProps, + TextInput, + ReferenceArrayInput, + SelectArrayInput, +} from "react-admin"; + +import { InstanceTemplateTitle } from "../instanceTemplate/InstanceTemplateTitle"; + +export const RegionCreate = (props: CreateProps): React.ReactElement => { + return ( + <Create {...props}> + <SimpleForm> + <TextInput label="description" source="description" /> + <ReferenceArrayInput + source="instanceTemplates" + reference="InstanceTemplate" + > + <SelectArrayInput + optionText={InstanceTemplateTitle} + parse={(value: any) => value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> + </ReferenceArrayInput> + <TextInput label="name" source="name" /> + <TextInput label="provider" source="provider" /> + </SimpleForm> + </Create> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/region/RegionEdit.tsx b/apps/cloud-provider-connector-admin/src/region/RegionEdit.tsx new file mode 100644 index 00000000..911499fa --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/region/RegionEdit.tsx @@ -0,0 +1,34 @@ +import * as React from "react"; + +import { + Edit, + SimpleForm, + EditProps, + TextInput, + ReferenceArrayInput, + SelectArrayInput, +} from "react-admin"; + +import { InstanceTemplateTitle } from "../instanceTemplate/InstanceTemplateTitle"; + +export const RegionEdit = (props: EditProps): React.ReactElement => { + return ( + <Edit {...props}> + <SimpleForm> + <TextInput label="description" source="description" /> + <ReferenceArrayInput + source="instanceTemplates" + reference="InstanceTemplate" + > + <SelectArrayInput + optionText={InstanceTemplateTitle} + parse={(value: any) => value && value.map((v: any) => ({ id: v }))} + format={(value: any) => value && value.map((v: any) => v.id)} + /> + </ReferenceArrayInput> + <TextInput label="name" source="name" /> + <TextInput label="provider" source="provider" /> + </SimpleForm> + </Edit> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/region/RegionList.tsx b/apps/cloud-provider-connector-admin/src/region/RegionList.tsx new file mode 100644 index 00000000..dda6ec8c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/region/RegionList.tsx @@ -0,0 +1,18 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, DateField, TextField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const RegionList = (props: ListProps): React.ReactElement => { + return ( + <List {...props} title={"Regions"} perPage={50} pagination={<Pagination />}> + <Datagrid rowClick="show" bulkActionButtons={false}> + <DateField source="createdAt" label="Created At" /> + <TextField label="description" source="description" /> + <TextField label="ID" source="id" /> + <TextField label="name" source="name" /> + <TextField label="provider" source="provider" /> + <DateField source="updatedAt" label="Updated At" />{" "} + </Datagrid> + </List> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/region/RegionShow.tsx b/apps/cloud-provider-connector-admin/src/region/RegionShow.tsx new file mode 100644 index 00000000..8e92c0c3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/region/RegionShow.tsx @@ -0,0 +1,54 @@ +import * as React from "react"; + +import { + Show, + SimpleShowLayout, + ShowProps, + DateField, + TextField, + ReferenceManyField, + Datagrid, + BooleanField, + ReferenceField, +} from "react-admin"; + +import { REGION_TITLE_FIELD } from "./RegionTitle"; + +export const RegionShow = (props: ShowProps): React.ReactElement => { + return ( + <Show {...props}> + <SimpleShowLayout> + <DateField source="createdAt" label="Created At" /> + <TextField label="description" source="description" /> + <TextField label="ID" source="id" /> + <TextField label="name" source="name" /> + <TextField label="provider" source="provider" /> + <DateField source="updatedAt" label="Updated At" /> + <ReferenceManyField + reference="InstanceTemplate" + target="regionId" + label="InstanceTemplates" + > + <Datagrid rowClick="show" bulkActionButtons={false}> + <TextField label="cpu" source="cpu" /> + <DateField source="createdAt" label="Created At" /> + <BooleanField label="hasGpu" source="hasGpu" /> + <TextField label="ID" source="id" /> + <TextField label="memoryGB" source="memoryGb" /> + <TextField label="name" source="name" /> + <TextField label="provider" source="provider" /> + <ReferenceField + label="region" + source="region.id" + reference="Region" + > + <TextField source={REGION_TITLE_FIELD} /> + </ReferenceField> + <TextField label="storageGB" source="storageGb" /> + <DateField source="updatedAt" label="Updated At" /> + </Datagrid> + </ReferenceManyField> + </SimpleShowLayout> + </Show> + ); +}; diff --git a/apps/cloud-provider-connector-admin/src/region/RegionTitle.ts b/apps/cloud-provider-connector-admin/src/region/RegionTitle.ts new file mode 100644 index 00000000..0ca30dc2 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/region/RegionTitle.ts @@ -0,0 +1,7 @@ +import { Region as TRegion } from "../api/region/Region"; + +export const REGION_TITLE_FIELD = "name"; + +export const RegionTitle = (record: TRegion): string => { + return record.name?.toString() || String(record.id); +}; diff --git a/apps/cloud-provider-connector-admin/src/reportWebVitals.ts b/apps/cloud-provider-connector-admin/src/reportWebVitals.ts new file mode 100644 index 00000000..821a6cde --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/reportWebVitals.ts @@ -0,0 +1,17 @@ +import { ReportHandler } from "web-vitals"; + +const reportWebVitals = (onPerfEntry?: ReportHandler): void => { + if (onPerfEntry && onPerfEntry instanceof Function) { + void import("web-vitals").then( + ({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + } + ); + } +}; + +export default reportWebVitals; diff --git a/apps/cloud-provider-connector-admin/src/setupTests.ts b/apps/cloud-provider-connector-admin/src/setupTests.ts new file mode 100644 index 00000000..1dd407a6 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/setupTests.ts @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import "@testing-library/jest-dom"; diff --git a/apps/cloud-provider-connector-admin/src/theme/theme.ts b/apps/cloud-provider-connector-admin/src/theme/theme.ts new file mode 100644 index 00000000..bcfca0e6 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/theme/theme.ts @@ -0,0 +1,33 @@ +import { defaultTheme } from "react-admin"; +import { createTheme, ThemeOptions } from "@mui/material/styles"; +import { merge } from "lodash"; +import createPalette from "@mui/material/styles/createPalette"; + +const palette = createPalette( + merge({}, defaultTheme.palette, { + primary: { + main: "#20a4f3", + }, + secondary: { + main: "#7950ed", + }, + error: { + main: "#e93c51", + }, + warning: { + main: "#f6aa50", + }, + info: { + main: "#144bc1", + }, + success: { + main: "#31c587", + }, + }) +); + +const themeOptions: ThemeOptions = { + palette, +}; + +export const theme = createTheme(merge({}, defaultTheme, themeOptions)); diff --git a/apps/cloud-provider-connector-admin/src/types.ts b/apps/cloud-provider-connector-admin/src/types.ts new file mode 100644 index 00000000..45a457df --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/types.ts @@ -0,0 +1,13 @@ +import { JsonValue } from "type-fest"; + +export type Credentials = { + username: string; + password: string; +}; +export type LoginMutateResult = { + login: { + username: string; + accessToken: string; + }; +}; +export type InputJsonValue = Omit<JsonValue, "null">; diff --git a/apps/cloud-provider-connector-admin/src/user/EnumRoles.ts b/apps/cloud-provider-connector-admin/src/user/EnumRoles.ts new file mode 100644 index 00000000..3df7048d --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/user/EnumRoles.ts @@ -0,0 +1,3 @@ +export enum EnumRoles { + User = "user", +} diff --git a/apps/cloud-provider-connector-admin/src/user/RolesOptions.ts b/apps/cloud-provider-connector-admin/src/user/RolesOptions.ts new file mode 100644 index 00000000..5e30fe9a --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/user/RolesOptions.ts @@ -0,0 +1,11 @@ +import { ROLES } from "./roles"; + +declare interface Role { + name: string; + displayName: string; +} + +export const ROLES_OPTIONS = ROLES.map((role: Role) => ({ + value: role.name, + label: role.displayName, +})); diff --git a/apps/cloud-provider-connector-admin/src/user/roles.ts b/apps/cloud-provider-connector-admin/src/user/roles.ts new file mode 100644 index 00000000..732870a1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/user/roles.ts @@ -0,0 +1,6 @@ +export const ROLES = [ + { + name: "user", + displayName: "User", + }, +]; diff --git a/apps/cloud-provider-connector-admin/src/util/BooleanFilter.ts b/apps/cloud-provider-connector-admin/src/util/BooleanFilter.ts new file mode 100644 index 00000000..a142d58c --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/BooleanFilter.ts @@ -0,0 +1,4 @@ +export class BooleanFilter { + equals?: boolean; + not?: boolean; +} diff --git a/apps/cloud-provider-connector-admin/src/util/BooleanNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/BooleanNullableFilter.ts new file mode 100644 index 00000000..b94aefce --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/BooleanNullableFilter.ts @@ -0,0 +1,4 @@ +export class BooleanNullableFilter { + equals?: boolean | null; + not?: boolean | null; +} diff --git a/apps/cloud-provider-connector-admin/src/util/DateTimeFilter.ts b/apps/cloud-provider-connector-admin/src/util/DateTimeFilter.ts new file mode 100644 index 00000000..cd8d2139 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/DateTimeFilter.ts @@ -0,0 +1,10 @@ +export class DateTimeFilter { + equals?: Date; + not?: Date; + in?: Date[]; + notIn?: Date[]; + lt?: Date; + lte?: Date; + gt?: Date; + gte?: Date; +} diff --git a/apps/cloud-provider-connector-admin/src/util/DateTimeNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/DateTimeNullableFilter.ts new file mode 100644 index 00000000..2f9c7b3b --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/DateTimeNullableFilter.ts @@ -0,0 +1,10 @@ +export class DateTimeNullableFilter { + equals?: Date | null; + in?: Date[] | null; + notIn?: Date[] | null; + lt?: Date; + lte?: Date; + gt?: Date; + gte?: Date; + not?: Date; +} diff --git a/apps/cloud-provider-connector-admin/src/util/FloatFilter.ts b/apps/cloud-provider-connector-admin/src/util/FloatFilter.ts new file mode 100644 index 00000000..62aeb145 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/FloatFilter.ts @@ -0,0 +1,10 @@ +export class FloatFilter { + equals?: number; + in?: number[]; + notIn?: number[]; + lt?: number; + lte?: number; + gt?: number; + gte?: number; + not?: number; +} diff --git a/apps/cloud-provider-connector-admin/src/util/FloatNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/FloatNullableFilter.ts new file mode 100644 index 00000000..d7bb1635 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/FloatNullableFilter.ts @@ -0,0 +1,10 @@ +export class FloatNullableFilter { + equals?: number | null; + in?: number[] | null; + notIn?: number[] | null; + lt?: number; + lte?: number; + gt?: number; + gte?: number; + not?: number; +} diff --git a/apps/cloud-provider-connector-admin/src/util/IntFilter.ts b/apps/cloud-provider-connector-admin/src/util/IntFilter.ts new file mode 100644 index 00000000..3dc02212 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/IntFilter.ts @@ -0,0 +1,10 @@ +export class IntFilter { + equals?: number; + in?: number[]; + notIn?: number[]; + lt?: number; + lte?: number; + gt?: number; + gte?: number; + not?: number; +} diff --git a/apps/cloud-provider-connector-admin/src/util/IntNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/IntNullableFilter.ts new file mode 100644 index 00000000..2107cae8 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/IntNullableFilter.ts @@ -0,0 +1,10 @@ +export class IntNullableFilter { + equals?: number | null; + in?: number[] | null; + notIn?: number[] | null; + lt?: number; + lte?: number; + gt?: number; + gte?: number; + not?: number; +} diff --git a/apps/cloud-provider-connector-admin/src/util/JsonFilter.ts b/apps/cloud-provider-connector-admin/src/util/JsonFilter.ts new file mode 100644 index 00000000..cc447632 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/JsonFilter.ts @@ -0,0 +1,5 @@ +import { InputJsonValue } from "../types"; +export class JsonFilter { + equals?: InputJsonValue; + not?: InputJsonValue; +} diff --git a/apps/cloud-provider-connector-admin/src/util/JsonNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/JsonNullableFilter.ts new file mode 100644 index 00000000..e6d15066 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/JsonNullableFilter.ts @@ -0,0 +1,5 @@ +import { JsonValue } from "type-fest"; +export class JsonNullableFilter { + equals?: JsonValue | null; + not?: JsonValue | null; +} diff --git a/apps/cloud-provider-connector-admin/src/util/MetaQueryPayload.ts b/apps/cloud-provider-connector-admin/src/util/MetaQueryPayload.ts new file mode 100644 index 00000000..bc3175b1 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/MetaQueryPayload.ts @@ -0,0 +1,3 @@ +export class MetaQueryPayload { + count!: number; +} diff --git a/apps/cloud-provider-connector-admin/src/util/QueryMode.ts b/apps/cloud-provider-connector-admin/src/util/QueryMode.ts new file mode 100644 index 00000000..8a2164e0 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/QueryMode.ts @@ -0,0 +1,4 @@ +export enum QueryMode { + Default = "default", + Insensitive = "insensitive", +} diff --git a/apps/cloud-provider-connector-admin/src/util/SortOrder.ts b/apps/cloud-provider-connector-admin/src/util/SortOrder.ts new file mode 100644 index 00000000..a5bcdb67 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/SortOrder.ts @@ -0,0 +1,4 @@ +export enum SortOrder { + Asc = "asc", + Desc = "desc", +} diff --git a/apps/cloud-provider-connector-admin/src/util/StringFilter.ts b/apps/cloud-provider-connector-admin/src/util/StringFilter.ts new file mode 100644 index 00000000..c2e26c5d --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/StringFilter.ts @@ -0,0 +1,16 @@ +import { QueryMode } from "./QueryMode"; + +export class StringFilter { + equals?: string; + in?: string[]; + notIn?: string[]; + lt?: string; + lte?: string; + gt?: string; + gte?: string; + contains?: string; + startsWith?: string; + endsWith?: string; + mode?: QueryMode; + not?: string; +} diff --git a/apps/cloud-provider-connector-admin/src/util/StringNullableFilter.ts b/apps/cloud-provider-connector-admin/src/util/StringNullableFilter.ts new file mode 100644 index 00000000..e1e37ec3 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/util/StringNullableFilter.ts @@ -0,0 +1,15 @@ +import { QueryMode } from "./QueryMode"; +export class StringNullableFilter { + equals?: string | null; + in?: string[] | null; + notIn?: string[] | null; + lt?: string; + lte?: string; + gt?: string; + gte?: string; + contains?: string; + startsWith?: string; + endsWith?: string; + mode?: QueryMode; + not?: string; +} diff --git a/apps/cloud-provider-connector-admin/src/vite-env.d.ts b/apps/cloud-provider-connector-admin/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/apps/cloud-provider-connector-admin/src/vite-env.d.ts @@ -0,0 +1 @@ +/// <reference types="vite/client" /> diff --git a/apps/cloud-provider-connector-admin/tsconfig.json b/apps/cloud-provider-connector-admin/tsconfig.json new file mode 100644 index 00000000..31cc7800 --- /dev/null +++ b/apps/cloud-provider-connector-admin/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "strict": true + }, + "include": ["src"], + "exclude": ["./node_modules"] +} diff --git a/apps/cloud-provider-connector-admin/vite.config.ts b/apps/cloud-provider-connector-admin/vite.config.ts new file mode 100644 index 00000000..cf64d08c --- /dev/null +++ b/apps/cloud-provider-connector-admin/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/apps/cloud-provider-connector-server/.dockerignore b/apps/cloud-provider-connector-server/.dockerignore new file mode 100644 index 00000000..cb5c30bb --- /dev/null +++ b/apps/cloud-provider-connector-server/.dockerignore @@ -0,0 +1,8 @@ +.dockerignore +docker-compose.yml +Dockerfile +dist/ +node_modules +.env +.gitignore +.prettierignore \ No newline at end of file diff --git a/apps/cloud-provider-connector-server/.env b/apps/cloud-provider-connector-server/.env new file mode 100644 index 00000000..1e2f3efc --- /dev/null +++ b/apps/cloud-provider-connector-server/.env @@ -0,0 +1,8 @@ +BCRYPT_SALT=10 +COMPOSE_PROJECT_NAME=amp_cmb5pom850tfvjwsi455bpkte +DB_NAME=my-db +DB_PASSWORD=admin +DB_PORT=5432 +DB_URL=postgres://admin:admin@localhost:5432/my-db +DB_USER=admin +PORT=3000 \ No newline at end of file diff --git a/apps/cloud-provider-connector-server/.gitignore b/apps/cloud-provider-connector-server/.gitignore new file mode 100644 index 00000000..08c9980f --- /dev/null +++ b/apps/cloud-provider-connector-server/.gitignore @@ -0,0 +1,5 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +/node_modules +/dist +.DS_Store diff --git a/apps/cloud-provider-connector-server/.prettierignore b/apps/cloud-provider-connector-server/.prettierignore new file mode 100644 index 00000000..e48f3559 --- /dev/null +++ b/apps/cloud-provider-connector-server/.prettierignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +prisma/migrations/ +package-lock.json +coverage/ \ No newline at end of file diff --git a/apps/cloud-provider-connector-server/Dockerfile b/apps/cloud-provider-connector-server/Dockerfile new file mode 100644 index 00000000..80dd8d37 --- /dev/null +++ b/apps/cloud-provider-connector-server/Dockerfile @@ -0,0 +1,68 @@ +# multi-stage: base (build) +FROM node:18.13.0 AS base + +# create directory where the application will be built +WORKDIR /app + +# copy over the dependency manifests, both the package.json +# and the package-lock.json are copied over +COPY package*.json ./ + +# installs packages and their dependencies +RUN npm install + +# copy over the prisma schema +COPY prisma/schema.prisma ./prisma/ + +# generate the prisma client based on the schema +RUN npm run prisma:generate + +# copy over the code base +COPY . . + +# create the bundle of the application +RUN npm run build + +# multi-stage: production (runtime) +FROM node:18.13.0-slim AS production + +# create arguments of builds time variables +ARG user=amplication +ARG group=${user} +ARG uid=1001 +ARG gid=$uid + +# [temporary] work around to be able to run prisma +RUN apt-get update -y && apt-get install -y openssl + +# create directory where the application will be executed from +WORKDIR /app + +# add the user and group +RUN groupadd --gid ${gid} ${user} +RUN useradd --uid ${uid} --gid ${gid} -m ${user} + +# copy over the bundled code from the build stage +COPY --from=base /app/node_modules/ ./node_modules +COPY --from=base /app/package.json ./package.json +COPY --from=base /app/dist ./dist +COPY --from=base /app/prisma ./prisma +COPY --from=base /app/scripts ./scripts +COPY --from=base /app/src ./src +COPY --from=base /app/tsconfig* ./ + +# change ownership of the workspace directory +RUN chown -R ${uid}:${gid} /app/ + +# get rid of the development dependencies +RUN npm install --production + +# set user to the created non-privileged user +USER ${user} + +# expose a specific port on the docker container +ENV PORT=3000 +EXPOSE ${PORT} + +# start the server using the previously build application +CMD [ "node", "./dist/main.js" ] diff --git a/apps/cloud-provider-connector-server/README.md b/apps/cloud-provider-connector-server/README.md new file mode 100644 index 00000000..bca0445d --- /dev/null +++ b/apps/cloud-provider-connector-server/README.md @@ -0,0 +1,64 @@ +<p align="right"> + <a href="https://amplication.com" target="_blank"> + <img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/logo.svg"/> + </a> +</p> + +# Introduction + +This service was generated with Amplication. The server-side of the generated project. This component provides the different backend services - i.e., REST API, GraphQL API, authentication, authorization, logging, data validation and the connection to the database. Additional information about the server component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site. + +# Getting started + +## Step 1: Configuration + +Configuration for the server component can be provided through the use of environment variables. These can be passed to the application via the use of the `.env` file in the base directory of the generated service. Below a table can be found which show the different variables that can be passed - these are the variables which exist by default, through the use of plugins additional integrations could require additional values. These values are provided default values after generation, change them to the desired values. + +| Variable | Description | Value | +| -------------------- | -------------------------------------------- | ------------------------------------------------------------------- | +| BCRYPT_SALT | the string used for hashing | [random-string] | +| COMPOSE_PROJECT_NAME | the identifier of the service plus prefix | amp_[service-identifier] | +| PORT | the port on which to run the server | 3000 | +| DB_URL | the connection url for the database | [db-provider]://[username]:[password]@localhost:[db-port]/[db-name] | +| DB_PORT | the port used by the database instance | [db-provider-port] | +| DB_USER | the username used to connect to the database | [username] | +| DB_PASSWORD | the password used to connect to the database | [password] | +| DB_NAME | the name of the database | [service-name] / [project-name] | +| JWT_SECRET_KEY | the secret used to sign the json-web token | [secret] | +| JWT_EXPIRATION | the expiration time for the json-web token | 2d | + +> **Note** +> Amplication generates default values and stores them under the .env file. It is advised to use some form of secrets manager/vault solution when using in production. + +## Step 2.1: Scripts - pre-requisites + +After configuration of the server the next step would be to run the application. Before running the server side of the component, make sure that the different pre-requisites are met - i.e., node.js [^16.x], npm, docker. After the setup of the pre-requisites the server component can be started. + +```sh +# installation of the dependencies +$ npm install + +# generate the prisma client +$ npm run prisma:generate +``` + +## Step 2.2: Scripts - local development + +```sh +# start the database where the server component will connect to +$ npm run docker:dev + +# initialize the database +$ npm run db:init + +# start the server component +$ npm run start +``` +By default, your app comes with one user with the username "admin" and password "admin". + +## Step 2.2: Scripts - container based development + +```shell +# start the server component as a docker container +$ npm run compose:up +``` diff --git a/apps/cloud-provider-connector-server/docker-compose.dev.yml b/apps/cloud-provider-connector-server/docker-compose.dev.yml new file mode 100644 index 00000000..8d7c3589 --- /dev/null +++ b/apps/cloud-provider-connector-server/docker-compose.dev.yml @@ -0,0 +1,13 @@ +version: "3" +services: + db: + image: postgres:12 + ports: + - ${DB_PORT}:5432 + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + volumes: + - postgres:/var/lib/postgresql/data +volumes: + postgres: ~ diff --git a/apps/cloud-provider-connector-server/docker-compose.yml b/apps/cloud-provider-connector-server/docker-compose.yml new file mode 100644 index 00000000..ef3a7a5f --- /dev/null +++ b/apps/cloud-provider-connector-server/docker-compose.yml @@ -0,0 +1,47 @@ +version: "3" +services: + server: + build: + context: . + args: + NPM_LOG_LEVEL: notice + ports: + - ${PORT}:3000 + environment: + BCRYPT_SALT: ${BCRYPT_SALT} + DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME} + depends_on: + - migrate + restart: on-failure + migrate: + build: + context: . + args: + NPM_LOG_LEVEL: notice + command: npm run db:init + working_dir: /app/server + environment: + BCRYPT_SALT: ${BCRYPT_SALT} + DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME} + depends_on: + db: + condition: service_healthy + db: + image: postgres:12 + ports: + - ${DB_PORT}:5432 + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_NAME} + volumes: + - postgres:/var/lib/postgresql/data + healthcheck: + test: + - CMD-SHELL + - pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER} + timeout: 45s + interval: 10s + retries: 10 +volumes: + postgres: ~ diff --git a/apps/cloud-provider-connector-server/nest-cli.json b/apps/cloud-provider-connector-server/nest-cli.json new file mode 100644 index 00000000..b7b60ae9 --- /dev/null +++ b/apps/cloud-provider-connector-server/nest-cli.json @@ -0,0 +1,10 @@ +{ + "sourceRoot": "src", + "compilerOptions": { + "assets": [ + { + "include": "swagger/**/*" + } + ] + } +} diff --git a/apps/cloud-provider-connector-server/package.json b/apps/cloud-provider-connector-server/package.json new file mode 100644 index 00000000..f01a8630 --- /dev/null +++ b/apps/cloud-provider-connector-server/package.json @@ -0,0 +1,76 @@ +{ + "name": "@cloud-provider-connector/server", + "private": true, + "scripts": { + "start": "nest start", + "start:watch": "nest start --watch", + "start:debug": "nest start --debug --watch", + "build": "nest build", + "test": "jest", + "seed": "ts-node scripts/seed.ts", + "db:migrate-save": "prisma migrate dev", + "db:migrate-up": "prisma migrate deploy", + "db:clean": "prisma migrate reset", + "db:init": "run-s \"db:migrate-save -- --name 'initial version'\" db:migrate-up seed", + "prisma:generate": "prisma generate", + "docker:dev": "docker-compose -f docker-compose.dev.yml up -d", + "package:container": "docker build .", + "compose:up": "docker-compose up -d", + "compose:down": "docker-compose down --volumes" + }, + "dependencies": { + "@apollo/server": "^4.9.4", + "@nestjs/apollo": "12.0.9", + "@nestjs/common": "10.2.7", + "@nestjs/config": "3.1.1", + "@nestjs/core": "10.2.7", + "@nestjs/graphql": "12.0.9", + "@nestjs/jwt": "^10.1.1", + "@nestjs/passport": "^10.0.2", + "@nestjs/platform-express": "10.2.7", + "@nestjs/serve-static": "4.0.0", + "@nestjs/swagger": "7.1.13", + "@prisma/client": "^5.4.2", + "@types/bcrypt": "5.0.0", + "bcrypt": "5.1.1", + "class-transformer": "0.5.1", + "class-validator": "0.14.0", + "dotenv": "16.3.1", + "graphql": "^16.8.1", + "graphql-type-json": "0.3.2", + "npm-run-all": "4.1.5", + "passport": "0.6.0", + "passport-http": "0.3.0", + "passport-jwt": "4.0.1", + "reflect-metadata": "0.1.13", + "ts-node": "10.9.2", + "type-fest": "2.19.0", + "validator": "13.11.0" + }, + "devDependencies": { + "@nestjs/cli": "^10.1.18", + "@nestjs/testing": "^10.2.7", + "@types/express": "^4.17.19", + "@types/graphql-type-json": "0.3.3", + "@types/jest": "^29.5.5", + "@types/normalize-path": "3.0.0", + "@types/passport-http": "0.3.9", + "@types/passport-jwt": "3.0.10", + "@types/supertest": "^2.0.14", + "@types/validator": "^13.11.2", + "jest": "^29.7.0", + "jest-mock-extended": "^3.0.5", + "prisma": "^5.4.2", + "supertest": "^6.3.3", + "ts-jest": "^29.1.1", + "typescript": "^5.4.3" + }, + "jest": { + "preset": "ts-jest", + "testEnvironment": "node", + "moduleNameMapper": { + "@app/custom-validators": "<rootDir>/src/validators" + }, + "modulePathIgnorePatterns": ["<rootDir>/dist/"] + } +} diff --git a/apps/cloud-provider-connector-server/prisma/schema.prisma b/apps/cloud-provider-connector-server/prisma/schema.prisma new file mode 100644 index 00000000..feba8b81 --- /dev/null +++ b/apps/cloud-provider-connector-server/prisma/schema.prisma @@ -0,0 +1,78 @@ +datasource db { + provider = "postgresql" + url = env("DB_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model AzureConnection { + clientId String? + clientSecret String? + createdAt DateTime @default(now()) + id String @id @default(cuid()) + region String? + subscriptionId String? + tenantId String? + updatedAt DateTime @updatedAt + userProfile String? +} + +model AwsConnection { + accessKeyId String? + createdAt DateTime @default(now()) + id String @id @default(cuid()) + region String? + secretAccessKey String? + sessionToken String? + updatedAt DateTime @updatedAt + userProfile String? +} + +model GcpConnection { + createdAt DateTime @default(now()) + id String @id @default(cuid()) + projectId String? + region String? + serviceAccountJson String? + updatedAt DateTime @updatedAt + userProfile String? +} + +model InstanceTemplate { + cpu Int? + createdAt DateTime @default(now()) + hasGpu Boolean? + id String @id @default(cuid()) + memoryGb Int? + name String? + provider String? + region Region? @relation(fields: [regionId], references: [id]) + regionId String? + storageGb Int? + updatedAt DateTime @updatedAt +} + +model ProviderLog { + action String? + createdAt DateTime @default(now()) + id String @id @default(cuid()) + provider String? + request Json? + response Json? + status String? + timestamp DateTime? + updatedAt DateTime @updatedAt + userProfile String? +} + +model Region { + createdAt DateTime @default(now()) + description String? + id String @id @default(cuid()) + instanceTemplates InstanceTemplate[] + name String? + provider String? + updatedAt DateTime @updatedAt +} diff --git a/apps/cloud-provider-connector-server/scripts/customSeed.ts b/apps/cloud-provider-connector-server/scripts/customSeed.ts new file mode 100644 index 00000000..26ccaf4c --- /dev/null +++ b/apps/cloud-provider-connector-server/scripts/customSeed.ts @@ -0,0 +1,7 @@ +import { PrismaClient } from "@prisma/client"; + +export async function customSeed() { + const client = new PrismaClient(); + + client.$disconnect(); +} diff --git a/apps/cloud-provider-connector-server/scripts/seed.ts b/apps/cloud-provider-connector-server/scripts/seed.ts new file mode 100644 index 00000000..04cee655 --- /dev/null +++ b/apps/cloud-provider-connector-server/scripts/seed.ts @@ -0,0 +1,25 @@ +import * as dotenv from "dotenv"; +import { PrismaClient } from "@prisma/client"; +import { customSeed } from "./customSeed"; + +if (require.main === module) { + dotenv.config(); + + const { BCRYPT_SALT } = process.env; + + if (!BCRYPT_SALT) { + throw new Error("BCRYPT_SALT environment variable must be defined"); + } +} + +async function seed() { + console.info("Seeding database..."); + + const client = new PrismaClient(); + void client.$disconnect(); + + console.info("Seeding database with custom seed..."); + customSeed(); + + console.info("Seeded database successfully"); +} diff --git a/apps/cloud-provider-connector-server/src/app.module.ts b/apps/cloud-provider-connector-server/src/app.module.ts new file mode 100644 index 00000000..af1f2090 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/app.module.ts @@ -0,0 +1,51 @@ +import { Module } from "@nestjs/common"; +import { AzureConnectionModule } from "./azureConnection/azureConnection.module"; +import { AwsConnectionModule } from "./awsConnection/awsConnection.module"; +import { GcpConnectionModule } from "./gcpConnection/gcpConnection.module"; +import { InstanceTemplateModule } from "./instanceTemplate/instanceTemplate.module"; +import { ProviderLogModule } from "./providerLog/providerLog.module"; +import { RegionModule } from "./region/region.module"; +import { HealthModule } from "./health/health.module"; +import { PrismaModule } from "./prisma/prisma.module"; +import { SecretsManagerModule } from "./providers/secrets/secretsManager.module"; +import { ServeStaticModule } from "@nestjs/serve-static"; +import { ServeStaticOptionsService } from "./serveStaticOptions.service"; +import { ConfigModule, ConfigService } from "@nestjs/config"; +import { GraphQLModule } from "@nestjs/graphql"; +import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo"; + +@Module({ + controllers: [], + imports: [ + AzureConnectionModule, + AwsConnectionModule, + GcpConnectionModule, + InstanceTemplateModule, + ProviderLogModule, + RegionModule, + HealthModule, + PrismaModule, + SecretsManagerModule, + ConfigModule.forRoot({ isGlobal: true }), + ServeStaticModule.forRootAsync({ + useClass: ServeStaticOptionsService, + }), + GraphQLModule.forRootAsync<ApolloDriverConfig>({ + driver: ApolloDriver, + useFactory: (configService: ConfigService) => { + const playground = configService.get("GRAPHQL_PLAYGROUND"); + const introspection = configService.get("GRAPHQL_INTROSPECTION"); + return { + autoSchemaFile: "schema.graphql", + sortSchema: true, + playground, + introspection: playground || introspection, + }; + }, + inject: [ConfigService], + imports: [ConfigModule], + }), + ], + providers: [], +}) +export class AppModule {} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.controller.ts b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.controller.ts new file mode 100644 index 00000000..e3550677 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { AwsConnectionService } from "./awsConnection.service"; +import { AwsConnectionControllerBase } from "./base/awsConnection.controller.base"; + +@swagger.ApiTags("awsConnections") +@common.Controller("awsConnections") +export class AwsConnectionController extends AwsConnectionControllerBase { + constructor(protected readonly service: AwsConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.module.ts b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.module.ts new file mode 100644 index 00000000..2b1822e5 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { AwsConnectionModuleBase } from "./base/awsConnection.module.base"; +import { AwsConnectionService } from "./awsConnection.service"; +import { AwsConnectionController } from "./awsConnection.controller"; +import { AwsConnectionResolver } from "./awsConnection.resolver"; + +@Module({ + imports: [AwsConnectionModuleBase], + controllers: [AwsConnectionController], + providers: [AwsConnectionService, AwsConnectionResolver], + exports: [AwsConnectionService], +}) +export class AwsConnectionModule {} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.resolver.ts b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.resolver.ts new file mode 100644 index 00000000..f0726592 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { AwsConnectionResolverBase } from "./base/awsConnection.resolver.base"; +import { AwsConnection } from "./base/AwsConnection"; +import { AwsConnectionService } from "./awsConnection.service"; + +@graphql.Resolver(() => AwsConnection) +export class AwsConnectionResolver extends AwsConnectionResolverBase { + constructor(protected readonly service: AwsConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.service.ts b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.service.ts new file mode 100644 index 00000000..a2f9fcd4 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/awsConnection.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { AwsConnectionServiceBase } from "./base/awsConnection.service.base"; + +@Injectable() +export class AwsConnectionService extends AwsConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnection.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnection.ts new file mode 100644 index 00000000..78a18a01 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnection.ts @@ -0,0 +1,104 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional, IsDate } from "class-validator"; +import { Type } from "class-transformer"; + +@ObjectType() +class AwsConnection { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + accessKeyId!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + secretAccessKey!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + sessionToken!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile!: string | null; +} + +export { AwsConnection as AwsConnection }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCountArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCountArgs.ts new file mode 100644 index 00000000..2a1b7aad --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class AwsConnectionCountArgs { + @ApiProperty({ + required: false, + type: () => AwsConnectionWhereInput, + }) + @Field(() => AwsConnectionWhereInput, { nullable: true }) + @Type(() => AwsConnectionWhereInput) + where?: AwsConnectionWhereInput; +} + +export { AwsConnectionCountArgs as AwsConnectionCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCreateInput.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCreateInput.ts new file mode 100644 index 00000000..0d0db61c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionCreateInput.ts @@ -0,0 +1,79 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class AwsConnectionCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + accessKeyId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + secretAccessKey?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + sessionToken?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { AwsConnectionCreateInput as AwsConnectionCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindManyArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindManyArgs.ts new file mode 100644 index 00000000..6b2406b8 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { AwsConnectionOrderByInput } from "./AwsConnectionOrderByInput"; + +@ArgsType() +class AwsConnectionFindManyArgs { + @ApiProperty({ + required: false, + type: () => AwsConnectionWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => AwsConnectionWhereInput, { nullable: true }) + @Type(() => AwsConnectionWhereInput) + where?: AwsConnectionWhereInput; + + @ApiProperty({ + required: false, + type: [AwsConnectionOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [AwsConnectionOrderByInput], { nullable: true }) + @Type(() => AwsConnectionOrderByInput) + orderBy?: Array<AwsConnectionOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { AwsConnectionFindManyArgs as AwsConnectionFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..d8d1c96d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class AwsConnectionFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => AwsConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereUniqueInput) + @Field(() => AwsConnectionWhereUniqueInput, { nullable: false }) + where!: AwsConnectionWhereUniqueInput; +} + +export { AwsConnectionFindUniqueArgs as AwsConnectionFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionListRelationFilter.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionListRelationFilter.ts new file mode 100644 index 00000000..085117a1 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereInput } from "./AwsConnectionWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class AwsConnectionListRelationFilter { + @ApiProperty({ + required: false, + type: () => AwsConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereInput) + @IsOptional() + @Field(() => AwsConnectionWhereInput, { + nullable: true, + }) + every?: AwsConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => AwsConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereInput) + @IsOptional() + @Field(() => AwsConnectionWhereInput, { + nullable: true, + }) + some?: AwsConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => AwsConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereInput) + @IsOptional() + @Field(() => AwsConnectionWhereInput, { + nullable: true, + }) + none?: AwsConnectionWhereInput; +} +export { AwsConnectionListRelationFilter as AwsConnectionListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionOrderByInput.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionOrderByInput.ts new file mode 100644 index 00000000..afb64968 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionOrderByInput.ts @@ -0,0 +1,111 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class AwsConnectionOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + accessKeyId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + region?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + secretAccessKey?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + sessionToken?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + userProfile?: SortOrder; +} + +export { AwsConnectionOrderByInput as AwsConnectionOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionUpdateInput.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionUpdateInput.ts new file mode 100644 index 00000000..eb4e9429 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionUpdateInput.ts @@ -0,0 +1,79 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class AwsConnectionUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + accessKeyId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + secretAccessKey?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + sessionToken?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { AwsConnectionUpdateInput as AwsConnectionUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereInput.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereInput.ts new file mode 100644 index 00000000..f728d100 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereInput.ts @@ -0,0 +1,88 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { Type } from "class-transformer"; +import { IsOptional } from "class-validator"; +import { StringFilter } from "../../util/StringFilter"; + +@InputType() +class AwsConnectionWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + accessKeyId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + region?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + secretAccessKey?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + sessionToken?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + userProfile?: StringNullableFilter; +} + +export { AwsConnectionWhereInput as AwsConnectionWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..3b933805 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/AwsConnectionWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class AwsConnectionWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { AwsConnectionWhereUniqueInput as AwsConnectionWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/CreateAwsConnectionArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/CreateAwsConnectionArgs.ts new file mode 100644 index 00000000..6571033e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/CreateAwsConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionCreateInput } from "./AwsConnectionCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateAwsConnectionArgs { + @ApiProperty({ + required: true, + type: () => AwsConnectionCreateInput, + }) + @ValidateNested() + @Type(() => AwsConnectionCreateInput) + @Field(() => AwsConnectionCreateInput, { nullable: false }) + data!: AwsConnectionCreateInput; +} + +export { CreateAwsConnectionArgs as CreateAwsConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/DeleteAwsConnectionArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/DeleteAwsConnectionArgs.ts new file mode 100644 index 00000000..28bc0b7e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/DeleteAwsConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteAwsConnectionArgs { + @ApiProperty({ + required: true, + type: () => AwsConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereUniqueInput) + @Field(() => AwsConnectionWhereUniqueInput, { nullable: false }) + where!: AwsConnectionWhereUniqueInput; +} + +export { DeleteAwsConnectionArgs as DeleteAwsConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/UpdateAwsConnectionArgs.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/UpdateAwsConnectionArgs.ts new file mode 100644 index 00000000..67e7ce39 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/UpdateAwsConnectionArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { AwsConnectionUpdateInput } from "./AwsConnectionUpdateInput"; + +@ArgsType() +class UpdateAwsConnectionArgs { + @ApiProperty({ + required: true, + type: () => AwsConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AwsConnectionWhereUniqueInput) + @Field(() => AwsConnectionWhereUniqueInput, { nullable: false }) + where!: AwsConnectionWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => AwsConnectionUpdateInput, + }) + @ValidateNested() + @Type(() => AwsConnectionUpdateInput) + @Field(() => AwsConnectionUpdateInput, { nullable: false }) + data!: AwsConnectionUpdateInput; +} + +export { UpdateAwsConnectionArgs as UpdateAwsConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.spec.ts new file mode 100644 index 00000000..c6df5c1c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.spec.ts @@ -0,0 +1,210 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { AwsConnectionController } from "../awsConnection.controller"; +import { AwsConnectionService } from "../awsConnection.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + accessKeyId: "exampleAccessKeyId", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + secretAccessKey: "exampleSecretAccessKey", + sessionToken: "exampleSessionToken", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const CREATE_RESULT = { + accessKeyId: "exampleAccessKeyId", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + secretAccessKey: "exampleSecretAccessKey", + sessionToken: "exampleSessionToken", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const FIND_MANY_RESULT = [ + { + accessKeyId: "exampleAccessKeyId", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + secretAccessKey: "exampleSecretAccessKey", + sessionToken: "exampleSessionToken", + updatedAt: new Date(), + userProfile: "exampleUserProfile", + }, +]; +const FIND_ONE_RESULT = { + accessKeyId: "exampleAccessKeyId", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + secretAccessKey: "exampleSecretAccessKey", + sessionToken: "exampleSessionToken", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; + +const service = { + createAwsConnection() { + return CREATE_RESULT; + }, + awsConnections: () => FIND_MANY_RESULT, + awsConnection: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("AwsConnection", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: AwsConnectionService, + useValue: service, + }, + ], + controllers: [AwsConnectionController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /awsConnections", async () => { + await request(app.getHttpServer()) + .post("/awsConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /awsConnections", async () => { + await request(app.getHttpServer()) + .get("/awsConnections") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /awsConnections/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/awsConnections"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /awsConnections/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/awsConnections"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /awsConnections existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/awsConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/awsConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.ts new file mode 100644 index 00000000..73b59606 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.controller.base.ts @@ -0,0 +1,158 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { AwsConnectionService } from "../awsConnection.service"; +import { AwsConnectionCreateInput } from "./AwsConnectionCreateInput"; +import { AwsConnection } from "./AwsConnection"; +import { AwsConnectionFindManyArgs } from "./AwsConnectionFindManyArgs"; +import { AwsConnectionWhereUniqueInput } from "./AwsConnectionWhereUniqueInput"; +import { AwsConnectionUpdateInput } from "./AwsConnectionUpdateInput"; + +export class AwsConnectionControllerBase { + constructor(protected readonly service: AwsConnectionService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: AwsConnection }) + async createAwsConnection( + @common.Body() data: AwsConnectionCreateInput + ): Promise<AwsConnection> { + return await this.service.createAwsConnection({ + data: data, + select: { + accessKeyId: true, + createdAt: true, + id: true, + region: true, + secretAccessKey: true, + sessionToken: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [AwsConnection] }) + @ApiNestedQuery(AwsConnectionFindManyArgs) + async awsConnections( + @common.Req() request: Request + ): Promise<AwsConnection[]> { + const args = plainToClass(AwsConnectionFindManyArgs, request.query); + return this.service.awsConnections({ + ...args, + select: { + accessKeyId: true, + createdAt: true, + id: true, + region: true, + secretAccessKey: true, + sessionToken: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: AwsConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async awsConnection( + @common.Param() params: AwsConnectionWhereUniqueInput + ): Promise<AwsConnection | null> { + const result = await this.service.awsConnection({ + where: params, + select: { + accessKeyId: true, + createdAt: true, + id: true, + region: true, + secretAccessKey: true, + sessionToken: true, + updatedAt: true, + userProfile: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: AwsConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateAwsConnection( + @common.Param() params: AwsConnectionWhereUniqueInput, + @common.Body() data: AwsConnectionUpdateInput + ): Promise<AwsConnection | null> { + try { + return await this.service.updateAwsConnection({ + where: params, + data: data, + select: { + accessKeyId: true, + createdAt: true, + id: true, + region: true, + secretAccessKey: true, + sessionToken: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: AwsConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteAwsConnection( + @common.Param() params: AwsConnectionWhereUniqueInput + ): Promise<AwsConnection | null> { + try { + return await this.service.deleteAwsConnection({ + where: params, + select: { + accessKeyId: true, + createdAt: true, + id: true, + region: true, + secretAccessKey: true, + sessionToken: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.module.base.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.module.base.ts new file mode 100644 index 00000000..e716cc27 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class AwsConnectionModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.resolver.base.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.resolver.base.ts new file mode 100644 index 00000000..ef23e3a3 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.resolver.base.ts @@ -0,0 +1,99 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { AwsConnection } from "./AwsConnection"; +import { AwsConnectionCountArgs } from "./AwsConnectionCountArgs"; +import { AwsConnectionFindManyArgs } from "./AwsConnectionFindManyArgs"; +import { AwsConnectionFindUniqueArgs } from "./AwsConnectionFindUniqueArgs"; +import { CreateAwsConnectionArgs } from "./CreateAwsConnectionArgs"; +import { UpdateAwsConnectionArgs } from "./UpdateAwsConnectionArgs"; +import { DeleteAwsConnectionArgs } from "./DeleteAwsConnectionArgs"; +import { AwsConnectionService } from "../awsConnection.service"; +@graphql.Resolver(() => AwsConnection) +export class AwsConnectionResolverBase { + constructor(protected readonly service: AwsConnectionService) {} + + async _awsConnectionsMeta( + @graphql.Args() args: AwsConnectionCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [AwsConnection]) + async awsConnections( + @graphql.Args() args: AwsConnectionFindManyArgs + ): Promise<AwsConnection[]> { + return this.service.awsConnections(args); + } + + @graphql.Query(() => AwsConnection, { nullable: true }) + async awsConnection( + @graphql.Args() args: AwsConnectionFindUniqueArgs + ): Promise<AwsConnection | null> { + const result = await this.service.awsConnection(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => AwsConnection) + async createAwsConnection( + @graphql.Args() args: CreateAwsConnectionArgs + ): Promise<AwsConnection> { + return await this.service.createAwsConnection({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => AwsConnection) + async updateAwsConnection( + @graphql.Args() args: UpdateAwsConnectionArgs + ): Promise<AwsConnection | null> { + try { + return await this.service.updateAwsConnection({ + ...args, + data: args.data, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => AwsConnection) + async deleteAwsConnection( + @graphql.Args() args: DeleteAwsConnectionArgs + ): Promise<AwsConnection | null> { + try { + return await this.service.deleteAwsConnection(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.service.base.ts b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.service.base.ts new file mode 100644 index 00000000..5d7af965 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/awsConnection/base/awsConnection.service.base.ts @@ -0,0 +1,49 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { Prisma, AwsConnection as PrismaAwsConnection } from "@prisma/client"; + +export class AwsConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.AwsConnectionCountArgs, "select"> + ): Promise<number> { + return this.prisma.awsConnection.count(args); + } + + async awsConnections( + args: Prisma.AwsConnectionFindManyArgs + ): Promise<PrismaAwsConnection[]> { + return this.prisma.awsConnection.findMany(args); + } + async awsConnection( + args: Prisma.AwsConnectionFindUniqueArgs + ): Promise<PrismaAwsConnection | null> { + return this.prisma.awsConnection.findUnique(args); + } + async createAwsConnection( + args: Prisma.AwsConnectionCreateArgs + ): Promise<PrismaAwsConnection> { + return this.prisma.awsConnection.create(args); + } + async updateAwsConnection( + args: Prisma.AwsConnectionUpdateArgs + ): Promise<PrismaAwsConnection> { + return this.prisma.awsConnection.update(args); + } + async deleteAwsConnection( + args: Prisma.AwsConnectionDeleteArgs + ): Promise<PrismaAwsConnection> { + return this.prisma.awsConnection.delete(args); + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.controller.ts b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.controller.ts new file mode 100644 index 00000000..fba79b16 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { AzureConnectionService } from "./azureConnection.service"; +import { AzureConnectionControllerBase } from "./base/azureConnection.controller.base"; + +@swagger.ApiTags("azureConnections") +@common.Controller("azureConnections") +export class AzureConnectionController extends AzureConnectionControllerBase { + constructor(protected readonly service: AzureConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.module.ts b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.module.ts new file mode 100644 index 00000000..170c8d43 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { AzureConnectionModuleBase } from "./base/azureConnection.module.base"; +import { AzureConnectionService } from "./azureConnection.service"; +import { AzureConnectionController } from "./azureConnection.controller"; +import { AzureConnectionResolver } from "./azureConnection.resolver"; + +@Module({ + imports: [AzureConnectionModuleBase], + controllers: [AzureConnectionController], + providers: [AzureConnectionService, AzureConnectionResolver], + exports: [AzureConnectionService], +}) +export class AzureConnectionModule {} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.resolver.ts b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.resolver.ts new file mode 100644 index 00000000..6b61c408 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { AzureConnectionResolverBase } from "./base/azureConnection.resolver.base"; +import { AzureConnection } from "./base/AzureConnection"; +import { AzureConnectionService } from "./azureConnection.service"; + +@graphql.Resolver(() => AzureConnection) +export class AzureConnectionResolver extends AzureConnectionResolverBase { + constructor(protected readonly service: AzureConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.service.ts b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.service.ts new file mode 100644 index 00000000..926292c5 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/azureConnection.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { AzureConnectionServiceBase } from "./base/azureConnection.service.base"; + +@Injectable() +export class AzureConnectionService extends AzureConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnection.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnection.ts new file mode 100644 index 00000000..02a1bd86 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnection.ts @@ -0,0 +1,116 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional, IsDate } from "class-validator"; +import { Type } from "class-transformer"; + +@ObjectType() +class AzureConnection { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientId!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientSecret!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + subscriptionId!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + tenantId!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile!: string | null; +} + +export { AzureConnection as AzureConnection }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCountArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCountArgs.ts new file mode 100644 index 00000000..4e7ab144 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class AzureConnectionCountArgs { + @ApiProperty({ + required: false, + type: () => AzureConnectionWhereInput, + }) + @Field(() => AzureConnectionWhereInput, { nullable: true }) + @Type(() => AzureConnectionWhereInput) + where?: AzureConnectionWhereInput; +} + +export { AzureConnectionCountArgs as AzureConnectionCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCreateInput.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCreateInput.ts new file mode 100644 index 00000000..76f482bd --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionCreateInput.ts @@ -0,0 +1,91 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class AzureConnectionCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientSecret?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + subscriptionId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + tenantId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { AzureConnectionCreateInput as AzureConnectionCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindManyArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindManyArgs.ts new file mode 100644 index 00000000..84660f51 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { AzureConnectionOrderByInput } from "./AzureConnectionOrderByInput"; + +@ArgsType() +class AzureConnectionFindManyArgs { + @ApiProperty({ + required: false, + type: () => AzureConnectionWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => AzureConnectionWhereInput, { nullable: true }) + @Type(() => AzureConnectionWhereInput) + where?: AzureConnectionWhereInput; + + @ApiProperty({ + required: false, + type: [AzureConnectionOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [AzureConnectionOrderByInput], { nullable: true }) + @Type(() => AzureConnectionOrderByInput) + orderBy?: Array<AzureConnectionOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { AzureConnectionFindManyArgs as AzureConnectionFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..58fbb9aa --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class AzureConnectionFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => AzureConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereUniqueInput) + @Field(() => AzureConnectionWhereUniqueInput, { nullable: false }) + where!: AzureConnectionWhereUniqueInput; +} + +export { AzureConnectionFindUniqueArgs as AzureConnectionFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionListRelationFilter.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionListRelationFilter.ts new file mode 100644 index 00000000..3ebb3173 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereInput } from "./AzureConnectionWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class AzureConnectionListRelationFilter { + @ApiProperty({ + required: false, + type: () => AzureConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereInput) + @IsOptional() + @Field(() => AzureConnectionWhereInput, { + nullable: true, + }) + every?: AzureConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => AzureConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereInput) + @IsOptional() + @Field(() => AzureConnectionWhereInput, { + nullable: true, + }) + some?: AzureConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => AzureConnectionWhereInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereInput) + @IsOptional() + @Field(() => AzureConnectionWhereInput, { + nullable: true, + }) + none?: AzureConnectionWhereInput; +} +export { AzureConnectionListRelationFilter as AzureConnectionListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionOrderByInput.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionOrderByInput.ts new file mode 100644 index 00000000..1820414c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionOrderByInput.ts @@ -0,0 +1,122 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class AzureConnectionOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + clientId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + clientSecret?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + region?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + subscriptionId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + tenantId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + userProfile?: SortOrder; +} + +export { AzureConnectionOrderByInput as AzureConnectionOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionUpdateInput.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionUpdateInput.ts new file mode 100644 index 00000000..1cd1764d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionUpdateInput.ts @@ -0,0 +1,91 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class AzureConnectionUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + clientSecret?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + subscriptionId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + tenantId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { AzureConnectionUpdateInput as AzureConnectionUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereInput.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereInput.ts new file mode 100644 index 00000000..ab4a589b --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereInput.ts @@ -0,0 +1,99 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { Type } from "class-transformer"; +import { IsOptional } from "class-validator"; +import { StringFilter } from "../../util/StringFilter"; + +@InputType() +class AzureConnectionWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + clientId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + clientSecret?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + region?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + subscriptionId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + tenantId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + userProfile?: StringNullableFilter; +} + +export { AzureConnectionWhereInput as AzureConnectionWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..d8fed5fd --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/AzureConnectionWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class AzureConnectionWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { AzureConnectionWhereUniqueInput as AzureConnectionWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/CreateAzureConnectionArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/CreateAzureConnectionArgs.ts new file mode 100644 index 00000000..87d0f156 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/CreateAzureConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionCreateInput } from "./AzureConnectionCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateAzureConnectionArgs { + @ApiProperty({ + required: true, + type: () => AzureConnectionCreateInput, + }) + @ValidateNested() + @Type(() => AzureConnectionCreateInput) + @Field(() => AzureConnectionCreateInput, { nullable: false }) + data!: AzureConnectionCreateInput; +} + +export { CreateAzureConnectionArgs as CreateAzureConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/DeleteAzureConnectionArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/DeleteAzureConnectionArgs.ts new file mode 100644 index 00000000..b25e8254 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/DeleteAzureConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteAzureConnectionArgs { + @ApiProperty({ + required: true, + type: () => AzureConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereUniqueInput) + @Field(() => AzureConnectionWhereUniqueInput, { nullable: false }) + where!: AzureConnectionWhereUniqueInput; +} + +export { DeleteAzureConnectionArgs as DeleteAzureConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/UpdateAzureConnectionArgs.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/UpdateAzureConnectionArgs.ts new file mode 100644 index 00000000..53306fcc --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/UpdateAzureConnectionArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { AzureConnectionUpdateInput } from "./AzureConnectionUpdateInput"; + +@ArgsType() +class UpdateAzureConnectionArgs { + @ApiProperty({ + required: true, + type: () => AzureConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AzureConnectionWhereUniqueInput) + @Field(() => AzureConnectionWhereUniqueInput, { nullable: false }) + where!: AzureConnectionWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => AzureConnectionUpdateInput, + }) + @ValidateNested() + @Type(() => AzureConnectionUpdateInput) + @Field(() => AzureConnectionUpdateInput, { nullable: false }) + data!: AzureConnectionUpdateInput; +} + +export { UpdateAzureConnectionArgs as UpdateAzureConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.spec.ts new file mode 100644 index 00000000..93d3e23a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.spec.ts @@ -0,0 +1,214 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { AzureConnectionController } from "../azureConnection.controller"; +import { AzureConnectionService } from "../azureConnection.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + clientId: "exampleClientId", + clientSecret: "exampleClientSecret", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + subscriptionId: "exampleSubscriptionId", + tenantId: "exampleTenantId", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const CREATE_RESULT = { + clientId: "exampleClientId", + clientSecret: "exampleClientSecret", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + subscriptionId: "exampleSubscriptionId", + tenantId: "exampleTenantId", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const FIND_MANY_RESULT = [ + { + clientId: "exampleClientId", + clientSecret: "exampleClientSecret", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + subscriptionId: "exampleSubscriptionId", + tenantId: "exampleTenantId", + updatedAt: new Date(), + userProfile: "exampleUserProfile", + }, +]; +const FIND_ONE_RESULT = { + clientId: "exampleClientId", + clientSecret: "exampleClientSecret", + createdAt: new Date(), + id: "exampleId", + region: "exampleRegion", + subscriptionId: "exampleSubscriptionId", + tenantId: "exampleTenantId", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; + +const service = { + createAzureConnection() { + return CREATE_RESULT; + }, + azureConnections: () => FIND_MANY_RESULT, + azureConnection: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("AzureConnection", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: AzureConnectionService, + useValue: service, + }, + ], + controllers: [AzureConnectionController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /azureConnections", async () => { + await request(app.getHttpServer()) + .post("/azureConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /azureConnections", async () => { + await request(app.getHttpServer()) + .get("/azureConnections") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /azureConnections/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/azureConnections"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /azureConnections/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/azureConnections"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /azureConnections existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/azureConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/azureConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.ts new file mode 100644 index 00000000..5765379c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.controller.base.ts @@ -0,0 +1,163 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { AzureConnectionService } from "../azureConnection.service"; +import { AzureConnectionCreateInput } from "./AzureConnectionCreateInput"; +import { AzureConnection } from "./AzureConnection"; +import { AzureConnectionFindManyArgs } from "./AzureConnectionFindManyArgs"; +import { AzureConnectionWhereUniqueInput } from "./AzureConnectionWhereUniqueInput"; +import { AzureConnectionUpdateInput } from "./AzureConnectionUpdateInput"; + +export class AzureConnectionControllerBase { + constructor(protected readonly service: AzureConnectionService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: AzureConnection }) + async createAzureConnection( + @common.Body() data: AzureConnectionCreateInput + ): Promise<AzureConnection> { + return await this.service.createAzureConnection({ + data: data, + select: { + clientId: true, + clientSecret: true, + createdAt: true, + id: true, + region: true, + subscriptionId: true, + tenantId: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [AzureConnection] }) + @ApiNestedQuery(AzureConnectionFindManyArgs) + async azureConnections( + @common.Req() request: Request + ): Promise<AzureConnection[]> { + const args = plainToClass(AzureConnectionFindManyArgs, request.query); + return this.service.azureConnections({ + ...args, + select: { + clientId: true, + clientSecret: true, + createdAt: true, + id: true, + region: true, + subscriptionId: true, + tenantId: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: AzureConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async azureConnection( + @common.Param() params: AzureConnectionWhereUniqueInput + ): Promise<AzureConnection | null> { + const result = await this.service.azureConnection({ + where: params, + select: { + clientId: true, + clientSecret: true, + createdAt: true, + id: true, + region: true, + subscriptionId: true, + tenantId: true, + updatedAt: true, + userProfile: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: AzureConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateAzureConnection( + @common.Param() params: AzureConnectionWhereUniqueInput, + @common.Body() data: AzureConnectionUpdateInput + ): Promise<AzureConnection | null> { + try { + return await this.service.updateAzureConnection({ + where: params, + data: data, + select: { + clientId: true, + clientSecret: true, + createdAt: true, + id: true, + region: true, + subscriptionId: true, + tenantId: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: AzureConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteAzureConnection( + @common.Param() params: AzureConnectionWhereUniqueInput + ): Promise<AzureConnection | null> { + try { + return await this.service.deleteAzureConnection({ + where: params, + select: { + clientId: true, + clientSecret: true, + createdAt: true, + id: true, + region: true, + subscriptionId: true, + tenantId: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.module.base.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.module.base.ts new file mode 100644 index 00000000..4331acb8 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class AzureConnectionModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.resolver.base.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.resolver.base.ts new file mode 100644 index 00000000..92f08265 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.resolver.base.ts @@ -0,0 +1,99 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { AzureConnection } from "./AzureConnection"; +import { AzureConnectionCountArgs } from "./AzureConnectionCountArgs"; +import { AzureConnectionFindManyArgs } from "./AzureConnectionFindManyArgs"; +import { AzureConnectionFindUniqueArgs } from "./AzureConnectionFindUniqueArgs"; +import { CreateAzureConnectionArgs } from "./CreateAzureConnectionArgs"; +import { UpdateAzureConnectionArgs } from "./UpdateAzureConnectionArgs"; +import { DeleteAzureConnectionArgs } from "./DeleteAzureConnectionArgs"; +import { AzureConnectionService } from "../azureConnection.service"; +@graphql.Resolver(() => AzureConnection) +export class AzureConnectionResolverBase { + constructor(protected readonly service: AzureConnectionService) {} + + async _azureConnectionsMeta( + @graphql.Args() args: AzureConnectionCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [AzureConnection]) + async azureConnections( + @graphql.Args() args: AzureConnectionFindManyArgs + ): Promise<AzureConnection[]> { + return this.service.azureConnections(args); + } + + @graphql.Query(() => AzureConnection, { nullable: true }) + async azureConnection( + @graphql.Args() args: AzureConnectionFindUniqueArgs + ): Promise<AzureConnection | null> { + const result = await this.service.azureConnection(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => AzureConnection) + async createAzureConnection( + @graphql.Args() args: CreateAzureConnectionArgs + ): Promise<AzureConnection> { + return await this.service.createAzureConnection({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => AzureConnection) + async updateAzureConnection( + @graphql.Args() args: UpdateAzureConnectionArgs + ): Promise<AzureConnection | null> { + try { + return await this.service.updateAzureConnection({ + ...args, + data: args.data, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => AzureConnection) + async deleteAzureConnection( + @graphql.Args() args: DeleteAzureConnectionArgs + ): Promise<AzureConnection | null> { + try { + return await this.service.deleteAzureConnection(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.service.base.ts b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.service.base.ts new file mode 100644 index 00000000..96577854 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/azureConnection/base/azureConnection.service.base.ts @@ -0,0 +1,52 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { + Prisma, + AzureConnection as PrismaAzureConnection, +} from "@prisma/client"; + +export class AzureConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.AzureConnectionCountArgs, "select"> + ): Promise<number> { + return this.prisma.azureConnection.count(args); + } + + async azureConnections( + args: Prisma.AzureConnectionFindManyArgs + ): Promise<PrismaAzureConnection[]> { + return this.prisma.azureConnection.findMany(args); + } + async azureConnection( + args: Prisma.AzureConnectionFindUniqueArgs + ): Promise<PrismaAzureConnection | null> { + return this.prisma.azureConnection.findUnique(args); + } + async createAzureConnection( + args: Prisma.AzureConnectionCreateArgs + ): Promise<PrismaAzureConnection> { + return this.prisma.azureConnection.create(args); + } + async updateAzureConnection( + args: Prisma.AzureConnectionUpdateArgs + ): Promise<PrismaAzureConnection> { + return this.prisma.azureConnection.update(args); + } + async deleteAzureConnection( + args: Prisma.AzureConnectionDeleteArgs + ): Promise<PrismaAzureConnection> { + return this.prisma.azureConnection.delete(args); + } +} diff --git a/apps/cloud-provider-connector-server/src/connectMicroservices.ts b/apps/cloud-provider-connector-server/src/connectMicroservices.ts new file mode 100644 index 00000000..068fa5f0 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/connectMicroservices.ts @@ -0,0 +1,6 @@ +import { INestApplication } from "@nestjs/common"; +import { ConfigService } from "@nestjs/config"; + +export async function connectMicroservices(app: INestApplication) { + const configService = app.get(ConfigService); +} diff --git a/apps/cloud-provider-connector-server/src/decorators/api-nested-query.decorator.ts b/apps/cloud-provider-connector-server/src/decorators/api-nested-query.decorator.ts new file mode 100644 index 00000000..9fd5ba30 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/decorators/api-nested-query.decorator.ts @@ -0,0 +1,80 @@ +import { applyDecorators } from "@nestjs/common"; +import { + ApiExtraModels, + ApiQuery, + ApiQueryOptions, + getSchemaPath, +} from "@nestjs/swagger"; +import "reflect-metadata"; + +const generateApiQueryObject = ( + prop: any, + propType: any, + required: boolean, + isArray: boolean +): ApiQueryOptions => { + if (propType === Number) { + return { + required, + name: prop, + style: "deepObject", + explode: true, + type: "number", + isArray, + }; + } else if (propType === String) { + return { + required, + name: prop, + style: "deepObject", + explode: true, + type: "string", + isArray, + }; + } else { + return { + required, + name: prop, + style: "deepObject", + explode: true, + type: "object", + isArray, + schema: { + $ref: getSchemaPath(propType), + }, + }; + } +}; + +// eslint-disable-next-line @typescript-eslint/ban-types,@typescript-eslint/explicit-module-boundary-types,@typescript-eslint/naming-convention +export function ApiNestedQuery(query: Function) { + const constructor = query.prototype; + const properties = Reflect.getMetadata( + "swagger/apiModelPropertiesArray", + constructor + ).map((prop: any) => prop.slice(1)); + + const decorators = properties + .map((property: any) => { + const { required, isArray } = Reflect.getMetadata( + "swagger/apiModelProperties", + constructor, + property + ); + const propertyType = Reflect.getMetadata( + "design:type", + constructor, + property + ); + const typedQuery = generateApiQueryObject( + property, + propertyType, + required, + isArray + ); + return [ApiExtraModels(propertyType), ApiQuery(typedQuery)]; + }) + .flat(); + + return applyDecorators(...decorators); +} diff --git a/apps/cloud-provider-connector-server/src/decorators/public.decorator.ts b/apps/cloud-provider-connector-server/src/decorators/public.decorator.ts new file mode 100644 index 00000000..9eab4e06 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/decorators/public.decorator.ts @@ -0,0 +1,10 @@ +import { applyDecorators, SetMetadata } from "@nestjs/common"; + +export const IS_PUBLIC_KEY = "isPublic"; + +const PublicAuthMiddleware = SetMetadata(IS_PUBLIC_KEY, true); +const PublicAuthSwagger = SetMetadata("swagger/apiSecurity", ["isPublic"]); + +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export const Public = () => + applyDecorators(PublicAuthMiddleware, PublicAuthSwagger); diff --git a/apps/cloud-provider-connector-server/src/errors.ts b/apps/cloud-provider-connector-server/src/errors.ts new file mode 100644 index 00000000..bd1aa6da --- /dev/null +++ b/apps/cloud-provider-connector-server/src/errors.ts @@ -0,0 +1,16 @@ +import * as common from "@nestjs/common"; +import { ApiProperty } from "@nestjs/swagger"; + +export class ForbiddenException extends common.ForbiddenException { + @ApiProperty() + statusCode!: number; + @ApiProperty() + message!: string; +} + +export class NotFoundException extends common.NotFoundException { + @ApiProperty() + statusCode!: number; + @ApiProperty() + message!: string; +} diff --git a/apps/cloud-provider-connector-server/src/filters/HttpExceptions.filter.ts b/apps/cloud-provider-connector-server/src/filters/HttpExceptions.filter.ts new file mode 100644 index 00000000..f5eda8e3 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/filters/HttpExceptions.filter.ts @@ -0,0 +1,89 @@ +import { + ArgumentsHost, + Catch, + HttpException, + HttpServer, + HttpStatus, +} from "@nestjs/common"; +import { BaseExceptionFilter } from "@nestjs/core"; +import { Prisma } from "@prisma/client"; +import { Response } from "express"; + +export type ErrorCodesStatusMapping = { + [key: string]: number; +}; + +/** + * {@link PrismaClientExceptionFilter} handling {@link Prisma.PrismaClientKnownRequestError} exceptions. + */ +@Catch(Prisma?.PrismaClientKnownRequestError) +export class HttpExceptionFilter extends BaseExceptionFilter { + /** + * default error codes mapping + * + * Error codes definition for Prisma Client (Query Engine) + * @see https://www.prisma.io/docs/reference/api-reference/error-reference#prisma-client-query-engine + */ + private errorCodesStatusMapping: ErrorCodesStatusMapping = { + P2000: HttpStatus.BAD_REQUEST, + P2002: HttpStatus.CONFLICT, + P2025: HttpStatus.NOT_FOUND, + }; + + /** + * @param applicationRef + */ + // eslint-disable-next-line @typescript-eslint/no-useless-constructor + constructor(applicationRef?: HttpServer) { + super(applicationRef); + } + + /** + * @param exception + * @param host + * @returns + */ + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + catch(exception: Prisma.PrismaClientKnownRequestError, host: ArgumentsHost) { + const statusCode = this.errorCodesStatusMapping[exception.code]; + let message; + if (host.getType() === "http") { + // for http requests (REST) + // Todo : Add all other exception types and also add mapping + const ctx = host.switchToHttp(); + const response = ctx.getResponse<Response>(); + if (exception.code === "P2002") { + // Handling Unique Key Constraint Violation Error + const fields = (exception.meta as { target: string[] }).target; + message = `Another record with the requested (${fields.join( + ", " + )}) already exists`; + } else { + message = + `[${exception.code}]: ` + + this.exceptionShortMessage(exception.message); + } + if (!Object.keys(this.errorCodesStatusMapping).includes(exception.code)) { + return super.catch(exception, host); + } + const errorResponse = { + message: message, + statusCode: statusCode, + }; + response.status(statusCode).send(errorResponse); + } + return new HttpException({ statusCode, message }, statusCode); + } + + /** + * @param exception + * @returns short message for the exception + */ + exceptionShortMessage(message: string): string { + const shortMessage = message.substring(message.indexOf("→")); + return shortMessage + .substring(shortMessage.indexOf("\n")) + .replace(/\n/g, "") + .trim(); + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/CreateGcpConnectionArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/CreateGcpConnectionArgs.ts new file mode 100644 index 00000000..e34bc099 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/CreateGcpConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionCreateInput } from "./GcpConnectionCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateGcpConnectionArgs { + @ApiProperty({ + required: true, + type: () => GcpConnectionCreateInput, + }) + @ValidateNested() + @Type(() => GcpConnectionCreateInput) + @Field(() => GcpConnectionCreateInput, { nullable: false }) + data!: GcpConnectionCreateInput; +} + +export { CreateGcpConnectionArgs as CreateGcpConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/DeleteGcpConnectionArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/DeleteGcpConnectionArgs.ts new file mode 100644 index 00000000..01932b29 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/DeleteGcpConnectionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteGcpConnectionArgs { + @ApiProperty({ + required: true, + type: () => GcpConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereUniqueInput) + @Field(() => GcpConnectionWhereUniqueInput, { nullable: false }) + where!: GcpConnectionWhereUniqueInput; +} + +export { DeleteGcpConnectionArgs as DeleteGcpConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnection.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnection.ts new file mode 100644 index 00000000..97888e5a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnection.ts @@ -0,0 +1,92 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsDate, IsString, MaxLength, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@ObjectType() +class GcpConnection { + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + projectId!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + serviceAccountJson!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile!: string | null; +} + +export { GcpConnection as GcpConnection }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCountArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCountArgs.ts new file mode 100644 index 00000000..414adfb8 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class GcpConnectionCountArgs { + @ApiProperty({ + required: false, + type: () => GcpConnectionWhereInput, + }) + @Field(() => GcpConnectionWhereInput, { nullable: true }) + @Type(() => GcpConnectionWhereInput) + where?: GcpConnectionWhereInput; +} + +export { GcpConnectionCountArgs as GcpConnectionCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCreateInput.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCreateInput.ts new file mode 100644 index 00000000..3680a2e6 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionCreateInput.ts @@ -0,0 +1,67 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class GcpConnectionCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + projectId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + serviceAccountJson?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { GcpConnectionCreateInput as GcpConnectionCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindManyArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindManyArgs.ts new file mode 100644 index 00000000..a4ece694 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { GcpConnectionOrderByInput } from "./GcpConnectionOrderByInput"; + +@ArgsType() +class GcpConnectionFindManyArgs { + @ApiProperty({ + required: false, + type: () => GcpConnectionWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => GcpConnectionWhereInput, { nullable: true }) + @Type(() => GcpConnectionWhereInput) + where?: GcpConnectionWhereInput; + + @ApiProperty({ + required: false, + type: [GcpConnectionOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [GcpConnectionOrderByInput], { nullable: true }) + @Type(() => GcpConnectionOrderByInput) + orderBy?: Array<GcpConnectionOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { GcpConnectionFindManyArgs as GcpConnectionFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindUniqueArgs.ts new file mode 100644 index 00000000..339377b8 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class GcpConnectionFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => GcpConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereUniqueInput) + @Field(() => GcpConnectionWhereUniqueInput, { nullable: false }) + where!: GcpConnectionWhereUniqueInput; +} + +export { GcpConnectionFindUniqueArgs as GcpConnectionFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionListRelationFilter.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionListRelationFilter.ts new file mode 100644 index 00000000..bfc7bde9 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereInput } from "./GcpConnectionWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class GcpConnectionListRelationFilter { + @ApiProperty({ + required: false, + type: () => GcpConnectionWhereInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereInput) + @IsOptional() + @Field(() => GcpConnectionWhereInput, { + nullable: true, + }) + every?: GcpConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => GcpConnectionWhereInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereInput) + @IsOptional() + @Field(() => GcpConnectionWhereInput, { + nullable: true, + }) + some?: GcpConnectionWhereInput; + + @ApiProperty({ + required: false, + type: () => GcpConnectionWhereInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereInput) + @IsOptional() + @Field(() => GcpConnectionWhereInput, { + nullable: true, + }) + none?: GcpConnectionWhereInput; +} +export { GcpConnectionListRelationFilter as GcpConnectionListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionOrderByInput.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionOrderByInput.ts new file mode 100644 index 00000000..cd320074 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionOrderByInput.ts @@ -0,0 +1,100 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class GcpConnectionOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + projectId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + region?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + serviceAccountJson?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + userProfile?: SortOrder; +} + +export { GcpConnectionOrderByInput as GcpConnectionOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionUpdateInput.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionUpdateInput.ts new file mode 100644 index 00000000..4a281285 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionUpdateInput.ts @@ -0,0 +1,67 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional } from "class-validator"; + +@InputType() +class GcpConnectionUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + projectId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + region?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + serviceAccountJson?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { GcpConnectionUpdateInput as GcpConnectionUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereInput.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereInput.ts new file mode 100644 index 00000000..9c50308d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereInput.ts @@ -0,0 +1,77 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { StringFilter } from "../../util/StringFilter"; +import { Type } from "class-transformer"; +import { IsOptional } from "class-validator"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; + +@InputType() +class GcpConnectionWhereInput { + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + projectId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + region?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + serviceAccountJson?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + userProfile?: StringNullableFilter; +} + +export { GcpConnectionWhereInput as GcpConnectionWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereUniqueInput.ts new file mode 100644 index 00000000..ab7f891f --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/GcpConnectionWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class GcpConnectionWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { GcpConnectionWhereUniqueInput as GcpConnectionWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/UpdateGcpConnectionArgs.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/UpdateGcpConnectionArgs.ts new file mode 100644 index 00000000..1368f688 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/UpdateGcpConnectionArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { GcpConnectionUpdateInput } from "./GcpConnectionUpdateInput"; + +@ArgsType() +class UpdateGcpConnectionArgs { + @ApiProperty({ + required: true, + type: () => GcpConnectionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => GcpConnectionWhereUniqueInput) + @Field(() => GcpConnectionWhereUniqueInput, { nullable: false }) + where!: GcpConnectionWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => GcpConnectionUpdateInput, + }) + @ValidateNested() + @Type(() => GcpConnectionUpdateInput) + @Field(() => GcpConnectionUpdateInput, { nullable: false }) + data!: GcpConnectionUpdateInput; +} + +export { UpdateGcpConnectionArgs as UpdateGcpConnectionArgs }; diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.spec.ts new file mode 100644 index 00000000..11e12407 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.spec.ts @@ -0,0 +1,206 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { GcpConnectionController } from "../gcpConnection.controller"; +import { GcpConnectionService } from "../gcpConnection.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + createdAt: new Date(), + id: "exampleId", + projectId: "exampleProjectId", + region: "exampleRegion", + serviceAccountJson: "exampleServiceAccountJson", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const CREATE_RESULT = { + createdAt: new Date(), + id: "exampleId", + projectId: "exampleProjectId", + region: "exampleRegion", + serviceAccountJson: "exampleServiceAccountJson", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const FIND_MANY_RESULT = [ + { + createdAt: new Date(), + id: "exampleId", + projectId: "exampleProjectId", + region: "exampleRegion", + serviceAccountJson: "exampleServiceAccountJson", + updatedAt: new Date(), + userProfile: "exampleUserProfile", + }, +]; +const FIND_ONE_RESULT = { + createdAt: new Date(), + id: "exampleId", + projectId: "exampleProjectId", + region: "exampleRegion", + serviceAccountJson: "exampleServiceAccountJson", + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; + +const service = { + createGcpConnection() { + return CREATE_RESULT; + }, + gcpConnections: () => FIND_MANY_RESULT, + gcpConnection: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("GcpConnection", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: GcpConnectionService, + useValue: service, + }, + ], + controllers: [GcpConnectionController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /gcpConnections", async () => { + await request(app.getHttpServer()) + .post("/gcpConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /gcpConnections", async () => { + await request(app.getHttpServer()) + .get("/gcpConnections") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /gcpConnections/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/gcpConnections"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /gcpConnections/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/gcpConnections"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /gcpConnections existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/gcpConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/gcpConnections") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.ts new file mode 100644 index 00000000..96a73c59 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.controller.base.ts @@ -0,0 +1,153 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { GcpConnectionService } from "../gcpConnection.service"; +import { GcpConnectionCreateInput } from "./GcpConnectionCreateInput"; +import { GcpConnection } from "./GcpConnection"; +import { GcpConnectionFindManyArgs } from "./GcpConnectionFindManyArgs"; +import { GcpConnectionWhereUniqueInput } from "./GcpConnectionWhereUniqueInput"; +import { GcpConnectionUpdateInput } from "./GcpConnectionUpdateInput"; + +export class GcpConnectionControllerBase { + constructor(protected readonly service: GcpConnectionService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: GcpConnection }) + async createGcpConnection( + @common.Body() data: GcpConnectionCreateInput + ): Promise<GcpConnection> { + return await this.service.createGcpConnection({ + data: data, + select: { + createdAt: true, + id: true, + projectId: true, + region: true, + serviceAccountJson: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [GcpConnection] }) + @ApiNestedQuery(GcpConnectionFindManyArgs) + async gcpConnections( + @common.Req() request: Request + ): Promise<GcpConnection[]> { + const args = plainToClass(GcpConnectionFindManyArgs, request.query); + return this.service.gcpConnections({ + ...args, + select: { + createdAt: true, + id: true, + projectId: true, + region: true, + serviceAccountJson: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: GcpConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async gcpConnection( + @common.Param() params: GcpConnectionWhereUniqueInput + ): Promise<GcpConnection | null> { + const result = await this.service.gcpConnection({ + where: params, + select: { + createdAt: true, + id: true, + projectId: true, + region: true, + serviceAccountJson: true, + updatedAt: true, + userProfile: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: GcpConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateGcpConnection( + @common.Param() params: GcpConnectionWhereUniqueInput, + @common.Body() data: GcpConnectionUpdateInput + ): Promise<GcpConnection | null> { + try { + return await this.service.updateGcpConnection({ + where: params, + data: data, + select: { + createdAt: true, + id: true, + projectId: true, + region: true, + serviceAccountJson: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: GcpConnection }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteGcpConnection( + @common.Param() params: GcpConnectionWhereUniqueInput + ): Promise<GcpConnection | null> { + try { + return await this.service.deleteGcpConnection({ + where: params, + select: { + createdAt: true, + id: true, + projectId: true, + region: true, + serviceAccountJson: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.module.base.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.module.base.ts new file mode 100644 index 00000000..9b18dfb8 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class GcpConnectionModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.resolver.base.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.resolver.base.ts new file mode 100644 index 00000000..5cbfa157 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.resolver.base.ts @@ -0,0 +1,99 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { GcpConnection } from "./GcpConnection"; +import { GcpConnectionCountArgs } from "./GcpConnectionCountArgs"; +import { GcpConnectionFindManyArgs } from "./GcpConnectionFindManyArgs"; +import { GcpConnectionFindUniqueArgs } from "./GcpConnectionFindUniqueArgs"; +import { CreateGcpConnectionArgs } from "./CreateGcpConnectionArgs"; +import { UpdateGcpConnectionArgs } from "./UpdateGcpConnectionArgs"; +import { DeleteGcpConnectionArgs } from "./DeleteGcpConnectionArgs"; +import { GcpConnectionService } from "../gcpConnection.service"; +@graphql.Resolver(() => GcpConnection) +export class GcpConnectionResolverBase { + constructor(protected readonly service: GcpConnectionService) {} + + async _gcpConnectionsMeta( + @graphql.Args() args: GcpConnectionCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [GcpConnection]) + async gcpConnections( + @graphql.Args() args: GcpConnectionFindManyArgs + ): Promise<GcpConnection[]> { + return this.service.gcpConnections(args); + } + + @graphql.Query(() => GcpConnection, { nullable: true }) + async gcpConnection( + @graphql.Args() args: GcpConnectionFindUniqueArgs + ): Promise<GcpConnection | null> { + const result = await this.service.gcpConnection(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => GcpConnection) + async createGcpConnection( + @graphql.Args() args: CreateGcpConnectionArgs + ): Promise<GcpConnection> { + return await this.service.createGcpConnection({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => GcpConnection) + async updateGcpConnection( + @graphql.Args() args: UpdateGcpConnectionArgs + ): Promise<GcpConnection | null> { + try { + return await this.service.updateGcpConnection({ + ...args, + data: args.data, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => GcpConnection) + async deleteGcpConnection( + @graphql.Args() args: DeleteGcpConnectionArgs + ): Promise<GcpConnection | null> { + try { + return await this.service.deleteGcpConnection(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.service.base.ts b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.service.base.ts new file mode 100644 index 00000000..b1b574ab --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/base/gcpConnection.service.base.ts @@ -0,0 +1,49 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { Prisma, GcpConnection as PrismaGcpConnection } from "@prisma/client"; + +export class GcpConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.GcpConnectionCountArgs, "select"> + ): Promise<number> { + return this.prisma.gcpConnection.count(args); + } + + async gcpConnections( + args: Prisma.GcpConnectionFindManyArgs + ): Promise<PrismaGcpConnection[]> { + return this.prisma.gcpConnection.findMany(args); + } + async gcpConnection( + args: Prisma.GcpConnectionFindUniqueArgs + ): Promise<PrismaGcpConnection | null> { + return this.prisma.gcpConnection.findUnique(args); + } + async createGcpConnection( + args: Prisma.GcpConnectionCreateArgs + ): Promise<PrismaGcpConnection> { + return this.prisma.gcpConnection.create(args); + } + async updateGcpConnection( + args: Prisma.GcpConnectionUpdateArgs + ): Promise<PrismaGcpConnection> { + return this.prisma.gcpConnection.update(args); + } + async deleteGcpConnection( + args: Prisma.GcpConnectionDeleteArgs + ): Promise<PrismaGcpConnection> { + return this.prisma.gcpConnection.delete(args); + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.controller.ts b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.controller.ts new file mode 100644 index 00000000..34e91006 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { GcpConnectionService } from "./gcpConnection.service"; +import { GcpConnectionControllerBase } from "./base/gcpConnection.controller.base"; + +@swagger.ApiTags("gcpConnections") +@common.Controller("gcpConnections") +export class GcpConnectionController extends GcpConnectionControllerBase { + constructor(protected readonly service: GcpConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.module.ts b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.module.ts new file mode 100644 index 00000000..4c5eaf42 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { GcpConnectionModuleBase } from "./base/gcpConnection.module.base"; +import { GcpConnectionService } from "./gcpConnection.service"; +import { GcpConnectionController } from "./gcpConnection.controller"; +import { GcpConnectionResolver } from "./gcpConnection.resolver"; + +@Module({ + imports: [GcpConnectionModuleBase], + controllers: [GcpConnectionController], + providers: [GcpConnectionService, GcpConnectionResolver], + exports: [GcpConnectionService], +}) +export class GcpConnectionModule {} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.resolver.ts b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.resolver.ts new file mode 100644 index 00000000..bf804fa9 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { GcpConnectionResolverBase } from "./base/gcpConnection.resolver.base"; +import { GcpConnection } from "./base/GcpConnection"; +import { GcpConnectionService } from "./gcpConnection.service"; + +@graphql.Resolver(() => GcpConnection) +export class GcpConnectionResolver extends GcpConnectionResolverBase { + constructor(protected readonly service: GcpConnectionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.service.ts b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.service.ts new file mode 100644 index 00000000..4b092e29 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/gcpConnection/gcpConnection.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { GcpConnectionServiceBase } from "./base/gcpConnection.service.base"; + +@Injectable() +export class GcpConnectionService extends GcpConnectionServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/health/base/health.controller.base.ts b/apps/cloud-provider-connector-server/src/health/base/health.controller.base.ts new file mode 100644 index 00000000..afd9e0dd --- /dev/null +++ b/apps/cloud-provider-connector-server/src/health/base/health.controller.base.ts @@ -0,0 +1,19 @@ +import { Get, HttpStatus, Res } from "@nestjs/common"; +import { Response } from "express"; +import { HealthService } from "../health.service"; + +export class HealthControllerBase { + constructor(protected readonly healthService: HealthService) {} + @Get("live") + healthLive(@Res() response: Response): Response<void> { + return response.status(HttpStatus.NO_CONTENT).send(); + } + @Get("ready") + async healthReady(@Res() response: Response): Promise<Response<void>> { + const dbConnection = await this.healthService.isDbReady(); + if (!dbConnection) { + return response.status(HttpStatus.NOT_FOUND).send(); + } + return response.status(HttpStatus.NO_CONTENT).send(); + } +} diff --git a/apps/cloud-provider-connector-server/src/health/base/health.service.base.ts b/apps/cloud-provider-connector-server/src/health/base/health.service.base.ts new file mode 100644 index 00000000..49a93a51 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/health/base/health.service.base.ts @@ -0,0 +1,15 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../../prisma/prisma.service"; + +@Injectable() +export class HealthServiceBase { + constructor(protected readonly prisma: PrismaService) {} + async isDbReady(): Promise<boolean> { + try { + await this.prisma.$queryRaw`SELECT 1`; + return true; + } catch (error) { + return false; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/health/health.controller.ts b/apps/cloud-provider-connector-server/src/health/health.controller.ts new file mode 100644 index 00000000..ff484e78 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/health/health.controller.ts @@ -0,0 +1,10 @@ +import { Controller } from "@nestjs/common"; +import { HealthControllerBase } from "./base/health.controller.base"; +import { HealthService } from "./health.service"; + +@Controller("_health") +export class HealthController extends HealthControllerBase { + constructor(protected readonly healthService: HealthService) { + super(healthService); + } +} diff --git a/apps/cloud-provider-connector-server/src/health/health.module.ts b/apps/cloud-provider-connector-server/src/health/health.module.ts new file mode 100644 index 00000000..39eff7f1 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/health/health.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { HealthController } from "./health.controller"; +import { HealthService } from "./health.service"; + +@Module({ + controllers: [HealthController], + providers: [HealthService], + exports: [HealthService], +}) +export class HealthModule {} diff --git a/apps/cloud-provider-connector-server/src/health/health.service.ts b/apps/cloud-provider-connector-server/src/health/health.service.ts new file mode 100644 index 00000000..44d93432 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/health/health.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { HealthServiceBase } from "./base/health.service.base"; + +@Injectable() +export class HealthService extends HealthServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/CreateInstanceTemplateArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/CreateInstanceTemplateArgs.ts new file mode 100644 index 00000000..cfd86cb1 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/CreateInstanceTemplateArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateCreateInput } from "./InstanceTemplateCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateInstanceTemplateArgs { + @ApiProperty({ + required: true, + type: () => InstanceTemplateCreateInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateCreateInput) + @Field(() => InstanceTemplateCreateInput, { nullable: false }) + data!: InstanceTemplateCreateInput; +} + +export { CreateInstanceTemplateArgs as CreateInstanceTemplateArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/DeleteInstanceTemplateArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/DeleteInstanceTemplateArgs.ts new file mode 100644 index 00000000..5d1bf52f --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/DeleteInstanceTemplateArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteInstanceTemplateArgs { + @ApiProperty({ + required: true, + type: () => InstanceTemplateWhereUniqueInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereUniqueInput) + @Field(() => InstanceTemplateWhereUniqueInput, { nullable: false }) + where!: InstanceTemplateWhereUniqueInput; +} + +export { DeleteInstanceTemplateArgs as DeleteInstanceTemplateArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplate.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplate.ts new file mode 100644 index 00000000..688df25e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplate.ts @@ -0,0 +1,140 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; + +import { + IsInt, + Min, + Max, + IsOptional, + IsDate, + IsBoolean, + IsString, + MaxLength, + ValidateNested, +} from "class-validator"; + +import { Type } from "class-transformer"; +import { Region } from "../../region/base/Region"; + +@ObjectType() +class InstanceTemplate { + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + cpu!: number | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsBoolean() + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + hasGpu!: boolean | null; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + memoryGb!: number | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider!: string | null; + + @ApiProperty({ + required: false, + type: () => Region, + }) + @ValidateNested() + @Type(() => Region) + @IsOptional() + region?: Region | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + storageGb!: number | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; +} + +export { InstanceTemplate as InstanceTemplate }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCountArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCountArgs.ts new file mode 100644 index 00000000..bfc3b4a2 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class InstanceTemplateCountArgs { + @ApiProperty({ + required: false, + type: () => InstanceTemplateWhereInput, + }) + @Field(() => InstanceTemplateWhereInput, { nullable: true }) + @Type(() => InstanceTemplateWhereInput) + where?: InstanceTemplateWhereInput; +} + +export { InstanceTemplateCountArgs as InstanceTemplateCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCreateInput.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCreateInput.ts new file mode 100644 index 00000000..ae765071 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateCreateInput.ts @@ -0,0 +1,118 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; + +import { + IsInt, + Min, + Max, + IsOptional, + IsBoolean, + IsString, + MaxLength, + ValidateNested, +} from "class-validator"; + +import { RegionWhereUniqueInput } from "../../region/base/RegionWhereUniqueInput"; +import { Type } from "class-transformer"; + +@InputType() +class InstanceTemplateCreateInput { + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + cpu?: number | null; + + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsBoolean() + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + hasGpu?: boolean | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + memoryGb?: number | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; + + @ApiProperty({ + required: false, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @IsOptional() + @Field(() => RegionWhereUniqueInput, { + nullable: true, + }) + region?: RegionWhereUniqueInput | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + storageGb?: number | null; +} + +export { InstanceTemplateCreateInput as InstanceTemplateCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindManyArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindManyArgs.ts new file mode 100644 index 00000000..1eabd925 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { InstanceTemplateOrderByInput } from "./InstanceTemplateOrderByInput"; + +@ArgsType() +class InstanceTemplateFindManyArgs { + @ApiProperty({ + required: false, + type: () => InstanceTemplateWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => InstanceTemplateWhereInput, { nullable: true }) + @Type(() => InstanceTemplateWhereInput) + where?: InstanceTemplateWhereInput; + + @ApiProperty({ + required: false, + type: [InstanceTemplateOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [InstanceTemplateOrderByInput], { nullable: true }) + @Type(() => InstanceTemplateOrderByInput) + orderBy?: Array<InstanceTemplateOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { InstanceTemplateFindManyArgs as InstanceTemplateFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindUniqueArgs.ts new file mode 100644 index 00000000..92905ef1 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class InstanceTemplateFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => InstanceTemplateWhereUniqueInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereUniqueInput) + @Field(() => InstanceTemplateWhereUniqueInput, { nullable: false }) + where!: InstanceTemplateWhereUniqueInput; +} + +export { InstanceTemplateFindUniqueArgs as InstanceTemplateFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateListRelationFilter.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateListRelationFilter.ts new file mode 100644 index 00000000..41fb337a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereInput } from "./InstanceTemplateWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class InstanceTemplateListRelationFilter { + @ApiProperty({ + required: false, + type: () => InstanceTemplateWhereInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereInput) + @IsOptional() + @Field(() => InstanceTemplateWhereInput, { + nullable: true, + }) + every?: InstanceTemplateWhereInput; + + @ApiProperty({ + required: false, + type: () => InstanceTemplateWhereInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereInput) + @IsOptional() + @Field(() => InstanceTemplateWhereInput, { + nullable: true, + }) + some?: InstanceTemplateWhereInput; + + @ApiProperty({ + required: false, + type: () => InstanceTemplateWhereInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereInput) + @IsOptional() + @Field(() => InstanceTemplateWhereInput, { + nullable: true, + }) + none?: InstanceTemplateWhereInput; +} +export { InstanceTemplateListRelationFilter as InstanceTemplateListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateOrderByInput.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateOrderByInput.ts new file mode 100644 index 00000000..7a4aa34e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateOrderByInput.ts @@ -0,0 +1,133 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class InstanceTemplateOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + cpu?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + hasGpu?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + memoryGb?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + name?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + provider?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + regionId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + storageGb?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; +} + +export { InstanceTemplateOrderByInput as InstanceTemplateOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateUpdateInput.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateUpdateInput.ts new file mode 100644 index 00000000..54f3850e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateUpdateInput.ts @@ -0,0 +1,118 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; + +import { + IsInt, + Min, + Max, + IsOptional, + IsBoolean, + IsString, + MaxLength, + ValidateNested, +} from "class-validator"; + +import { RegionWhereUniqueInput } from "../../region/base/RegionWhereUniqueInput"; +import { Type } from "class-transformer"; + +@InputType() +class InstanceTemplateUpdateInput { + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + cpu?: number | null; + + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsBoolean() + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + hasGpu?: boolean | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + memoryGb?: number | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; + + @ApiProperty({ + required: false, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @IsOptional() + @Field(() => RegionWhereUniqueInput, { + nullable: true, + }) + region?: RegionWhereUniqueInput | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsInt() + @Min(-999999999) + @Max(999999999) + @IsOptional() + @Field(() => Number, { + nullable: true, + }) + storageGb?: number | null; +} + +export { InstanceTemplateUpdateInput as InstanceTemplateUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereInput.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereInput.ts new file mode 100644 index 00000000..5624bf30 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereInput.ts @@ -0,0 +1,114 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IntNullableFilter } from "../../util/IntNullableFilter"; +import { Type } from "class-transformer"; +import { IsOptional, ValidateNested } from "class-validator"; +import { BooleanNullableFilter } from "../../util/BooleanNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { RegionWhereUniqueInput } from "../../region/base/RegionWhereUniqueInput"; + +@InputType() +class InstanceTemplateWhereInput { + @ApiProperty({ + required: false, + type: IntNullableFilter, + }) + @Type(() => IntNullableFilter) + @IsOptional() + @Field(() => IntNullableFilter, { + nullable: true, + }) + cpu?: IntNullableFilter; + + @ApiProperty({ + required: false, + type: BooleanNullableFilter, + }) + @Type(() => BooleanNullableFilter) + @IsOptional() + @Field(() => BooleanNullableFilter, { + nullable: true, + }) + hasGpu?: BooleanNullableFilter; + + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: IntNullableFilter, + }) + @Type(() => IntNullableFilter) + @IsOptional() + @Field(() => IntNullableFilter, { + nullable: true, + }) + memoryGb?: IntNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + name?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + provider?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @IsOptional() + @Field(() => RegionWhereUniqueInput, { + nullable: true, + }) + region?: RegionWhereUniqueInput; + + @ApiProperty({ + required: false, + type: IntNullableFilter, + }) + @Type(() => IntNullableFilter) + @IsOptional() + @Field(() => IntNullableFilter, { + nullable: true, + }) + storageGb?: IntNullableFilter; +} + +export { InstanceTemplateWhereInput as InstanceTemplateWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereUniqueInput.ts new file mode 100644 index 00000000..56f9d6e3 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/InstanceTemplateWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class InstanceTemplateWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { InstanceTemplateWhereUniqueInput as InstanceTemplateWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/UpdateInstanceTemplateArgs.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/UpdateInstanceTemplateArgs.ts new file mode 100644 index 00000000..1122c42d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/UpdateInstanceTemplateArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { InstanceTemplateUpdateInput } from "./InstanceTemplateUpdateInput"; + +@ArgsType() +class UpdateInstanceTemplateArgs { + @ApiProperty({ + required: true, + type: () => InstanceTemplateWhereUniqueInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateWhereUniqueInput) + @Field(() => InstanceTemplateWhereUniqueInput, { nullable: false }) + where!: InstanceTemplateWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => InstanceTemplateUpdateInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateUpdateInput) + @Field(() => InstanceTemplateUpdateInput, { nullable: false }) + data!: InstanceTemplateUpdateInput; +} + +export { UpdateInstanceTemplateArgs as UpdateInstanceTemplateArgs }; diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.spec.ts new file mode 100644 index 00000000..4a6347c7 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.spec.ts @@ -0,0 +1,214 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { InstanceTemplateController } from "../instanceTemplate.controller"; +import { InstanceTemplateService } from "../instanceTemplate.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + cpu: 42, + createdAt: new Date(), + hasGpu: "true", + id: "exampleId", + memoryGb: 42, + name: "exampleName", + provider: "exampleProvider", + storageGb: 42, + updatedAt: new Date(), +}; +const CREATE_RESULT = { + cpu: 42, + createdAt: new Date(), + hasGpu: "true", + id: "exampleId", + memoryGb: 42, + name: "exampleName", + provider: "exampleProvider", + storageGb: 42, + updatedAt: new Date(), +}; +const FIND_MANY_RESULT = [ + { + cpu: 42, + createdAt: new Date(), + hasGpu: "true", + id: "exampleId", + memoryGb: 42, + name: "exampleName", + provider: "exampleProvider", + storageGb: 42, + updatedAt: new Date(), + }, +]; +const FIND_ONE_RESULT = { + cpu: 42, + createdAt: new Date(), + hasGpu: "true", + id: "exampleId", + memoryGb: 42, + name: "exampleName", + provider: "exampleProvider", + storageGb: 42, + updatedAt: new Date(), +}; + +const service = { + createInstanceTemplate() { + return CREATE_RESULT; + }, + instanceTemplates: () => FIND_MANY_RESULT, + instanceTemplate: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("InstanceTemplate", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: InstanceTemplateService, + useValue: service, + }, + ], + controllers: [InstanceTemplateController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /instanceTemplates", async () => { + await request(app.getHttpServer()) + .post("/instanceTemplates") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /instanceTemplates", async () => { + await request(app.getHttpServer()) + .get("/instanceTemplates") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /instanceTemplates/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/instanceTemplates"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /instanceTemplates/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/instanceTemplates"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /instanceTemplates existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/instanceTemplates") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/instanceTemplates") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.ts new file mode 100644 index 00000000..96b4d82c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.controller.base.ts @@ -0,0 +1,214 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { InstanceTemplateService } from "../instanceTemplate.service"; +import { InstanceTemplateCreateInput } from "./InstanceTemplateCreateInput"; +import { InstanceTemplate } from "./InstanceTemplate"; +import { InstanceTemplateFindManyArgs } from "./InstanceTemplateFindManyArgs"; +import { InstanceTemplateWhereUniqueInput } from "./InstanceTemplateWhereUniqueInput"; +import { InstanceTemplateUpdateInput } from "./InstanceTemplateUpdateInput"; + +export class InstanceTemplateControllerBase { + constructor(protected readonly service: InstanceTemplateService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: InstanceTemplate }) + async createInstanceTemplate( + @common.Body() data: InstanceTemplateCreateInput + ): Promise<InstanceTemplate> { + return await this.service.createInstanceTemplate({ + data: { + ...data, + + region: data.region + ? { + connect: data.region, + } + : undefined, + }, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [InstanceTemplate] }) + @ApiNestedQuery(InstanceTemplateFindManyArgs) + async instanceTemplates( + @common.Req() request: Request + ): Promise<InstanceTemplate[]> { + const args = plainToClass(InstanceTemplateFindManyArgs, request.query); + return this.service.instanceTemplates({ + ...args, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: InstanceTemplate }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async instanceTemplate( + @common.Param() params: InstanceTemplateWhereUniqueInput + ): Promise<InstanceTemplate | null> { + const result = await this.service.instanceTemplate({ + where: params, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: InstanceTemplate }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateInstanceTemplate( + @common.Param() params: InstanceTemplateWhereUniqueInput, + @common.Body() data: InstanceTemplateUpdateInput + ): Promise<InstanceTemplate | null> { + try { + return await this.service.updateInstanceTemplate({ + where: params, + data: { + ...data, + + region: data.region + ? { + connect: data.region, + } + : undefined, + }, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: InstanceTemplate }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteInstanceTemplate( + @common.Param() params: InstanceTemplateWhereUniqueInput + ): Promise<InstanceTemplate | null> { + try { + return await this.service.deleteInstanceTemplate({ + where: params, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.module.base.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.module.base.ts new file mode 100644 index 00000000..f5c3c8e4 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class InstanceTemplateModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.resolver.base.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.resolver.base.ts new file mode 100644 index 00000000..60f0c565 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.resolver.base.ts @@ -0,0 +1,131 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { InstanceTemplate } from "./InstanceTemplate"; +import { InstanceTemplateCountArgs } from "./InstanceTemplateCountArgs"; +import { InstanceTemplateFindManyArgs } from "./InstanceTemplateFindManyArgs"; +import { InstanceTemplateFindUniqueArgs } from "./InstanceTemplateFindUniqueArgs"; +import { CreateInstanceTemplateArgs } from "./CreateInstanceTemplateArgs"; +import { UpdateInstanceTemplateArgs } from "./UpdateInstanceTemplateArgs"; +import { DeleteInstanceTemplateArgs } from "./DeleteInstanceTemplateArgs"; +import { Region } from "../../region/base/Region"; +import { InstanceTemplateService } from "../instanceTemplate.service"; +@graphql.Resolver(() => InstanceTemplate) +export class InstanceTemplateResolverBase { + constructor(protected readonly service: InstanceTemplateService) {} + + async _instanceTemplatesMeta( + @graphql.Args() args: InstanceTemplateCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [InstanceTemplate]) + async instanceTemplates( + @graphql.Args() args: InstanceTemplateFindManyArgs + ): Promise<InstanceTemplate[]> { + return this.service.instanceTemplates(args); + } + + @graphql.Query(() => InstanceTemplate, { nullable: true }) + async instanceTemplate( + @graphql.Args() args: InstanceTemplateFindUniqueArgs + ): Promise<InstanceTemplate | null> { + const result = await this.service.instanceTemplate(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => InstanceTemplate) + async createInstanceTemplate( + @graphql.Args() args: CreateInstanceTemplateArgs + ): Promise<InstanceTemplate> { + return await this.service.createInstanceTemplate({ + ...args, + data: { + ...args.data, + + region: args.data.region + ? { + connect: args.data.region, + } + : undefined, + }, + }); + } + + @graphql.Mutation(() => InstanceTemplate) + async updateInstanceTemplate( + @graphql.Args() args: UpdateInstanceTemplateArgs + ): Promise<InstanceTemplate | null> { + try { + return await this.service.updateInstanceTemplate({ + ...args, + data: { + ...args.data, + + region: args.data.region + ? { + connect: args.data.region, + } + : undefined, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => InstanceTemplate) + async deleteInstanceTemplate( + @graphql.Args() args: DeleteInstanceTemplateArgs + ): Promise<InstanceTemplate | null> { + try { + return await this.service.deleteInstanceTemplate(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.ResolveField(() => Region, { + nullable: true, + name: "region", + }) + async getRegion( + @graphql.Parent() parent: InstanceTemplate + ): Promise<Region | null> { + const result = await this.service.getRegion(parent.id); + + if (!result) { + return null; + } + return result; + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.service.base.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.service.base.ts new file mode 100644 index 00000000..de1051fa --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/base/instanceTemplate.service.base.ts @@ -0,0 +1,61 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { + Prisma, + InstanceTemplate as PrismaInstanceTemplate, + Region as PrismaRegion, +} from "@prisma/client"; + +export class InstanceTemplateServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.InstanceTemplateCountArgs, "select"> + ): Promise<number> { + return this.prisma.instanceTemplate.count(args); + } + + async instanceTemplates( + args: Prisma.InstanceTemplateFindManyArgs + ): Promise<PrismaInstanceTemplate[]> { + return this.prisma.instanceTemplate.findMany(args); + } + async instanceTemplate( + args: Prisma.InstanceTemplateFindUniqueArgs + ): Promise<PrismaInstanceTemplate | null> { + return this.prisma.instanceTemplate.findUnique(args); + } + async createInstanceTemplate( + args: Prisma.InstanceTemplateCreateArgs + ): Promise<PrismaInstanceTemplate> { + return this.prisma.instanceTemplate.create(args); + } + async updateInstanceTemplate( + args: Prisma.InstanceTemplateUpdateArgs + ): Promise<PrismaInstanceTemplate> { + return this.prisma.instanceTemplate.update(args); + } + async deleteInstanceTemplate( + args: Prisma.InstanceTemplateDeleteArgs + ): Promise<PrismaInstanceTemplate> { + return this.prisma.instanceTemplate.delete(args); + } + + async getRegion(parentId: string): Promise<PrismaRegion | null> { + return this.prisma.instanceTemplate + .findUnique({ + where: { id: parentId }, + }) + .region(); + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.controller.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.controller.ts new file mode 100644 index 00000000..e74938f6 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { InstanceTemplateService } from "./instanceTemplate.service"; +import { InstanceTemplateControllerBase } from "./base/instanceTemplate.controller.base"; + +@swagger.ApiTags("instanceTemplates") +@common.Controller("instanceTemplates") +export class InstanceTemplateController extends InstanceTemplateControllerBase { + constructor(protected readonly service: InstanceTemplateService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.module.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.module.ts new file mode 100644 index 00000000..a4d02ea5 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { InstanceTemplateModuleBase } from "./base/instanceTemplate.module.base"; +import { InstanceTemplateService } from "./instanceTemplate.service"; +import { InstanceTemplateController } from "./instanceTemplate.controller"; +import { InstanceTemplateResolver } from "./instanceTemplate.resolver"; + +@Module({ + imports: [InstanceTemplateModuleBase], + controllers: [InstanceTemplateController], + providers: [InstanceTemplateService, InstanceTemplateResolver], + exports: [InstanceTemplateService], +}) +export class InstanceTemplateModule {} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.resolver.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.resolver.ts new file mode 100644 index 00000000..2bff8db6 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { InstanceTemplateResolverBase } from "./base/instanceTemplate.resolver.base"; +import { InstanceTemplate } from "./base/InstanceTemplate"; +import { InstanceTemplateService } from "./instanceTemplate.service"; + +@graphql.Resolver(() => InstanceTemplate) +export class InstanceTemplateResolver extends InstanceTemplateResolverBase { + constructor(protected readonly service: InstanceTemplateService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.service.ts b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.service.ts new file mode 100644 index 00000000..cf33e808 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/instanceTemplate/instanceTemplate.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { InstanceTemplateServiceBase } from "./base/instanceTemplate.service.base"; + +@Injectable() +export class InstanceTemplateService extends InstanceTemplateServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/main.ts b/apps/cloud-provider-connector-server/src/main.ts new file mode 100644 index 00000000..474eeadf --- /dev/null +++ b/apps/cloud-provider-connector-server/src/main.ts @@ -0,0 +1,53 @@ +import { ValidationPipe } from "@nestjs/common"; +import { HttpAdapterHost, NestFactory } from "@nestjs/core"; +import { OpenAPIObject, SwaggerModule } from "@nestjs/swagger"; +import { HttpExceptionFilter } from "./filters/HttpExceptions.filter"; +import { AppModule } from "./app.module"; +import { connectMicroservices } from "./connectMicroservices"; +import { + swaggerPath, + swaggerDocumentOptions, + swaggerSetupOptions, +} from "./swagger"; + +const { PORT = 3000 } = process.env; + +async function main() { + const app = await NestFactory.create(AppModule, { cors: true }); + + app.setGlobalPrefix("api"); + app.useGlobalPipes( + new ValidationPipe({ + transform: true, + forbidUnknownValues: false, + }) + ); + + const document = SwaggerModule.createDocument(app, swaggerDocumentOptions); + + /** check if there is Public decorator for each path (action) and its method (findMany / findOne) on each controller */ + Object.values((document as OpenAPIObject).paths).forEach((path: any) => { + Object.values(path).forEach((method: any) => { + if ( + Array.isArray(method.security) && + method.security.includes("isPublic") + ) { + method.security = []; + } + }); + }); + + await connectMicroservices(app); + await app.startAllMicroservices(); + + SwaggerModule.setup(swaggerPath, app, document, swaggerSetupOptions); + + const { httpAdapter } = app.get(HttpAdapterHost); + app.useGlobalFilters(new HttpExceptionFilter(httpAdapter)); + + void app.listen(PORT); + + return app; +} + +module.exports = main(); diff --git a/apps/cloud-provider-connector-server/src/prisma.util.spec.ts b/apps/cloud-provider-connector-server/src/prisma.util.spec.ts new file mode 100644 index 00000000..0aa308ed --- /dev/null +++ b/apps/cloud-provider-connector-server/src/prisma.util.spec.ts @@ -0,0 +1,23 @@ +import { + isRecordNotFoundError, + PRISMA_QUERY_INTERPRETATION_ERROR, +} from "./prisma.util"; + +describe("isRecordNotFoundError", () => { + test("returns true for record not found error", () => { + expect( + isRecordNotFoundError( + Object.assign( + new Error(`Error occurred during query execution: + InterpretationError("Error for binding '0': RecordNotFound("Record to update not found.")")`), + { + code: PRISMA_QUERY_INTERPRETATION_ERROR, + } + ) + ) + ).toBe(true); + }); + test("returns false for any other error", () => { + expect(isRecordNotFoundError(new Error())).toBe(false); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/prisma.util.ts b/apps/cloud-provider-connector-server/src/prisma.util.ts new file mode 100644 index 00000000..029b98a9 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/prisma.util.ts @@ -0,0 +1,29 @@ +export const PRISMA_QUERY_INTERPRETATION_ERROR = "P2016"; +export const PRISMA_RECORD_NOT_FOUND = "RecordNotFound"; + +export function isRecordNotFoundError(error: any): boolean { + return ( + error instanceof Error && + "code" in error && + error.code === PRISMA_QUERY_INTERPRETATION_ERROR && + error.message.includes(PRISMA_RECORD_NOT_FOUND) + ); +} + +export async function transformStringFieldUpdateInput< + T extends undefined | string | { set?: string } +>(input: T, transform: (input: string) => Promise<string>): Promise<T> { + if (typeof input === "object" && typeof input?.set === "string") { + return { set: await transform(input.set) } as T; + } + if (typeof input === "object") { + if (typeof input.set === "string") { + return { set: await transform(input.set) } as T; + } + return input; + } + if (typeof input === "string") { + return (await transform(input)) as T; + } + return input; +} diff --git a/apps/cloud-provider-connector-server/src/prisma/prisma.module.ts b/apps/cloud-provider-connector-server/src/prisma/prisma.module.ts new file mode 100644 index 00000000..1edbf95e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/prisma/prisma.module.ts @@ -0,0 +1,9 @@ +import { Global, Module } from "@nestjs/common"; +import { PrismaService } from "./prisma.service"; + +@Global() +@Module({ + providers: [PrismaService], + exports: [PrismaService], +}) +export class PrismaModule {} diff --git a/apps/cloud-provider-connector-server/src/prisma/prisma.service.ts b/apps/cloud-provider-connector-server/src/prisma/prisma.service.ts new file mode 100644 index 00000000..79ea4fa7 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/prisma/prisma.service.ts @@ -0,0 +1,9 @@ +import { Injectable, OnModuleInit, INestApplication } from "@nestjs/common"; +import { PrismaClient } from "@prisma/client"; + +@Injectable() +export class PrismaService extends PrismaClient implements OnModuleInit { + async onModuleInit() { + await this.$connect(); + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/CreateProviderLogArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/CreateProviderLogArgs.ts new file mode 100644 index 00000000..2aa9105e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/CreateProviderLogArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogCreateInput } from "./ProviderLogCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateProviderLogArgs { + @ApiProperty({ + required: true, + type: () => ProviderLogCreateInput, + }) + @ValidateNested() + @Type(() => ProviderLogCreateInput) + @Field(() => ProviderLogCreateInput, { nullable: false }) + data!: ProviderLogCreateInput; +} + +export { CreateProviderLogArgs as CreateProviderLogArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/DeleteProviderLogArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/DeleteProviderLogArgs.ts new file mode 100644 index 00000000..a4ed75a4 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/DeleteProviderLogArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteProviderLogArgs { + @ApiProperty({ + required: true, + type: () => ProviderLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereUniqueInput) + @Field(() => ProviderLogWhereUniqueInput, { nullable: false }) + where!: ProviderLogWhereUniqueInput; +} + +export { DeleteProviderLogArgs as DeleteProviderLogArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLog.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLog.ts new file mode 100644 index 00000000..35d6e63b --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLog.ts @@ -0,0 +1,126 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional, IsDate } from "class-validator"; +import { Type } from "class-transformer"; +import { IsJSONValue } from "../../validators"; +import { GraphQLJSON } from "graphql-type-json"; +import { JsonValue } from "type-fest"; + +@ObjectType() +class ProviderLog { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + action!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider!: string | null; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + request!: JsonValue; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + response!: JsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + status!: string | null; + + @ApiProperty({ + required: false, + }) + @IsDate() + @Type(() => Date) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + timestamp!: Date | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile!: string | null; +} + +export { ProviderLog as ProviderLog }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCountArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCountArgs.ts new file mode 100644 index 00000000..757e86bc --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class ProviderLogCountArgs { + @ApiProperty({ + required: false, + type: () => ProviderLogWhereInput, + }) + @Field(() => ProviderLogWhereInput, { nullable: true }) + @Type(() => ProviderLogWhereInput) + where?: ProviderLogWhereInput; +} + +export { ProviderLogCountArgs as ProviderLogCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCreateInput.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCreateInput.ts new file mode 100644 index 00000000..b9c53a48 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogCreateInput.ts @@ -0,0 +1,102 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional, IsDate } from "class-validator"; +import { IsJSONValue } from "../../validators"; +import { GraphQLJSON } from "graphql-type-json"; +import { InputJsonValue } from "../../types"; +import { Type } from "class-transformer"; + +@InputType() +class ProviderLogCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + action?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + request?: InputJsonValue; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + response?: InputJsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + status?: string | null; + + @ApiProperty({ + required: false, + }) + @IsDate() + @Type(() => Date) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + timestamp?: Date | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { ProviderLogCreateInput as ProviderLogCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindManyArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindManyArgs.ts new file mode 100644 index 00000000..d28b3d25 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { ProviderLogOrderByInput } from "./ProviderLogOrderByInput"; + +@ArgsType() +class ProviderLogFindManyArgs { + @ApiProperty({ + required: false, + type: () => ProviderLogWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => ProviderLogWhereInput, { nullable: true }) + @Type(() => ProviderLogWhereInput) + where?: ProviderLogWhereInput; + + @ApiProperty({ + required: false, + type: [ProviderLogOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [ProviderLogOrderByInput], { nullable: true }) + @Type(() => ProviderLogOrderByInput) + orderBy?: Array<ProviderLogOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { ProviderLogFindManyArgs as ProviderLogFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindUniqueArgs.ts new file mode 100644 index 00000000..ba0372d0 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class ProviderLogFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => ProviderLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereUniqueInput) + @Field(() => ProviderLogWhereUniqueInput, { nullable: false }) + where!: ProviderLogWhereUniqueInput; +} + +export { ProviderLogFindUniqueArgs as ProviderLogFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogListRelationFilter.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogListRelationFilter.ts new file mode 100644 index 00000000..1d5acc1d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereInput } from "./ProviderLogWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class ProviderLogListRelationFilter { + @ApiProperty({ + required: false, + type: () => ProviderLogWhereInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereInput) + @IsOptional() + @Field(() => ProviderLogWhereInput, { + nullable: true, + }) + every?: ProviderLogWhereInput; + + @ApiProperty({ + required: false, + type: () => ProviderLogWhereInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereInput) + @IsOptional() + @Field(() => ProviderLogWhereInput, { + nullable: true, + }) + some?: ProviderLogWhereInput; + + @ApiProperty({ + required: false, + type: () => ProviderLogWhereInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereInput) + @IsOptional() + @Field(() => ProviderLogWhereInput, { + nullable: true, + }) + none?: ProviderLogWhereInput; +} +export { ProviderLogListRelationFilter as ProviderLogListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogOrderByInput.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogOrderByInput.ts new file mode 100644 index 00000000..1769bc41 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogOrderByInput.ts @@ -0,0 +1,133 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class ProviderLogOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + action?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + provider?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + request?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + response?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + status?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + timestamp?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + userProfile?: SortOrder; +} + +export { ProviderLogOrderByInput as ProviderLogOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogUpdateInput.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogUpdateInput.ts new file mode 100644 index 00000000..04a3d32d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogUpdateInput.ts @@ -0,0 +1,102 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString, MaxLength, IsOptional, IsDate } from "class-validator"; +import { IsJSONValue } from "../../validators"; +import { GraphQLJSON } from "graphql-type-json"; +import { InputJsonValue } from "../../types"; +import { Type } from "class-transformer"; + +@InputType() +class ProviderLogUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + action?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + request?: InputJsonValue; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + response?: InputJsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + status?: string | null; + + @ApiProperty({ + required: false, + }) + @IsDate() + @Type(() => Date) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + timestamp?: Date | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + userProfile?: string | null; +} + +export { ProviderLogUpdateInput as ProviderLogUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereInput.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereInput.ts new file mode 100644 index 00000000..2fa2953a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereInput.ts @@ -0,0 +1,112 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { Type } from "class-transformer"; +import { IsOptional } from "class-validator"; +import { StringFilter } from "../../util/StringFilter"; +import { JsonFilter } from "../../util/JsonFilter"; +import { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +@InputType() +class ProviderLogWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + action?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + provider?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: JsonFilter, + }) + @Type(() => JsonFilter) + @IsOptional() + @Field(() => JsonFilter, { + nullable: true, + }) + request?: JsonFilter; + + @ApiProperty({ + required: false, + type: JsonFilter, + }) + @Type(() => JsonFilter) + @IsOptional() + @Field(() => JsonFilter, { + nullable: true, + }) + response?: JsonFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + status?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: DateTimeNullableFilter, + }) + @Type(() => DateTimeNullableFilter) + @IsOptional() + @Field(() => DateTimeNullableFilter, { + nullable: true, + }) + timestamp?: DateTimeNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + userProfile?: StringNullableFilter; +} + +export { ProviderLogWhereInput as ProviderLogWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereUniqueInput.ts new file mode 100644 index 00000000..2f802a63 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/ProviderLogWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class ProviderLogWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { ProviderLogWhereUniqueInput as ProviderLogWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/UpdateProviderLogArgs.ts b/apps/cloud-provider-connector-server/src/providerLog/base/UpdateProviderLogArgs.ts new file mode 100644 index 00000000..cc44eae4 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/UpdateProviderLogArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { ProviderLogUpdateInput } from "./ProviderLogUpdateInput"; + +@ArgsType() +class UpdateProviderLogArgs { + @ApiProperty({ + required: true, + type: () => ProviderLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ProviderLogWhereUniqueInput) + @Field(() => ProviderLogWhereUniqueInput, { nullable: false }) + where!: ProviderLogWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => ProviderLogUpdateInput, + }) + @ValidateNested() + @Type(() => ProviderLogUpdateInput) + @Field(() => ProviderLogUpdateInput, { nullable: false }) + data!: ProviderLogUpdateInput; +} + +export { UpdateProviderLogArgs as UpdateProviderLogArgs }; diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.spec.ts new file mode 100644 index 00000000..06939116 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.spec.ts @@ -0,0 +1,214 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { ProviderLogController } from "../providerLog.controller"; +import { ProviderLogService } from "../providerLog.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + action: "exampleAction", + createdAt: new Date(), + id: "exampleId", + provider: "exampleProvider", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const CREATE_RESULT = { + action: "exampleAction", + createdAt: new Date(), + id: "exampleId", + provider: "exampleProvider", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const FIND_MANY_RESULT = [ + { + action: "exampleAction", + createdAt: new Date(), + id: "exampleId", + provider: "exampleProvider", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", + }, +]; +const FIND_ONE_RESULT = { + action: "exampleAction", + createdAt: new Date(), + id: "exampleId", + provider: "exampleProvider", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; + +const service = { + createProviderLog() { + return CREATE_RESULT; + }, + providerLogs: () => FIND_MANY_RESULT, + providerLog: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("ProviderLog", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: ProviderLogService, + useValue: service, + }, + ], + controllers: [ProviderLogController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /providerLogs", async () => { + await request(app.getHttpServer()) + .post("/providerLogs") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + timestamp: CREATE_RESULT.timestamp.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /providerLogs", async () => { + await request(app.getHttpServer()) + .get("/providerLogs") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + timestamp: FIND_MANY_RESULT[0].timestamp.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /providerLogs/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/providerLogs"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /providerLogs/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/providerLogs"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + timestamp: FIND_ONE_RESULT.timestamp.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /providerLogs existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/providerLogs") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + timestamp: CREATE_RESULT.timestamp.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/providerLogs") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.ts b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.ts new file mode 100644 index 00000000..6166bf37 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.controller.base.ts @@ -0,0 +1,166 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { ProviderLogService } from "../providerLog.service"; +import { ProviderLogCreateInput } from "./ProviderLogCreateInput"; +import { ProviderLog } from "./ProviderLog"; +import { ProviderLogFindManyArgs } from "./ProviderLogFindManyArgs"; +import { ProviderLogWhereUniqueInput } from "./ProviderLogWhereUniqueInput"; +import { ProviderLogUpdateInput } from "./ProviderLogUpdateInput"; + +export class ProviderLogControllerBase { + constructor(protected readonly service: ProviderLogService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: ProviderLog }) + async createProviderLog( + @common.Body() data: ProviderLogCreateInput + ): Promise<ProviderLog> { + return await this.service.createProviderLog({ + data: data, + select: { + action: true, + createdAt: true, + id: true, + provider: true, + request: true, + response: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [ProviderLog] }) + @ApiNestedQuery(ProviderLogFindManyArgs) + async providerLogs(@common.Req() request: Request): Promise<ProviderLog[]> { + const args = plainToClass(ProviderLogFindManyArgs, request.query); + return this.service.providerLogs({ + ...args, + select: { + action: true, + createdAt: true, + id: true, + provider: true, + request: true, + response: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: ProviderLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async providerLog( + @common.Param() params: ProviderLogWhereUniqueInput + ): Promise<ProviderLog | null> { + const result = await this.service.providerLog({ + where: params, + select: { + action: true, + createdAt: true, + id: true, + provider: true, + request: true, + response: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: ProviderLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateProviderLog( + @common.Param() params: ProviderLogWhereUniqueInput, + @common.Body() data: ProviderLogUpdateInput + ): Promise<ProviderLog | null> { + try { + return await this.service.updateProviderLog({ + where: params, + data: data, + select: { + action: true, + createdAt: true, + id: true, + provider: true, + request: true, + response: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: ProviderLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteProviderLog( + @common.Param() params: ProviderLogWhereUniqueInput + ): Promise<ProviderLog | null> { + try { + return await this.service.deleteProviderLog({ + where: params, + select: { + action: true, + createdAt: true, + id: true, + provider: true, + request: true, + response: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.module.base.ts b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.module.base.ts new file mode 100644 index 00000000..58e97909 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class ProviderLogModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.resolver.base.ts b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.resolver.base.ts new file mode 100644 index 00000000..3a1f7038 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.resolver.base.ts @@ -0,0 +1,99 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { ProviderLog } from "./ProviderLog"; +import { ProviderLogCountArgs } from "./ProviderLogCountArgs"; +import { ProviderLogFindManyArgs } from "./ProviderLogFindManyArgs"; +import { ProviderLogFindUniqueArgs } from "./ProviderLogFindUniqueArgs"; +import { CreateProviderLogArgs } from "./CreateProviderLogArgs"; +import { UpdateProviderLogArgs } from "./UpdateProviderLogArgs"; +import { DeleteProviderLogArgs } from "./DeleteProviderLogArgs"; +import { ProviderLogService } from "../providerLog.service"; +@graphql.Resolver(() => ProviderLog) +export class ProviderLogResolverBase { + constructor(protected readonly service: ProviderLogService) {} + + async _providerLogsMeta( + @graphql.Args() args: ProviderLogCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [ProviderLog]) + async providerLogs( + @graphql.Args() args: ProviderLogFindManyArgs + ): Promise<ProviderLog[]> { + return this.service.providerLogs(args); + } + + @graphql.Query(() => ProviderLog, { nullable: true }) + async providerLog( + @graphql.Args() args: ProviderLogFindUniqueArgs + ): Promise<ProviderLog | null> { + const result = await this.service.providerLog(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => ProviderLog) + async createProviderLog( + @graphql.Args() args: CreateProviderLogArgs + ): Promise<ProviderLog> { + return await this.service.createProviderLog({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => ProviderLog) + async updateProviderLog( + @graphql.Args() args: UpdateProviderLogArgs + ): Promise<ProviderLog | null> { + try { + return await this.service.updateProviderLog({ + ...args, + data: args.data, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => ProviderLog) + async deleteProviderLog( + @graphql.Args() args: DeleteProviderLogArgs + ): Promise<ProviderLog | null> { + try { + return await this.service.deleteProviderLog(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.service.base.ts b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.service.base.ts new file mode 100644 index 00000000..132afffc --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/base/providerLog.service.base.ts @@ -0,0 +1,49 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { Prisma, ProviderLog as PrismaProviderLog } from "@prisma/client"; + +export class ProviderLogServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.ProviderLogCountArgs, "select"> + ): Promise<number> { + return this.prisma.providerLog.count(args); + } + + async providerLogs( + args: Prisma.ProviderLogFindManyArgs + ): Promise<PrismaProviderLog[]> { + return this.prisma.providerLog.findMany(args); + } + async providerLog( + args: Prisma.ProviderLogFindUniqueArgs + ): Promise<PrismaProviderLog | null> { + return this.prisma.providerLog.findUnique(args); + } + async createProviderLog( + args: Prisma.ProviderLogCreateArgs + ): Promise<PrismaProviderLog> { + return this.prisma.providerLog.create(args); + } + async updateProviderLog( + args: Prisma.ProviderLogUpdateArgs + ): Promise<PrismaProviderLog> { + return this.prisma.providerLog.update(args); + } + async deleteProviderLog( + args: Prisma.ProviderLogDeleteArgs + ): Promise<PrismaProviderLog> { + return this.prisma.providerLog.delete(args); + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/providerLog.controller.ts b/apps/cloud-provider-connector-server/src/providerLog/providerLog.controller.ts new file mode 100644 index 00000000..c1c7ad54 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/providerLog.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { ProviderLogService } from "./providerLog.service"; +import { ProviderLogControllerBase } from "./base/providerLog.controller.base"; + +@swagger.ApiTags("providerLogs") +@common.Controller("providerLogs") +export class ProviderLogController extends ProviderLogControllerBase { + constructor(protected readonly service: ProviderLogService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/providerLog.module.ts b/apps/cloud-provider-connector-server/src/providerLog/providerLog.module.ts new file mode 100644 index 00000000..523b0c50 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/providerLog.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { ProviderLogModuleBase } from "./base/providerLog.module.base"; +import { ProviderLogService } from "./providerLog.service"; +import { ProviderLogController } from "./providerLog.controller"; +import { ProviderLogResolver } from "./providerLog.resolver"; + +@Module({ + imports: [ProviderLogModuleBase], + controllers: [ProviderLogController], + providers: [ProviderLogService, ProviderLogResolver], + exports: [ProviderLogService], +}) +export class ProviderLogModule {} diff --git a/apps/cloud-provider-connector-server/src/providerLog/providerLog.resolver.ts b/apps/cloud-provider-connector-server/src/providerLog/providerLog.resolver.ts new file mode 100644 index 00000000..58cadf89 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/providerLog.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { ProviderLogResolverBase } from "./base/providerLog.resolver.base"; +import { ProviderLog } from "./base/ProviderLog"; +import { ProviderLogService } from "./providerLog.service"; + +@graphql.Resolver(() => ProviderLog) +export class ProviderLogResolver extends ProviderLogResolverBase { + constructor(protected readonly service: ProviderLogService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/providerLog/providerLog.service.ts b/apps/cloud-provider-connector-server/src/providerLog/providerLog.service.ts new file mode 100644 index 00000000..213c7581 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providerLog/providerLog.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { ProviderLogServiceBase } from "./base/providerLog.service.base"; + +@Injectable() +export class ProviderLogService extends ProviderLogServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.spec.ts b/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.spec.ts new file mode 100644 index 00000000..f1611722 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.spec.ts @@ -0,0 +1,41 @@ +import { ConfigService } from "@nestjs/config"; +import { mock } from "jest-mock-extended"; +import { SecretsManagerServiceBase } from "./secretsManager.service.base"; +import { EnumSecretsNameKey } from "../secretsNameKey.enum"; + +describe("Testing the secrets manager base class", () => { + const SECRET_KEY = "SECRET_KEY"; + const SECRET_VALUE = "SECRET_VALUE"; + const configService = mock<ConfigService>(); + const secretsManagerServiceBase = new SecretsManagerServiceBase( + configService + ); + beforeEach(() => { + configService.get.mockClear(); + }); + it("should return value from env", async () => { + //ARRANGE + configService.get.mockReturnValue(SECRET_VALUE); + //ACT + const result = await secretsManagerServiceBase.getSecret( + SECRET_KEY as unknown as EnumSecretsNameKey + ); + //ASSERT + expect(result).toBe(SECRET_VALUE); + }); + it("should return null for unknown keys", async () => { + //ARRANGE + configService.get.mockReturnValue(undefined); + //ACT + const result = await secretsManagerServiceBase.getSecret( + SECRET_KEY as unknown as EnumSecretsNameKey + ); + //ASSERT + expect(result).toBeNull(); + }); + it("should throw an exception if getting null key", () => { + return expect( + secretsManagerServiceBase.getSecret(null as unknown as EnumSecretsNameKey) + ).rejects.toThrow(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.ts b/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.ts new file mode 100644 index 00000000..340818c2 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providers/secrets/base/secretsManager.service.base.ts @@ -0,0 +1,17 @@ +import { ConfigService } from "@nestjs/config"; +import { EnumSecretsNameKey } from "../secretsNameKey.enum"; + +export interface ISecretsManager { + getSecret: (key: EnumSecretsNameKey) => Promise<any | null>; +} + +export class SecretsManagerServiceBase implements ISecretsManager { + constructor(protected readonly configService: ConfigService) {} + async getSecret<T>(key: EnumSecretsNameKey): Promise<T | null> { + const value = this.configService.get(key.toString()); + if (value) { + return value; + } + return null; + } +} diff --git a/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.module.ts b/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.module.ts new file mode 100644 index 00000000..3a621e40 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.module.ts @@ -0,0 +1,8 @@ +import { Module } from "@nestjs/common"; +import { SecretsManagerService } from "./secretsManager.service"; + +@Module({ + providers: [SecretsManagerService], + exports: [SecretsManagerService], +}) +export class SecretsManagerModule {} diff --git a/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.service.ts b/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.service.ts new file mode 100644 index 00000000..89907c3b --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providers/secrets/secretsManager.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { ConfigService } from "@nestjs/config"; +import { SecretsManagerServiceBase } from "./base/secretsManager.service.base"; + +@Injectable() +export class SecretsManagerService extends SecretsManagerServiceBase { + constructor(protected readonly configService: ConfigService) { + super(configService); + } +} diff --git a/apps/cloud-provider-connector-server/src/providers/secrets/secretsNameKey.enum.ts b/apps/cloud-provider-connector-server/src/providers/secrets/secretsNameKey.enum.ts new file mode 100644 index 00000000..e225d65d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/providers/secrets/secretsNameKey.enum.ts @@ -0,0 +1 @@ +export enum EnumSecretsNameKey {} \ No newline at end of file diff --git a/apps/cloud-provider-connector-server/src/region/base/CreateRegionArgs.ts b/apps/cloud-provider-connector-server/src/region/base/CreateRegionArgs.ts new file mode 100644 index 00000000..6c7aa0fd --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/CreateRegionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionCreateInput } from "./RegionCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateRegionArgs { + @ApiProperty({ + required: true, + type: () => RegionCreateInput, + }) + @ValidateNested() + @Type(() => RegionCreateInput) + @Field(() => RegionCreateInput, { nullable: false }) + data!: RegionCreateInput; +} + +export { CreateRegionArgs as CreateRegionArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/DeleteRegionArgs.ts b/apps/cloud-provider-connector-server/src/region/base/DeleteRegionArgs.ts new file mode 100644 index 00000000..7ff7fc44 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/DeleteRegionArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteRegionArgs { + @ApiProperty({ + required: true, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @Field(() => RegionWhereUniqueInput, { nullable: false }) + where!: RegionWhereUniqueInput; +} + +export { DeleteRegionArgs as DeleteRegionArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts b/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts new file mode 100644 index 00000000..a58aabf6 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateCreateNestedManyWithoutRegionsInput.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { InstanceTemplateWhereUniqueInput } from "../../instanceTemplate/base/InstanceTemplateWhereUniqueInput"; +import { ApiProperty } from "@nestjs/swagger"; + +@InputType() +class InstanceTemplateCreateNestedManyWithoutRegionsInput { + @Field(() => [InstanceTemplateWhereUniqueInput], { + nullable: true, + }) + @ApiProperty({ + required: false, + type: () => [InstanceTemplateWhereUniqueInput], + }) + connect?: Array<InstanceTemplateWhereUniqueInput>; +} + +export { InstanceTemplateCreateNestedManyWithoutRegionsInput as InstanceTemplateCreateNestedManyWithoutRegionsInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateUpdateManyWithoutRegionsInput.ts b/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateUpdateManyWithoutRegionsInput.ts new file mode 100644 index 00000000..117f6075 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/InstanceTemplateUpdateManyWithoutRegionsInput.ts @@ -0,0 +1,46 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { InstanceTemplateWhereUniqueInput } from "../../instanceTemplate/base/InstanceTemplateWhereUniqueInput"; +import { ApiProperty } from "@nestjs/swagger"; + +@InputType() +class InstanceTemplateUpdateManyWithoutRegionsInput { + @Field(() => [InstanceTemplateWhereUniqueInput], { + nullable: true, + }) + @ApiProperty({ + required: false, + type: () => [InstanceTemplateWhereUniqueInput], + }) + connect?: Array<InstanceTemplateWhereUniqueInput>; + + @Field(() => [InstanceTemplateWhereUniqueInput], { + nullable: true, + }) + @ApiProperty({ + required: false, + type: () => [InstanceTemplateWhereUniqueInput], + }) + disconnect?: Array<InstanceTemplateWhereUniqueInput>; + + @Field(() => [InstanceTemplateWhereUniqueInput], { + nullable: true, + }) + @ApiProperty({ + required: false, + type: () => [InstanceTemplateWhereUniqueInput], + }) + set?: Array<InstanceTemplateWhereUniqueInput>; +} + +export { InstanceTemplateUpdateManyWithoutRegionsInput as InstanceTemplateUpdateManyWithoutRegionsInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/Region.ts b/apps/cloud-provider-connector-server/src/region/base/Region.ts new file mode 100644 index 00000000..0e824292 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/Region.ts @@ -0,0 +1,96 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { + IsDate, + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; +import { Type } from "class-transformer"; +import { InstanceTemplate } from "../../instanceTemplate/base/InstanceTemplate"; + +@ObjectType() +class Region { + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + description!: string | null; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @ApiProperty({ + required: false, + type: () => [InstanceTemplate], + }) + @ValidateNested() + @Type(() => InstanceTemplate) + @IsOptional() + instanceTemplates?: Array<InstanceTemplate>; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider!: string | null; + + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + updatedAt!: Date; +} + +export { Region as Region }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionCountArgs.ts b/apps/cloud-provider-connector-server/src/region/base/RegionCountArgs.ts new file mode 100644 index 00000000..6b42d38a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionCountArgs.ts @@ -0,0 +1,28 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereInput } from "./RegionWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class RegionCountArgs { + @ApiProperty({ + required: false, + type: () => RegionWhereInput, + }) + @Field(() => RegionWhereInput, { nullable: true }) + @Type(() => RegionWhereInput) + where?: RegionWhereInput; +} + +export { RegionCountArgs as RegionCountArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionCreateInput.ts b/apps/cloud-provider-connector-server/src/region/base/RegionCreateInput.ts new file mode 100644 index 00000000..79fd9b3b --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionCreateInput.ts @@ -0,0 +1,74 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; +import { InstanceTemplateCreateNestedManyWithoutRegionsInput } from "./InstanceTemplateCreateNestedManyWithoutRegionsInput"; +import { Type } from "class-transformer"; + +@InputType() +class RegionCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + description?: string | null; + + @ApiProperty({ + required: false, + type: () => InstanceTemplateCreateNestedManyWithoutRegionsInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateCreateNestedManyWithoutRegionsInput) + @IsOptional() + @Field(() => InstanceTemplateCreateNestedManyWithoutRegionsInput, { + nullable: true, + }) + instanceTemplates?: InstanceTemplateCreateNestedManyWithoutRegionsInput; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; +} + +export { RegionCreateInput as RegionCreateInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionFindManyArgs.ts b/apps/cloud-provider-connector-server/src/region/base/RegionFindManyArgs.ts new file mode 100644 index 00000000..fa138d19 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionFindManyArgs.ts @@ -0,0 +1,62 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereInput } from "./RegionWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { RegionOrderByInput } from "./RegionOrderByInput"; + +@ArgsType() +class RegionFindManyArgs { + @ApiProperty({ + required: false, + type: () => RegionWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => RegionWhereInput, { nullable: true }) + @Type(() => RegionWhereInput) + where?: RegionWhereInput; + + @ApiProperty({ + required: false, + type: [RegionOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [RegionOrderByInput], { nullable: true }) + @Type(() => RegionOrderByInput) + orderBy?: Array<RegionOrderByInput>; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + skip?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @IsInt() + @Field(() => Number, { nullable: true }) + @Type(() => Number) + take?: number; +} + +export { RegionFindManyArgs as RegionFindManyArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionFindUniqueArgs.ts b/apps/cloud-provider-connector-server/src/region/base/RegionFindUniqueArgs.ts new file mode 100644 index 00000000..eee4438f --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionFindUniqueArgs.ts @@ -0,0 +1,30 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class RegionFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @Field(() => RegionWhereUniqueInput, { nullable: false }) + where!: RegionWhereUniqueInput; +} + +export { RegionFindUniqueArgs as RegionFindUniqueArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionListRelationFilter.ts b/apps/cloud-provider-connector-server/src/region/base/RegionListRelationFilter.ts new file mode 100644 index 00000000..a3d7dd40 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionListRelationFilter.ts @@ -0,0 +1,56 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereInput } from "./RegionWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class RegionListRelationFilter { + @ApiProperty({ + required: false, + type: () => RegionWhereInput, + }) + @ValidateNested() + @Type(() => RegionWhereInput) + @IsOptional() + @Field(() => RegionWhereInput, { + nullable: true, + }) + every?: RegionWhereInput; + + @ApiProperty({ + required: false, + type: () => RegionWhereInput, + }) + @ValidateNested() + @Type(() => RegionWhereInput) + @IsOptional() + @Field(() => RegionWhereInput, { + nullable: true, + }) + some?: RegionWhereInput; + + @ApiProperty({ + required: false, + type: () => RegionWhereInput, + }) + @ValidateNested() + @Type(() => RegionWhereInput) + @IsOptional() + @Field(() => RegionWhereInput, { + nullable: true, + }) + none?: RegionWhereInput; +} +export { RegionListRelationFilter as RegionListRelationFilter }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionOrderByInput.ts b/apps/cloud-provider-connector-server/src/region/base/RegionOrderByInput.ts new file mode 100644 index 00000000..a48264ca --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionOrderByInput.ts @@ -0,0 +1,89 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional, IsEnum } from "class-validator"; +import { SortOrder } from "../../util/SortOrder"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +class RegionOrderByInput { + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + createdAt?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + description?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + id?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + name?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + provider?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + updatedAt?: SortOrder; +} + +export { RegionOrderByInput as RegionOrderByInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionUpdateInput.ts b/apps/cloud-provider-connector-server/src/region/base/RegionUpdateInput.ts new file mode 100644 index 00000000..d9f63c36 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionUpdateInput.ts @@ -0,0 +1,74 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { + IsString, + MaxLength, + IsOptional, + ValidateNested, +} from "class-validator"; +import { InstanceTemplateUpdateManyWithoutRegionsInput } from "./InstanceTemplateUpdateManyWithoutRegionsInput"; +import { Type } from "class-transformer"; + +@InputType() +class RegionUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + description?: string | null; + + @ApiProperty({ + required: false, + type: () => InstanceTemplateUpdateManyWithoutRegionsInput, + }) + @ValidateNested() + @Type(() => InstanceTemplateUpdateManyWithoutRegionsInput) + @IsOptional() + @Field(() => InstanceTemplateUpdateManyWithoutRegionsInput, { + nullable: true, + }) + instanceTemplates?: InstanceTemplateUpdateManyWithoutRegionsInput; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + name?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + provider?: string | null; +} + +export { RegionUpdateInput as RegionUpdateInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionWhereInput.ts b/apps/cloud-provider-connector-server/src/region/base/RegionWhereInput.ts new file mode 100644 index 00000000..8d4feae2 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionWhereInput.ts @@ -0,0 +1,79 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { Type } from "class-transformer"; +import { IsOptional, ValidateNested } from "class-validator"; +import { StringFilter } from "../../util/StringFilter"; +import { InstanceTemplateListRelationFilter } from "../../instanceTemplate/base/InstanceTemplateListRelationFilter"; + +@InputType() +class RegionWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + description?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringFilter, + }) + @Type(() => StringFilter) + @IsOptional() + @Field(() => StringFilter, { + nullable: true, + }) + id?: StringFilter; + + @ApiProperty({ + required: false, + type: () => InstanceTemplateListRelationFilter, + }) + @ValidateNested() + @Type(() => InstanceTemplateListRelationFilter) + @IsOptional() + @Field(() => InstanceTemplateListRelationFilter, { + nullable: true, + }) + instanceTemplates?: InstanceTemplateListRelationFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + name?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + provider?: StringNullableFilter; +} + +export { RegionWhereInput as RegionWhereInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/RegionWhereUniqueInput.ts b/apps/cloud-provider-connector-server/src/region/base/RegionWhereUniqueInput.ts new file mode 100644 index 00000000..a0946f4b --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/RegionWhereUniqueInput.ts @@ -0,0 +1,27 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { InputType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsString } from "class-validator"; + +@InputType() +class RegionWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { RegionWhereUniqueInput as RegionWhereUniqueInput }; diff --git a/apps/cloud-provider-connector-server/src/region/base/UpdateRegionArgs.ts b/apps/cloud-provider-connector-server/src/region/base/UpdateRegionArgs.ts new file mode 100644 index 00000000..401c2aa7 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/UpdateRegionArgs.ts @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { ArgsType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { RegionUpdateInput } from "./RegionUpdateInput"; + +@ArgsType() +class UpdateRegionArgs { + @ApiProperty({ + required: true, + type: () => RegionWhereUniqueInput, + }) + @ValidateNested() + @Type(() => RegionWhereUniqueInput) + @Field(() => RegionWhereUniqueInput, { nullable: false }) + where!: RegionWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => RegionUpdateInput, + }) + @ValidateNested() + @Type(() => RegionUpdateInput) + @Field(() => RegionUpdateInput, { nullable: false }) + data!: RegionUpdateInput; +} + +export { UpdateRegionArgs as UpdateRegionArgs }; diff --git a/apps/cloud-provider-connector-server/src/region/base/region.controller.base.spec.ts b/apps/cloud-provider-connector-server/src/region/base/region.controller.base.spec.ts new file mode 100644 index 00000000..2a8e8df1 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/region.controller.base.spec.ts @@ -0,0 +1,202 @@ +import { Test } from "@nestjs/testing"; +import { + INestApplication, + HttpStatus, + ExecutionContext, + CallHandler, +} from "@nestjs/common"; +import request from "supertest"; +import { ACGuard } from "nest-access-control"; +import { DefaultAuthGuard } from "../../auth/defaultAuth.guard"; +import { ACLModule } from "../../auth/acl.module"; +import { AclFilterResponseInterceptor } from "../../interceptors/aclFilterResponse.interceptor"; +import { AclValidateRequestInterceptor } from "../../interceptors/aclValidateRequest.interceptor"; +import { map } from "rxjs"; +import { RegionController } from "../region.controller"; +import { RegionService } from "../region.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + createdAt: new Date(), + description: "exampleDescription", + id: "exampleId", + name: "exampleName", + provider: "exampleProvider", + updatedAt: new Date(), +}; +const CREATE_RESULT = { + createdAt: new Date(), + description: "exampleDescription", + id: "exampleId", + name: "exampleName", + provider: "exampleProvider", + updatedAt: new Date(), +}; +const FIND_MANY_RESULT = [ + { + createdAt: new Date(), + description: "exampleDescription", + id: "exampleId", + name: "exampleName", + provider: "exampleProvider", + updatedAt: new Date(), + }, +]; +const FIND_ONE_RESULT = { + createdAt: new Date(), + description: "exampleDescription", + id: "exampleId", + name: "exampleName", + provider: "exampleProvider", + updatedAt: new Date(), +}; + +const service = { + createRegion() { + return CREATE_RESULT; + }, + regions: () => FIND_MANY_RESULT, + region: ({ where }: { where: { id: string } }) => { + switch (where.id) { + case existingId: + return FIND_ONE_RESULT; + case nonExistingId: + return null; + } + }, +}; + +const basicAuthGuard = { + canActivate: (context: ExecutionContext) => { + const argumentHost = context.switchToHttp(); + const request = argumentHost.getRequest(); + request.user = { + roles: ["user"], + }; + return true; + }, +}; + +const acGuard = { + canActivate: () => { + return true; + }, +}; + +const aclFilterResponseInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle().pipe( + map((data) => { + return data; + }) + ); + }, +}; +const aclValidateRequestInterceptor = { + intercept: (context: ExecutionContext, next: CallHandler) => { + return next.handle(); + }, +}; + +describe("Region", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: RegionService, + useValue: service, + }, + ], + controllers: [RegionController], + imports: [ACLModule], + }) + .overrideGuard(DefaultAuthGuard) + .useValue(basicAuthGuard) + .overrideGuard(ACGuard) + .useValue(acGuard) + .overrideInterceptor(AclFilterResponseInterceptor) + .useValue(aclFilterResponseInterceptor) + .overrideInterceptor(AclValidateRequestInterceptor) + .useValue(aclValidateRequestInterceptor) + .compile(); + + app = moduleRef.createNestApplication(); + await app.init(); + }); + + test("POST /regions", async () => { + await request(app.getHttpServer()) + .post("/regions") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /regions", async () => { + await request(app.getHttpServer()) + .get("/regions") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /regions/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/regions"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /regions/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/regions"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /regions existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/regions") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/regions") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/region/base/region.controller.base.ts b/apps/cloud-provider-connector-server/src/region/base/region.controller.base.ts new file mode 100644 index 00000000..9064510d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/region.controller.base.ts @@ -0,0 +1,234 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { isRecordNotFoundError } from "../../prisma.util"; +import * as errors from "../../errors"; +import { Request } from "express"; +import { plainToClass } from "class-transformer"; +import { ApiNestedQuery } from "../../decorators/api-nested-query.decorator"; +import { RegionService } from "../region.service"; +import { RegionCreateInput } from "./RegionCreateInput"; +import { Region } from "./Region"; +import { RegionFindManyArgs } from "./RegionFindManyArgs"; +import { RegionWhereUniqueInput } from "./RegionWhereUniqueInput"; +import { RegionUpdateInput } from "./RegionUpdateInput"; +import { InstanceTemplateFindManyArgs } from "../../instanceTemplate/base/InstanceTemplateFindManyArgs"; +import { InstanceTemplate } from "../../instanceTemplate/base/InstanceTemplate"; +import { InstanceTemplateWhereUniqueInput } from "../../instanceTemplate/base/InstanceTemplateWhereUniqueInput"; + +export class RegionControllerBase { + constructor(protected readonly service: RegionService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: Region }) + async createRegion(@common.Body() data: RegionCreateInput): Promise<Region> { + return await this.service.createRegion({ + data: data, + select: { + createdAt: true, + description: true, + id: true, + name: true, + provider: true, + updatedAt: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [Region] }) + @ApiNestedQuery(RegionFindManyArgs) + async regions(@common.Req() request: Request): Promise<Region[]> { + const args = plainToClass(RegionFindManyArgs, request.query); + return this.service.regions({ + ...args, + select: { + createdAt: true, + description: true, + id: true, + name: true, + provider: true, + updatedAt: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: Region }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async region( + @common.Param() params: RegionWhereUniqueInput + ): Promise<Region | null> { + const result = await this.service.region({ + where: params, + select: { + createdAt: true, + description: true, + id: true, + name: true, + provider: true, + updatedAt: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: Region }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateRegion( + @common.Param() params: RegionWhereUniqueInput, + @common.Body() data: RegionUpdateInput + ): Promise<Region | null> { + try { + return await this.service.updateRegion({ + where: params, + data: data, + select: { + createdAt: true, + description: true, + id: true, + name: true, + provider: true, + updatedAt: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Delete("/:id") + @swagger.ApiOkResponse({ type: Region }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteRegion( + @common.Param() params: RegionWhereUniqueInput + ): Promise<Region | null> { + try { + return await this.service.deleteRegion({ + where: params, + select: { + createdAt: true, + description: true, + id: true, + name: true, + provider: true, + updatedAt: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } + + @common.Get("/:id/instanceTemplates") + @ApiNestedQuery(InstanceTemplateFindManyArgs) + async findInstanceTemplates( + @common.Req() request: Request, + @common.Param() params: RegionWhereUniqueInput + ): Promise<InstanceTemplate[]> { + const query = plainToClass(InstanceTemplateFindManyArgs, request.query); + const results = await this.service.findInstanceTemplates(params.id, { + ...query, + select: { + cpu: true, + createdAt: true, + hasGpu: true, + id: true, + memoryGb: true, + name: true, + provider: true, + + region: { + select: { + id: true, + }, + }, + + storageGb: true, + updatedAt: true, + }, + }); + if (results === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return results; + } + + @common.Post("/:id/instanceTemplates") + async connectInstanceTemplates( + @common.Param() params: RegionWhereUniqueInput, + @common.Body() body: InstanceTemplateWhereUniqueInput[] + ): Promise<void> { + const data = { + instanceTemplates: { + connect: body, + }, + }; + await this.service.updateRegion({ + where: params, + data, + select: { id: true }, + }); + } + + @common.Patch("/:id/instanceTemplates") + async updateInstanceTemplates( + @common.Param() params: RegionWhereUniqueInput, + @common.Body() body: InstanceTemplateWhereUniqueInput[] + ): Promise<void> { + const data = { + instanceTemplates: { + set: body, + }, + }; + await this.service.updateRegion({ + where: params, + data, + select: { id: true }, + }); + } + + @common.Delete("/:id/instanceTemplates") + async disconnectInstanceTemplates( + @common.Param() params: RegionWhereUniqueInput, + @common.Body() body: InstanceTemplateWhereUniqueInput[] + ): Promise<void> { + const data = { + instanceTemplates: { + disconnect: body, + }, + }; + await this.service.updateRegion({ + where: params, + data, + select: { id: true }, + }); + } +} diff --git a/apps/cloud-provider-connector-server/src/region/base/region.module.base.ts b/apps/cloud-provider-connector-server/src/region/base/region.module.base.ts new file mode 100644 index 00000000..d60a7264 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/region.module.base.ts @@ -0,0 +1,18 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { Module } from "@nestjs/common"; + +@Module({ + imports: [], + exports: [], +}) +export class RegionModuleBase {} diff --git a/apps/cloud-provider-connector-server/src/region/base/region.resolver.base.ts b/apps/cloud-provider-connector-server/src/region/base/region.resolver.base.ts new file mode 100644 index 00000000..cb16ce9d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/region.resolver.base.ts @@ -0,0 +1,111 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import * as graphql from "@nestjs/graphql"; +import { GraphQLError } from "graphql"; +import { isRecordNotFoundError } from "../../prisma.util"; +import { MetaQueryPayload } from "../../util/MetaQueryPayload"; +import { Region } from "./Region"; +import { RegionCountArgs } from "./RegionCountArgs"; +import { RegionFindManyArgs } from "./RegionFindManyArgs"; +import { RegionFindUniqueArgs } from "./RegionFindUniqueArgs"; +import { CreateRegionArgs } from "./CreateRegionArgs"; +import { UpdateRegionArgs } from "./UpdateRegionArgs"; +import { DeleteRegionArgs } from "./DeleteRegionArgs"; +import { InstanceTemplateFindManyArgs } from "../../instanceTemplate/base/InstanceTemplateFindManyArgs"; +import { InstanceTemplate } from "../../instanceTemplate/base/InstanceTemplate"; +import { RegionService } from "../region.service"; +@graphql.Resolver(() => Region) +export class RegionResolverBase { + constructor(protected readonly service: RegionService) {} + + async _regionsMeta( + @graphql.Args() args: RegionCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [Region]) + async regions(@graphql.Args() args: RegionFindManyArgs): Promise<Region[]> { + return this.service.regions(args); + } + + @graphql.Query(() => Region, { nullable: true }) + async region( + @graphql.Args() args: RegionFindUniqueArgs + ): Promise<Region | null> { + const result = await this.service.region(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => Region) + async createRegion(@graphql.Args() args: CreateRegionArgs): Promise<Region> { + return await this.service.createRegion({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => Region) + async updateRegion( + @graphql.Args() args: UpdateRegionArgs + ): Promise<Region | null> { + try { + return await this.service.updateRegion({ + ...args, + data: args.data, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.Mutation(() => Region) + async deleteRegion( + @graphql.Args() args: DeleteRegionArgs + ): Promise<Region | null> { + try { + return await this.service.deleteRegion(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } + + @graphql.ResolveField(() => [InstanceTemplate], { name: "instanceTemplates" }) + async findInstanceTemplates( + @graphql.Parent() parent: Region, + @graphql.Args() args: InstanceTemplateFindManyArgs + ): Promise<InstanceTemplate[]> { + const results = await this.service.findInstanceTemplates(parent.id, args); + + if (!results) { + return []; + } + + return results; + } +} diff --git a/apps/cloud-provider-connector-server/src/region/base/region.service.base.ts b/apps/cloud-provider-connector-server/src/region/base/region.service.base.ts new file mode 100644 index 00000000..8c092d84 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/base/region.service.base.ts @@ -0,0 +1,54 @@ +/* +------------------------------------------------------------------------------ +This code was generated by Amplication. + +Changes to this file will be lost if the code is regenerated. + +There are other ways to to customize your code, see this doc to learn more +https://docs.amplication.com/how-to/custom-code + +------------------------------------------------------------------------------ + */ +import { PrismaService } from "../../prisma/prisma.service"; +import { + Prisma, + Region as PrismaRegion, + InstanceTemplate as PrismaInstanceTemplate, +} from "@prisma/client"; + +export class RegionServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count(args: Omit<Prisma.RegionCountArgs, "select">): Promise<number> { + return this.prisma.region.count(args); + } + + async regions(args: Prisma.RegionFindManyArgs): Promise<PrismaRegion[]> { + return this.prisma.region.findMany(args); + } + async region( + args: Prisma.RegionFindUniqueArgs + ): Promise<PrismaRegion | null> { + return this.prisma.region.findUnique(args); + } + async createRegion(args: Prisma.RegionCreateArgs): Promise<PrismaRegion> { + return this.prisma.region.create(args); + } + async updateRegion(args: Prisma.RegionUpdateArgs): Promise<PrismaRegion> { + return this.prisma.region.update(args); + } + async deleteRegion(args: Prisma.RegionDeleteArgs): Promise<PrismaRegion> { + return this.prisma.region.delete(args); + } + + async findInstanceTemplates( + parentId: string, + args: Prisma.InstanceTemplateFindManyArgs + ): Promise<PrismaInstanceTemplate[]> { + return this.prisma.region + .findUniqueOrThrow({ + where: { id: parentId }, + }) + .instanceTemplates(args); + } +} diff --git a/apps/cloud-provider-connector-server/src/region/region.controller.ts b/apps/cloud-provider-connector-server/src/region/region.controller.ts new file mode 100644 index 00000000..a2fb259d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/region.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { RegionService } from "./region.service"; +import { RegionControllerBase } from "./base/region.controller.base"; + +@swagger.ApiTags("regions") +@common.Controller("regions") +export class RegionController extends RegionControllerBase { + constructor(protected readonly service: RegionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/region/region.module.ts b/apps/cloud-provider-connector-server/src/region/region.module.ts new file mode 100644 index 00000000..86415467 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/region.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { RegionModuleBase } from "./base/region.module.base"; +import { RegionService } from "./region.service"; +import { RegionController } from "./region.controller"; +import { RegionResolver } from "./region.resolver"; + +@Module({ + imports: [RegionModuleBase], + controllers: [RegionController], + providers: [RegionService, RegionResolver], + exports: [RegionService], +}) +export class RegionModule {} diff --git a/apps/cloud-provider-connector-server/src/region/region.resolver.ts b/apps/cloud-provider-connector-server/src/region/region.resolver.ts new file mode 100644 index 00000000..1388b574 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/region.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { RegionResolverBase } from "./base/region.resolver.base"; +import { Region } from "./base/Region"; +import { RegionService } from "./region.service"; + +@graphql.Resolver(() => Region) +export class RegionResolver extends RegionResolverBase { + constructor(protected readonly service: RegionService) { + super(service); + } +} diff --git a/apps/cloud-provider-connector-server/src/region/region.service.ts b/apps/cloud-provider-connector-server/src/region/region.service.ts new file mode 100644 index 00000000..1471b91d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/region/region.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { RegionServiceBase } from "./base/region.service.base"; + +@Injectable() +export class RegionService extends RegionServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/cloud-provider-connector-server/src/serveStaticOptions.service.ts b/apps/cloud-provider-connector-server/src/serveStaticOptions.service.ts new file mode 100644 index 00000000..390248b4 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/serveStaticOptions.service.ts @@ -0,0 +1,39 @@ +import * as path from "path"; +import { Injectable, Logger } from "@nestjs/common"; +import { ConfigService } from "@nestjs/config"; +import { + ServeStaticModuleOptions, + ServeStaticModuleOptionsFactory, +} from "@nestjs/serve-static"; + +const SERVE_STATIC_ROOT_PATH_VAR = "SERVE_STATIC_ROOT_PATH"; +const DEFAULT_STATIC_MODULE_OPTIONS_LIST: ServeStaticModuleOptions[] = [ + { + serveRoot: "/swagger", + rootPath: path.join(__dirname, "swagger"), + }, +]; + +@Injectable() +export class ServeStaticOptionsService + implements ServeStaticModuleOptionsFactory +{ + private readonly logger = new Logger(ServeStaticOptionsService.name); + + constructor(private readonly configService: ConfigService) {} + + createLoggerOptions(): ServeStaticModuleOptions[] { + const serveStaticRootPath = this.configService.get( + SERVE_STATIC_ROOT_PATH_VAR + ); + if (serveStaticRootPath) { + const resolvedPath = path.resolve(serveStaticRootPath); + this.logger.log(`Serving static files from ${resolvedPath}`); + return [ + ...DEFAULT_STATIC_MODULE_OPTIONS_LIST, + { rootPath: resolvedPath, exclude: ["/api*", "/graphql"] }, + ]; + } + return DEFAULT_STATIC_MODULE_OPTIONS_LIST; + } +} diff --git a/apps/cloud-provider-connector-server/src/swagger.ts b/apps/cloud-provider-connector-server/src/swagger.ts new file mode 100644 index 00000000..a0616a21 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/swagger.ts @@ -0,0 +1,20 @@ +import { DocumentBuilder, SwaggerCustomOptions } from "@nestjs/swagger"; + +export const swaggerPath = "api"; + +export const swaggerDocumentOptions = new DocumentBuilder() + .setTitle("Cloud Provider Connector") + .setDescription( + 'API connections to AWS, Azure, and GCP.\n\n## Congratulations! Your service resource is ready.\n \nPlease note that all endpoints are secured with JWT Bearer authentication.\nBy default, your service resource comes with one user with the username "admin" and password "admin".\nLearn more in [our docs](https://docs.amplication.com)' + ) + .addBearerAuth() + .build(); + +export const swaggerSetupOptions: SwaggerCustomOptions = { + swaggerOptions: { + persistAuthorization: true, + }, + customCssUrl: "../swagger/swagger.css", + customfavIcon: "../swagger/favicon.png", + customSiteTitle: "Cloud Provider Connector", +}; diff --git a/apps/cloud-provider-connector-server/src/swagger/favicon.png b/apps/cloud-provider-connector-server/src/swagger/favicon.png new file mode 100644 index 00000000..a79882d5 Binary files /dev/null and b/apps/cloud-provider-connector-server/src/swagger/favicon.png differ diff --git a/apps/cloud-provider-connector-server/src/swagger/logo-amplication-white.svg b/apps/cloud-provider-connector-server/src/swagger/logo-amplication-white.svg new file mode 100644 index 00000000..0054cd4d --- /dev/null +++ b/apps/cloud-provider-connector-server/src/swagger/logo-amplication-white.svg @@ -0,0 +1,15 @@ +<svg width="206" height="45" viewBox="0 0 206 45" fill="none" xmlns="http://www.w3.org/2000/svg"> +<path d="M0 22.472C0 34.0994 8.90877 43.6025 20.3874 44.9441V0C8.90877 1.34161 0 10.9006 0 22.472Z" fill="white"/> +<path d="M46.2574 22.472C46.2574 10.8447 37.2344 1.22981 25.6987 0V45H46.2574V23.1429C46.2574 22.9193 46.2574 22.6957 46.2574 22.472Z" fill="white"/> +<path d="M70.8698 26.2732V38.8508H67.6718V37.1738C66.8152 38.5154 64.9877 39.1303 63.3887 39.1303C60.0194 39.1303 57.0498 36.5589 57.0498 32.534C57.0498 28.5092 59.9623 25.9937 63.3887 25.9937C64.9877 25.9937 66.8152 26.6086 67.6718 27.9502V26.2732H70.8698ZM67.6147 32.534C67.6147 30.298 65.7301 28.9005 63.9027 28.9005C61.9039 28.9005 60.3049 30.4098 60.3049 32.534C60.3049 34.6583 61.9039 36.2235 63.9027 36.2235C65.8444 36.2235 67.6147 34.7701 67.6147 32.534Z" fill="white"/> +<path d="M95.14 31.8074V38.8509H91.942V32.031C91.942 30.0186 90.857 29.0124 89.3722 29.0124C87.5447 29.0124 86.3455 30.354 86.5168 32.6459V32.5341V38.8509H83.3188V32.031C83.3188 30.0186 82.2337 29.0124 80.8632 29.0124C79.3784 29.0124 77.8936 29.795 77.8936 32.1987V38.8509H74.6956V26.2733H77.8936V28.4534C78.3504 26.8882 80.1208 26.0497 81.7198 26.0497C83.6043 26.0497 85.1462 26.8882 85.8886 28.5093C86.9166 26.4969 88.9153 26.0497 90.2288 26.0497C93.4268 25.9938 95.14 28.118 95.14 31.8074Z" fill="white"/> +<path d="M112.614 32.534C112.614 36.5589 109.702 39.0744 106.276 39.0744C104.677 39.0744 102.849 38.4595 101.992 37.1179V44.944H98.7944V26.2732H101.992V27.9502C102.849 26.6086 104.734 25.9937 106.276 25.9937C109.645 25.9937 112.614 28.5651 112.614 32.534ZM109.416 32.5899C109.416 30.4657 107.76 28.9005 105.762 28.9005C103.82 28.9005 102.05 30.3539 102.05 32.5899C102.05 34.8259 103.934 36.2235 105.762 36.2235C107.76 36.2235 109.416 34.7141 109.416 32.5899Z" fill="white"/> +<path d="M115.642 19.5092H118.84V38.8508H115.642V19.5092Z" fill="white"/> +<path d="M122.152 21.8006C122.152 20.6826 123.123 19.9 124.265 19.9C125.407 19.9 126.321 20.6826 126.321 21.8006C126.321 22.8628 125.407 23.7013 124.265 23.7013C123.123 23.7572 122.152 22.9187 122.152 21.8006ZM122.609 26.2727H125.807V38.8503H122.609V26.2727Z" fill="white"/> +<path d="M128.834 32.534C128.834 28.5651 132.09 25.9937 135.859 25.9937C138.086 25.9937 139.913 26.944 141.113 28.3974L138.828 30.1303C138.143 29.3477 137.058 28.8446 135.916 28.8446C133.689 28.8446 132.09 30.3539 132.09 32.4781C132.09 34.6024 133.689 36.1117 135.916 36.1117C137.058 36.1117 138.143 35.6086 138.828 34.826L141.113 36.5589C139.913 38.0123 138.086 38.9626 135.859 38.9626C132.09 39.1303 128.834 36.5589 128.834 32.534Z" fill="white"/> +<path d="M156.589 26.2732V38.8508H153.391V37.1738C152.534 38.5154 150.707 39.1303 149.107 39.1303C145.738 39.1303 142.769 36.5589 142.769 32.534C142.769 28.5092 145.681 25.9937 149.107 25.9937C150.707 25.9937 152.534 26.6086 153.391 27.9502V26.2732H156.589ZM153.333 32.534C153.333 30.298 151.449 28.9005 149.621 28.9005C147.623 28.9005 146.024 30.4098 146.024 32.534C146.024 34.6583 147.623 36.2235 149.621 36.2235C151.563 36.2235 153.333 34.7701 153.333 32.534Z" fill="white"/> +<path d="M167.496 28.7891H164.755V38.9071H161.556V28.7891H159.215V26.2735H161.556V21.6338H164.755V26.2735H167.496V28.7891Z" fill="white"/> +<path d="M169.438 21.8006C169.438 20.6826 170.409 19.9 171.551 19.9C172.693 19.9 173.607 20.6826 173.607 21.8006C173.607 22.8628 172.693 23.7013 171.551 23.7013C170.409 23.7572 169.438 22.9187 169.438 21.8006ZM169.952 26.2727H173.15V38.8503H169.952V26.2727Z" fill="white"/> +<path d="M176.12 32.534C176.12 28.5651 179.318 25.9937 182.973 25.9937C186.627 25.9937 189.825 28.5092 189.825 32.534C189.825 36.503 186.627 39.1303 182.973 39.1303C179.318 39.1303 176.12 36.503 176.12 32.534ZM186.627 32.534C186.627 30.3539 184.971 28.9005 182.973 28.9005C180.974 28.9005 179.375 30.3539 179.375 32.534C179.375 34.7701 180.974 36.2235 182.973 36.2235C184.971 36.2235 186.627 34.7701 186.627 32.534Z" fill="white"/> +<path d="M205.187 31.8073V38.8508H201.989V32.0868C201.989 30.0744 200.733 29.0682 199.305 29.0682C197.82 29.0682 196.05 29.8508 196.05 32.2545V38.8508H192.852V26.2732H196.05V28.2856C196.735 26.7204 198.734 25.9937 200.047 25.9937C203.36 25.9937 205.187 28.1179 205.187 31.8073Z" fill="white"/> +</svg> diff --git a/apps/cloud-provider-connector-server/src/swagger/swagger.css b/apps/cloud-provider-connector-server/src/swagger/swagger.css new file mode 100644 index 00000000..b7c40372 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/swagger/swagger.css @@ -0,0 +1,321 @@ +html, +body { + background-color: #f4f4f7; +} + +body { + margin: auto; + line-height: 1.6; + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + color: #121242; +} + +.swagger-ui { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; +} + +.swagger-ui button, +.swagger-ui input, +.swagger-ui optgroup, +.swagger-ui select, +.swagger-ui textarea, +.swagger-ui .parameter__name, +.swagger-ui .parameters-col_name > *, +.swagger-ui label { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-weight: normal; + font-size: 12px; + outline: none; +} + +.swagger-ui textarea { + border: 1px solid #d0d0d9; + min-height: 100px; +} + +.swagger-ui input[type="email"], +.swagger-ui input[type="file"], +.swagger-ui input[type="password"], +.swagger-ui input[type="search"], +.swagger-ui input[type="text"], +.swagger-ui textarea { + border-radius: 3px; +} + +.swagger-ui input[disabled], +.swagger-ui select[disabled], +.swagger-ui textarea[disabled] { + background: #f4f4f7; + color: #b8b8c6; +} + +.swagger-ui .btn { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-weight: 500; + box-shadow: none; + border: 1px solid #d0d0d9; + height: 28px; + border-radius: 14px; + background-color: #fff; + color: #7950ed; +} + +.swagger-ui .btn:hover { + box-shadow: none; +} + +/* topbar */ + +.swagger-ui .topbar { + background-color: #7950ed; + height: 80px; + padding: 0; + display: flex; + flex-direction: row; + align-items: center; + justify-content: flex-start; +} + +.swagger-ui .topbar-wrapper a { + display: block; + width: 206px; + height: 35px; + background-image: url("logo-amplication-white.svg"); + background-repeat: no-repeat; + background-size: contain; +} + +.swagger-ui .topbar-wrapper svg, +.swagger-ui .topbar-wrapper img { + display: none; +} + +/* title */ +.swagger-ui .info { + margin: 0; +} + +.swagger-ui .info .title { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-size: 32px; + font-weight: 600; +} + +.swagger-ui .information-container { + padding-top: 50px; + padding-bottom: 20px; + position: relative; +} + +.swagger-ui .info .title small.version-stamp { + display: none; +} + +.swagger-ui .info .title small { + background-color: #a787ff; +} + +.swagger-ui .info .description p { + max-width: 1000px; + margin: 0; +} + +.swagger-ui .info .description p, +.swagger-ui .info .description a { + font-size: 1rem; +} + +.swagger-ui .information-container section { + position: relative; +} + +.swagger-ui .scheme-container { + box-shadow: none; + background-color: transparent; + position: relative; + margin: 0; + margin-top: 20px; + margin-bottom: 20px; + padding: 0; +} + +.swagger-ui .scheme-container .auth-wrapper { + justify-content: flex-start; +} + +.swagger-ui .btn.authorize { + box-shadow: none; + border: 1px solid #d0d0d9; + height: 40px; + border-radius: 20px; + background-color: #fff; + color: #7950ed; +} + +.swagger-ui .btn.authorize svg { + fill: #7950ed; +} + +/* content */ + +.swagger-ui .opblock-tag { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-size: 28px; + font-weight: 600; +} + +.swagger-ui .opblock.is-open .opblock-summary { + border-color: #e7e7ec !important; + border-bottom: none; +} + +.swagger-ui .opblock .opblock-section-header { + background-color: #fff; + border: none; + border-top: 1px solid #e7e7ec; + border-bottom: 1px solid #e7e7ec; + box-shadow: none; +} + +.swagger-ui .opblock .tab-header .tab-item.active h4 span:after { + display: none; +} + +.swagger-ui .opblock.opblock-post { + border: 1px solid #e7e7ec; + background: #f9f9fa; + box-shadow: none; + color: #fff; +} + +.swagger-ui .opblock.opblock-post:hover, +.swagger-ui .opblock.opblock-post.is-open { + border-color: #31c587; +} + +.swagger-ui .opblock.opblock-post .opblock-summary-method { + background-color: #31c587; +} + +.swagger-ui .opblock.opblock-get { + border: 1px solid #e7e7ec; + background: #f9f9fa; + box-shadow: none; +} +.swagger-ui .opblock.opblock-get:hover, +.swagger-ui .opblock.opblock-get.is-open { + border-color: #20a4f3; +} +.swagger-ui .opblock.opblock-get .opblock-summary-method { + background-color: #20a4f3; +} + +.swagger-ui .opblock.opblock-delete { + border: 1px solid #e7e7ec; + background: #f9f9fa; + box-shadow: none; +} +.swagger-ui .opblock.opblock-delete:hover, +.swagger-ui .opblock.opblock-delete.is-open { + border-color: #e93c51; +} +.swagger-ui .opblock.opblock-delete .opblock-summary-method { + background-color: #e93c51; +} + +.swagger-ui .opblock.opblock-patch { + border: 1px solid #e7e7ec; + background: #f9f9fa; + box-shadow: none; +} +.swagger-ui .opblock.opblock-patch:hover, +.swagger-ui .opblock.opblock-patch.is-open { + border-color: #41cadd; +} +.swagger-ui .opblock.opblock-patch .opblock-summary-method { + background-color: #41cadd; +} + +.swagger-ui .opblock-body pre { + background-color: #121242 !important; +} + +.swagger-ui select, +.swagger-ui .response-control-media-type--accept-controller select { + border: 1px solid #d0d0d9; + box-shadow: none; + outline: none; +} + +/* models */ + +.swagger-ui section.models { + background-color: #fff; + border: 1px solid #e7e7ec; +} + +.swagger-ui section.models.is-open h4 { + border-bottom: 1px solid #e7e7ec; +} + +.swagger-ui section.models .model-container, +.swagger-ui section.models .model-container:hover { + background-color: #f4f4f7; + color: #121242; +} + +.swagger-ui .model-title { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-weight: normal; + font-size: 15px; + color: #121242; +} + +/* modal */ + +.swagger-ui .dialog-ux .modal-ux-header h3, +.swagger-ui .dialog-ux .modal-ux-content h4, +.swagger-ui .dialog-ux .modal-ux-content h4 code { + font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", + "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", + "Helvetica Neue", sans-serif; + font-weight: normal; + font-size: 15px; + color: #121242; +} + +.swagger-ui .dialog-ux .modal-ux-content .btn.authorize { + height: 28px; + border-radius: 14px; +} + +.swagger-ui .auth-btn-wrapper { + display: flex; + flex-direction: row-reverse; + align-items: center; + justify-content: flex-start; +} + +.swagger-ui .auth-btn-wrapper .btn-done { + border: none; + color: #121242; + margin-right: 0; +} + +.swagger-ui .authorization__btn { + fill: #414168; +} diff --git a/apps/cloud-provider-connector-server/src/tests/health/health.service.spec.ts b/apps/cloud-provider-connector-server/src/tests/health/health.service.spec.ts new file mode 100644 index 00000000..4b191f1f --- /dev/null +++ b/apps/cloud-provider-connector-server/src/tests/health/health.service.spec.ts @@ -0,0 +1,36 @@ +import { mock } from "jest-mock-extended"; +import { PrismaService } from "../../prisma/prisma.service"; +import { HealthServiceBase } from "../../health/base/health.service.base"; + +describe("Testing the HealthServiceBase", () => { + //ARRANGE + let prismaService: PrismaService; + let healthServiceBase: HealthServiceBase; + + describe("Testing the isDbReady function in HealthServiceBase class", () => { + beforeEach(() => { + prismaService = mock<PrismaService>(); + healthServiceBase = new HealthServiceBase(prismaService); + }); + it("should return true if allow connection to db", async () => { + //ARRANGE + (prismaService.$queryRaw as jest.Mock).mockReturnValue( + Promise.resolve(true) + ); + //ACT + const response = await healthServiceBase.isDbReady(); + //ASSERT + expect(response).toBe(true); + }); + it("should return false if db is not available", async () => { + //ARRANGE + (prismaService.$queryRaw as jest.Mock).mockReturnValue( + Promise.reject(false) + ); + //ACT + const response = await healthServiceBase.isDbReady(); + //ASSERT + expect(response).toBe(false); + }); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/types.ts b/apps/cloud-provider-connector-server/src/types.ts new file mode 100644 index 00000000..f762a5df --- /dev/null +++ b/apps/cloud-provider-connector-server/src/types.ts @@ -0,0 +1,3 @@ +import type { JsonValue } from "type-fest"; + +export type InputJsonValue = Omit<JsonValue, "null">; diff --git a/apps/cloud-provider-connector-server/src/util/BooleanFilter.ts b/apps/cloud-provider-connector-server/src/util/BooleanFilter.ts new file mode 100644 index 00000000..75f4e344 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/BooleanFilter.ts @@ -0,0 +1,32 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class BooleanFilter { + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + @Type(() => Boolean) + equals?: boolean; + + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + @Type(() => Boolean) + not?: boolean; +} diff --git a/apps/cloud-provider-connector-server/src/util/BooleanNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/BooleanNullableFilter.ts new file mode 100644 index 00000000..9f48ac17 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/BooleanNullableFilter.ts @@ -0,0 +1,31 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; +@InputType({ + isAbstract: true, + description: undefined, +}) +export class BooleanNullableFilter { + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + @Type(() => Boolean) + equals?: boolean | null; + + @ApiProperty({ + required: false, + type: Boolean, + }) + @IsOptional() + @Field(() => Boolean, { + nullable: true, + }) + @Type(() => Boolean) + not?: boolean | null; +} diff --git a/apps/cloud-provider-connector-server/src/util/DateTimeFilter.ts b/apps/cloud-provider-connector-server/src/util/DateTimeFilter.ts new file mode 100644 index 00000000..d2b6dfba --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/DateTimeFilter.ts @@ -0,0 +1,97 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; +@InputType({ + isAbstract: true, + description: undefined, +}) +export class DateTimeFilter { + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + equals?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + not?: Date; + + @ApiProperty({ + required: false, + type: [Date], + }) + @IsOptional() + @Field(() => [Date], { + nullable: true, + }) + @Type(() => Date) + in?: Date[]; + + @ApiProperty({ + required: false, + type: [Date], + }) + @IsOptional() + @Field(() => [Date], { + nullable: true, + }) + @Type(() => Date) + notIn?: Date[]; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + lt?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + lte?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + gt?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + gte?: Date; +} diff --git a/apps/cloud-provider-connector-server/src/util/DateTimeNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/DateTimeNullableFilter.ts new file mode 100644 index 00000000..ccc00a54 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/DateTimeNullableFilter.ts @@ -0,0 +1,97 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; +@InputType({ + isAbstract: true, + description: undefined, +}) +export class DateTimeNullableFilter { + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + equals?: Date | null; + + @ApiProperty({ + required: false, + type: [Date], + }) + @IsOptional() + @Field(() => [Date], { + nullable: true, + }) + @Type(() => Date) + in?: Date[] | null; + + @ApiProperty({ + required: false, + type: [Date], + }) + @IsOptional() + @Field(() => [Date], { + nullable: true, + }) + @Type(() => Date) + notIn?: Date[] | null; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + lt?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + lte?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + gt?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + gte?: Date; + + @ApiProperty({ + required: false, + type: Date, + }) + @IsOptional() + @Field(() => Date, { + nullable: true, + }) + @Type(() => Date) + not?: Date; +} diff --git a/apps/cloud-provider-connector-server/src/util/FloatFilter.ts b/apps/cloud-provider-connector-server/src/util/FloatFilter.ts new file mode 100644 index 00000000..a3266d21 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/FloatFilter.ts @@ -0,0 +1,98 @@ +import { Field, InputType, Float } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class FloatFilter { + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + equals?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => [Float], { + nullable: true, + }) + @Type(() => Number) + in?: number[]; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Float], { + nullable: true, + }) + @Type(() => Number) + notIn?: number[]; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + lt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + lte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + gt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + gte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + not?: number; +} diff --git a/apps/cloud-provider-connector-server/src/util/FloatNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/FloatNullableFilter.ts new file mode 100644 index 00000000..feb0fc52 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/FloatNullableFilter.ts @@ -0,0 +1,98 @@ +import { Field, InputType, Float } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class FloatNullableFilter { + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + equals?: number | null; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Float], { + nullable: true, + }) + @Type(() => Number) + in?: number[] | null; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Float], { + nullable: true, + }) + @Type(() => Number) + notIn?: number[] | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + lt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + lte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + gt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + gte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Float, { + nullable: true, + }) + @Type(() => Number) + not?: number; +} diff --git a/apps/cloud-provider-connector-server/src/util/IntFilter.ts b/apps/cloud-provider-connector-server/src/util/IntFilter.ts new file mode 100644 index 00000000..f6880e77 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/IntFilter.ts @@ -0,0 +1,98 @@ +import { Field, InputType, Int } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class IntFilter { + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + equals?: number; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Int], { + nullable: true, + }) + @Type(() => Number) + in?: number[]; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Int], { + nullable: true, + }) + @Type(() => Number) + notIn?: number[]; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + lt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + lte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + gt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + gte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + not?: number; +} diff --git a/apps/cloud-provider-connector-server/src/util/IntNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/IntNullableFilter.ts new file mode 100644 index 00000000..e3b71a33 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/IntNullableFilter.ts @@ -0,0 +1,98 @@ +import { Field, InputType, Int } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class IntNullableFilter { + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + equals?: number | null; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Int], { + nullable: true, + }) + @Type(() => Number) + in?: number[] | null; + + @ApiProperty({ + required: false, + type: [Number], + }) + @IsOptional() + @Field(() => [Int], { + nullable: true, + }) + @Type(() => Number) + notIn?: number[] | null; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + lt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + lte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + gt?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + gte?: number; + + @ApiProperty({ + required: false, + type: Number, + }) + @IsOptional() + @Field(() => Int, { + nullable: true, + }) + @Type(() => Number) + not?: number; +} diff --git a/apps/cloud-provider-connector-server/src/util/JsonFilter.ts b/apps/cloud-provider-connector-server/src/util/JsonFilter.ts new file mode 100644 index 00000000..7040b74f --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/JsonFilter.ts @@ -0,0 +1,31 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { GraphQLJSONObject } from "graphql-type-json"; +import { InputJsonValue } from "../types"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class JsonFilter { + @ApiProperty({ + required: false, + type: GraphQLJSONObject, + }) + @IsOptional() + @Field(() => GraphQLJSONObject, { + nullable: true, + }) + equals?: InputJsonValue; + + @ApiProperty({ + required: false, + type: GraphQLJSONObject, + }) + @IsOptional() + @Field(() => GraphQLJSONObject, { + nullable: true, + }) + not?: InputJsonValue; +} diff --git a/apps/cloud-provider-connector-server/src/util/JsonNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/JsonNullableFilter.ts new file mode 100644 index 00000000..3381d524 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/JsonNullableFilter.ts @@ -0,0 +1,31 @@ +import type { JsonValue } from "type-fest"; +import { Field, InputType } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { GraphQLJSONObject } from "graphql-type-json"; + +@InputType({ + isAbstract: true, + description: undefined, +}) +export class JsonNullableFilter { + @ApiProperty({ + required: false, + type: GraphQLJSONObject, + }) + @IsOptional() + @Field(() => GraphQLJSONObject, { + nullable: true, + }) + equals?: JsonValue; + + @ApiProperty({ + required: false, + type: GraphQLJSONObject, + }) + @IsOptional() + @Field(() => GraphQLJSONObject, { + nullable: true, + }) + not?: JsonValue; +} diff --git a/apps/cloud-provider-connector-server/src/util/MetaQueryPayload.ts b/apps/cloud-provider-connector-server/src/util/MetaQueryPayload.ts new file mode 100644 index 00000000..fc30531c --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/MetaQueryPayload.ts @@ -0,0 +1,13 @@ +import { ObjectType, Field } from "@nestjs/graphql"; +import { ApiProperty } from "@nestjs/swagger"; + +@ObjectType() +class MetaQueryPayload { + @ApiProperty({ + required: true, + type: [Number], + }) + @Field(() => Number) + count!: number; +} +export { MetaQueryPayload }; diff --git a/apps/cloud-provider-connector-server/src/util/QueryMode.ts b/apps/cloud-provider-connector-server/src/util/QueryMode.ts new file mode 100644 index 00000000..f9b1653e --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/QueryMode.ts @@ -0,0 +1,10 @@ +import { registerEnumType } from "@nestjs/graphql"; + +export enum QueryMode { + Default = "default", + Insensitive = "insensitive", +} +registerEnumType(QueryMode, { + name: "QueryMode", + description: undefined, +}); diff --git a/apps/cloud-provider-connector-server/src/util/SortOrder.ts b/apps/cloud-provider-connector-server/src/util/SortOrder.ts new file mode 100644 index 00000000..d4108e69 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/SortOrder.ts @@ -0,0 +1,10 @@ +import { registerEnumType } from "@nestjs/graphql"; + +export enum SortOrder { + Asc = "asc", + Desc = "desc", +} +registerEnumType(SortOrder, { + name: "SortOrder", + description: undefined, +}); diff --git a/apps/cloud-provider-connector-server/src/util/StringFilter.ts b/apps/cloud-provider-connector-server/src/util/StringFilter.ts new file mode 100644 index 00000000..80b573d0 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/StringFilter.ts @@ -0,0 +1,141 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { QueryMode } from "./QueryMode"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, +}) +export class StringFilter { + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + equals?: string; + + @ApiProperty({ + required: false, + type: [String], + }) + @IsOptional() + @Field(() => [String], { + nullable: true, + }) + @Type(() => String) + in?: string[]; + + @ApiProperty({ + required: false, + type: [String], + }) + @IsOptional() + @Field(() => [String], { + nullable: true, + }) + @Type(() => String) + notIn?: string[]; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + lt?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + lte?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + gt?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + gte?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + contains?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + startsWith?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + endsWith?: string; + + @ApiProperty({ + required: false, + enum: ["Default", "Insensitive"], + }) + @IsOptional() + @Field(() => QueryMode, { + nullable: true, + }) + mode?: QueryMode; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + not?: string; +} diff --git a/apps/cloud-provider-connector-server/src/util/StringNullableFilter.ts b/apps/cloud-provider-connector-server/src/util/StringNullableFilter.ts new file mode 100644 index 00000000..01b399cb --- /dev/null +++ b/apps/cloud-provider-connector-server/src/util/StringNullableFilter.ts @@ -0,0 +1,141 @@ +import { Field, InputType } from "@nestjs/graphql"; +import { QueryMode } from "./QueryMode"; +import { ApiProperty } from "@nestjs/swagger"; +import { IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType({ + isAbstract: true, +}) +export class StringNullableFilter { + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + equals?: string | null; + + @ApiProperty({ + required: false, + type: [String], + }) + @IsOptional() + @Field(() => [String], { + nullable: true, + }) + @Type(() => String) + in?: string[] | null; + + @ApiProperty({ + required: false, + type: [String], + }) + @IsOptional() + @Field(() => [String], { + nullable: true, + }) + @Type(() => String) + notIn?: string[] | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + lt?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + lte?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + gt?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + gte?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + contains?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + startsWith?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + endsWith?: string; + + @ApiProperty({ + required: false, + enum: ["Default", "Insensitive"], + }) + @IsOptional() + @Field(() => QueryMode, { + nullable: true, + }) + mode?: QueryMode; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + @Type(() => String) + not?: string; +} diff --git a/apps/cloud-provider-connector-server/src/validators/index.ts b/apps/cloud-provider-connector-server/src/validators/index.ts new file mode 100644 index 00000000..7f62d844 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/validators/index.ts @@ -0,0 +1 @@ +export * from "./is-json-value-validator"; diff --git a/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.spec.ts b/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.spec.ts new file mode 100644 index 00000000..5a778242 --- /dev/null +++ b/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.spec.ts @@ -0,0 +1,44 @@ +import { validate, ValidationError } from "class-validator"; +import { IsJSONValue } from "./is-json-value-validator"; + +class TestClass { + @IsJSONValue() + jsonProperty: unknown; +} + +describe("IsJSONValue", () => { + it("should validate a valid JSON string", async () => { + const testObj = new TestClass(); + testObj.jsonProperty = '{"name": "John", "age": 30}'; + const errors: ValidationError[] = await validate(testObj); + expect(errors.length).toBe(0); + }); + + it("should not validate an invalid JSON string", async () => { + const testObj = new TestClass(); + testObj.jsonProperty = '{name: "John", age: 30}'; + const errors: ValidationError[] = await validate(testObj); + expect(errors.length).toBe(1); + }); + + it("should not validate an invalid JSON string", async () => { + const testObj = new TestClass(); + testObj.jsonProperty = "John"; + const errors: ValidationError[] = await validate(testObj); + expect(errors.length).toBe(1); + }); + + it("should validate a valid JSON object", async () => { + const testObj = new TestClass(); + testObj.jsonProperty = { name: "John", age: 30 }; + const errors: ValidationError[] = await validate(testObj); + expect(errors.length).toBe(0); + }); + + it("should validate a valid JSON array", async () => { + const testObj = new TestClass(); + testObj.jsonProperty = ["John", "30"]; + const errors: ValidationError[] = await validate(testObj); + expect(errors.length).toBe(0); + }); +}); diff --git a/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.ts b/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.ts new file mode 100644 index 00000000..1002540a --- /dev/null +++ b/apps/cloud-provider-connector-server/src/validators/is-json-value-validator.ts @@ -0,0 +1,29 @@ +import { + ValidationArguments, + registerDecorator, + ValidationOptions, +} from "class-validator"; +import isJSONValidator from "validator/lib/isJSON"; + +export function IsJSONValue(validationOptions?: ValidationOptions) { + return function (object: Record<string, any>, propertyName: string) { + registerDecorator({ + name: "IsJSONValue", + target: object.constructor, + propertyName: propertyName, + options: validationOptions, + validator: { + validate(value: any, args: ValidationArguments) { + if (typeof value === "string") { + return isJSONValidator(value); + } + + return isJSONValidator(JSON.stringify(value)); + }, + defaultMessage(args: ValidationArguments): string { + return `${args.property} must be a valid json`; + }, + }, + }); + }; +} diff --git a/apps/cloud-provider-connector-server/tsconfig.build.json b/apps/cloud-provider-connector-server/tsconfig.build.json new file mode 100644 index 00000000..e5794017 --- /dev/null +++ b/apps/cloud-provider-connector-server/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "prisma", "test", "dist", "**/*spec.ts", "admin"] +} diff --git a/apps/cloud-provider-connector-server/tsconfig.json b/apps/cloud-provider-connector-server/tsconfig.json new file mode 100644 index 00000000..707e8cd0 --- /dev/null +++ b/apps/cloud-provider-connector-server/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "module": "commonjs", + "declaration": false, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es2022", + "lib": ["es2023"], + "sourceMap": true, + "outDir": "./dist", + "incremental": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true + }, + "include": ["src"] +}