diff --git a/apps/audit-tracking-service-admin/.dockerignore b/apps/audit-tracking-service-admin/.dockerignore new file mode 100644 index 00000000..1194b4f9 --- /dev/null +++ b/apps/audit-tracking-service-admin/.dockerignore @@ -0,0 +1,7 @@ +.dockerignore +docker-compose.yml +Dockerfile +build/ +node_modules +.env +.gitignore diff --git a/apps/audit-tracking-service-admin/.env b/apps/audit-tracking-service-admin/.env new file mode 100644 index 00000000..e96bc900 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/.gitignore b/apps/audit-tracking-service-admin/.gitignore new file mode 100644 index 00000000..590b2e05 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/Dockerfile b/apps/audit-tracking-service-admin/Dockerfile new file mode 100644 index 00000000..0911e21f --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/README.md b/apps/audit-tracking-service-admin/README.md new file mode 100644 index 00000000..cc7c3873 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/configuration/nginx.conf b/apps/audit-tracking-service-admin/configuration/nginx.conf new file mode 100644 index 00000000..c907b5ce --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/index.html b/apps/audit-tracking-service-admin/index.html new file mode 100644 index 00000000..5336d1e2 --- /dev/null +++ b/apps/audit-tracking-service-admin/index.html @@ -0,0 +1,17 @@ + + + + + + + + + + Audit & Tracking Service + + + +
+ + + diff --git a/apps/audit-tracking-service-admin/package.json b/apps/audit-tracking-service-admin/package.json new file mode 100644 index 00000000..517f3383 --- /dev/null +++ b/apps/audit-tracking-service-admin/package.json @@ -0,0 +1,41 @@ +{ + "name": "@audit-tracking-service/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/audit-tracking-service-admin/public/favicon.ico b/apps/audit-tracking-service-admin/public/favicon.ico new file mode 100644 index 00000000..fcbdcf2d Binary files /dev/null and b/apps/audit-tracking-service-admin/public/favicon.ico differ diff --git a/apps/audit-tracking-service-admin/public/logo192.png b/apps/audit-tracking-service-admin/public/logo192.png new file mode 100644 index 00000000..1918ff2e Binary files /dev/null and b/apps/audit-tracking-service-admin/public/logo192.png differ diff --git a/apps/audit-tracking-service-admin/public/logo512.png b/apps/audit-tracking-service-admin/public/logo512.png new file mode 100644 index 00000000..7e7dc74f Binary files /dev/null and b/apps/audit-tracking-service-admin/public/logo512.png differ diff --git a/apps/audit-tracking-service-admin/public/manifest.json b/apps/audit-tracking-service-admin/public/manifest.json new file mode 100644 index 00000000..ecab61c1 --- /dev/null +++ b/apps/audit-tracking-service-admin/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "Audit & Tracking Service", + "name": "Audit & Tracking Service", + "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/audit-tracking-service-admin/public/robots.txt b/apps/audit-tracking-service-admin/public/robots.txt new file mode 100644 index 00000000..e9e57dc4 --- /dev/null +++ b/apps/audit-tracking-service-admin/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/apps/audit-tracking-service-admin/src/App.scss b/apps/audit-tracking-service-admin/src/App.scss new file mode 100644 index 00000000..4c1cbb06 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/App.tsx b/apps/audit-tracking-service-admin/src/App.tsx new file mode 100644 index 00000000..87825ae9 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/App.tsx @@ -0,0 +1,59 @@ +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 { DeploymentStatusHistoryList } from "./deploymentStatusHistory/DeploymentStatusHistoryList"; +import { DeploymentStatusHistoryCreate } from "./deploymentStatusHistory/DeploymentStatusHistoryCreate"; +import { DeploymentStatusHistoryEdit } from "./deploymentStatusHistory/DeploymentStatusHistoryEdit"; +import { DeploymentStatusHistoryShow } from "./deploymentStatusHistory/DeploymentStatusHistoryShow"; +import { ResourceTagList } from "./resourceTag/ResourceTagList"; +import { ResourceTagCreate } from "./resourceTag/ResourceTagCreate"; +import { ResourceTagEdit } from "./resourceTag/ResourceTagEdit"; +import { ResourceTagShow } from "./resourceTag/ResourceTagShow"; +import { AuditLogList } from "./auditLog/AuditLogList"; +import { AuditLogCreate } from "./auditLog/AuditLogCreate"; +import { AuditLogEdit } from "./auditLog/AuditLogEdit"; +import { AuditLogShow } from "./auditLog/AuditLogShow"; +import { jwtAuthProvider } from "./auth-provider/ra-auth-jwt"; + +const App = (): React.ReactElement => { + return ( +
+ + + + + +
+ ); +}; + +export default App; diff --git a/apps/audit-tracking-service-admin/src/Components/Pagination.tsx b/apps/audit-tracking-service-admin/src/Components/Pagination.tsx new file mode 100644 index 00000000..2de2ebf3 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/Login.tsx b/apps/audit-tracking-service-admin/src/Login.tsx new file mode 100644 index 00000000..dbd6a85b --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/LoginForm.tsx b/apps/audit-tracking-service-admin/src/LoginForm.tsx new file mode 100644 index 00000000..92d48da1 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/api/auditLog/AuditLog.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLog.ts new file mode 100644 index 00000000..1edcee84 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLog.ts @@ -0,0 +1,14 @@ +import { JsonValue } from "type-fest"; + +export type AuditLog = { + action: string | null; + createdAt: Date; + details: JsonValue; + entity: string | null; + entityId: string | null; + id: string; + status: string | null; + timestamp: Date | null; + updatedAt: Date; + userProfile: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCountArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCountArgs.ts new file mode 100644 index 00000000..c61b5df0 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCountArgs.ts @@ -0,0 +1,5 @@ +import { AuditLogWhereInput } from "./AuditLogWhereInput"; + +export type AuditLogCountArgs = { + where?: AuditLogWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCreateInput.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCreateInput.ts new file mode 100644 index 00000000..db70ec7d --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogCreateInput.ts @@ -0,0 +1,11 @@ +import { InputJsonValue } from "../../types"; + +export type AuditLogCreateInput = { + action?: string | null; + details?: InputJsonValue; + entity?: string | null; + entityId?: string | null; + status?: string | null; + timestamp?: Date | null; + userProfile?: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindManyArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindManyArgs.ts new file mode 100644 index 00000000..ec7cdafb --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindManyArgs.ts @@ -0,0 +1,9 @@ +import { AuditLogWhereInput } from "./AuditLogWhereInput"; +import { AuditLogOrderByInput } from "./AuditLogOrderByInput"; + +export type AuditLogFindManyArgs = { + where?: AuditLogWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindUniqueArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindUniqueArgs.ts new file mode 100644 index 00000000..4fbfa919 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; + +export type AuditLogFindUniqueArgs = { + where: AuditLogWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogListRelationFilter.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogListRelationFilter.ts new file mode 100644 index 00000000..29948d21 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogListRelationFilter.ts @@ -0,0 +1,7 @@ +import { AuditLogWhereInput } from "./AuditLogWhereInput"; + +export type AuditLogListRelationFilter = { + every?: AuditLogWhereInput; + some?: AuditLogWhereInput; + none?: AuditLogWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogOrderByInput.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogOrderByInput.ts new file mode 100644 index 00000000..26f06227 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogOrderByInput.ts @@ -0,0 +1,14 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type AuditLogOrderByInput = { + action?: SortOrder; + createdAt?: SortOrder; + details?: SortOrder; + entity?: SortOrder; + entityId?: SortOrder; + id?: SortOrder; + status?: SortOrder; + timestamp?: SortOrder; + updatedAt?: SortOrder; + userProfile?: SortOrder; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogUpdateInput.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogUpdateInput.ts new file mode 100644 index 00000000..de793531 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogUpdateInput.ts @@ -0,0 +1,11 @@ +import { InputJsonValue } from "../../types"; + +export type AuditLogUpdateInput = { + action?: string | null; + details?: InputJsonValue; + entity?: string | null; + entityId?: string | null; + status?: string | null; + timestamp?: Date | null; + userProfile?: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereInput.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereInput.ts new file mode 100644 index 00000000..682d15d5 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereInput.ts @@ -0,0 +1,15 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { JsonFilter } from "../../util/JsonFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +export type AuditLogWhereInput = { + action?: StringNullableFilter; + details?: JsonFilter; + entity?: StringNullableFilter; + entityId?: StringNullableFilter; + id?: StringFilter; + status?: StringNullableFilter; + timestamp?: DateTimeNullableFilter; + userProfile?: StringNullableFilter; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereUniqueInput.ts b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereUniqueInput.ts new file mode 100644 index 00000000..4bf9e67a --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/AuditLogWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type AuditLogWhereUniqueInput = { + id: string; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/CreateAuditLogArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/CreateAuditLogArgs.ts new file mode 100644 index 00000000..aa4c5bd4 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/CreateAuditLogArgs.ts @@ -0,0 +1,5 @@ +import { AuditLogCreateInput } from "./AuditLogCreateInput"; + +export type CreateAuditLogArgs = { + data: AuditLogCreateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/DeleteAuditLogArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/DeleteAuditLogArgs.ts new file mode 100644 index 00000000..a176a22c --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/DeleteAuditLogArgs.ts @@ -0,0 +1,5 @@ +import { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; + +export type DeleteAuditLogArgs = { + where: AuditLogWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/auditLog/UpdateAuditLogArgs.ts b/apps/audit-tracking-service-admin/src/api/auditLog/UpdateAuditLogArgs.ts new file mode 100644 index 00000000..c75649e6 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/auditLog/UpdateAuditLogArgs.ts @@ -0,0 +1,7 @@ +import { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; +import { AuditLogUpdateInput } from "./AuditLogUpdateInput"; + +export type UpdateAuditLogArgs = { + where: AuditLogWhereUniqueInput; + data: AuditLogUpdateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/CreateDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/CreateDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..23a0ec53 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/CreateDeploymentStatusHistoryArgs.ts @@ -0,0 +1,5 @@ +import { DeploymentStatusHistoryCreateInput } from "./DeploymentStatusHistoryCreateInput"; + +export type CreateDeploymentStatusHistoryArgs = { + data: DeploymentStatusHistoryCreateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeleteDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeleteDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..1aaeaa80 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeleteDeploymentStatusHistoryArgs.ts @@ -0,0 +1,5 @@ +import { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; + +export type DeleteDeploymentStatusHistoryArgs = { + where: DeploymentStatusHistoryWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistory.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistory.ts new file mode 100644 index 00000000..cd45d76d --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistory.ts @@ -0,0 +1,9 @@ +export type DeploymentStatusHistory = { + createdAt: Date; + deployment: string | null; + details: string | null; + id: string; + status: string | null; + timestamp: Date | null; + updatedAt: Date; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCountArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCountArgs.ts new file mode 100644 index 00000000..574097ed --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCountArgs.ts @@ -0,0 +1,5 @@ +import { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; + +export type DeploymentStatusHistoryCountArgs = { + where?: DeploymentStatusHistoryWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCreateInput.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCreateInput.ts new file mode 100644 index 00000000..edfc7b9a --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryCreateInput.ts @@ -0,0 +1,6 @@ +export type DeploymentStatusHistoryCreateInput = { + deployment?: string | null; + details?: string | null; + status?: string | null; + timestamp?: Date | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindManyArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindManyArgs.ts new file mode 100644 index 00000000..f17a897c --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindManyArgs.ts @@ -0,0 +1,9 @@ +import { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; +import { DeploymentStatusHistoryOrderByInput } from "./DeploymentStatusHistoryOrderByInput"; + +export type DeploymentStatusHistoryFindManyArgs = { + where?: DeploymentStatusHistoryWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindUniqueArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindUniqueArgs.ts new file mode 100644 index 00000000..c926c7b5 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; + +export type DeploymentStatusHistoryFindUniqueArgs = { + where: DeploymentStatusHistoryWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryListRelationFilter.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryListRelationFilter.ts new file mode 100644 index 00000000..84f70de5 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryListRelationFilter.ts @@ -0,0 +1,7 @@ +import { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; + +export type DeploymentStatusHistoryListRelationFilter = { + every?: DeploymentStatusHistoryWhereInput; + some?: DeploymentStatusHistoryWhereInput; + none?: DeploymentStatusHistoryWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryOrderByInput.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryOrderByInput.ts new file mode 100644 index 00000000..abeeaeba --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryOrderByInput.ts @@ -0,0 +1,11 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type DeploymentStatusHistoryOrderByInput = { + createdAt?: SortOrder; + deployment?: SortOrder; + details?: SortOrder; + id?: SortOrder; + status?: SortOrder; + timestamp?: SortOrder; + updatedAt?: SortOrder; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryUpdateInput.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryUpdateInput.ts new file mode 100644 index 00000000..bef37d13 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryUpdateInput.ts @@ -0,0 +1,6 @@ +export type DeploymentStatusHistoryUpdateInput = { + deployment?: string | null; + details?: string | null; + status?: string | null; + timestamp?: Date | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereInput.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereInput.ts new file mode 100644 index 00000000..b2ba246d --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereInput.ts @@ -0,0 +1,11 @@ +import { StringNullableFilter } from "../../util/StringNullableFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +export type DeploymentStatusHistoryWhereInput = { + deployment?: StringNullableFilter; + details?: StringNullableFilter; + id?: StringFilter; + status?: StringNullableFilter; + timestamp?: DateTimeNullableFilter; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereUniqueInput.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereUniqueInput.ts new file mode 100644 index 00000000..e2ffffaa --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/DeploymentStatusHistoryWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type DeploymentStatusHistoryWhereUniqueInput = { + id: string; +}; diff --git a/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/UpdateDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/UpdateDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..2e576d61 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/deploymentStatusHistory/UpdateDeploymentStatusHistoryArgs.ts @@ -0,0 +1,7 @@ +import { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; +import { DeploymentStatusHistoryUpdateInput } from "./DeploymentStatusHistoryUpdateInput"; + +export type UpdateDeploymentStatusHistoryArgs = { + where: DeploymentStatusHistoryWhereUniqueInput; + data: DeploymentStatusHistoryUpdateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/CreateResourceTagArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/CreateResourceTagArgs.ts new file mode 100644 index 00000000..3ee08a3e --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/CreateResourceTagArgs.ts @@ -0,0 +1,5 @@ +import { ResourceTagCreateInput } from "./ResourceTagCreateInput"; + +export type CreateResourceTagArgs = { + data: ResourceTagCreateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/DeleteResourceTagArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/DeleteResourceTagArgs.ts new file mode 100644 index 00000000..0560cbe6 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/DeleteResourceTagArgs.ts @@ -0,0 +1,5 @@ +import { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; + +export type DeleteResourceTagArgs = { + where: ResourceTagWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTag.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTag.ts new file mode 100644 index 00000000..4c2d3831 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTag.ts @@ -0,0 +1,9 @@ +export type ResourceTag = { + createdAt: Date; + id: string; + key: string | null; + resourceId: string | null; + resourceType: string | null; + updatedAt: Date; + value: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCountArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCountArgs.ts new file mode 100644 index 00000000..30d0e2d5 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCountArgs.ts @@ -0,0 +1,5 @@ +import { ResourceTagWhereInput } from "./ResourceTagWhereInput"; + +export type ResourceTagCountArgs = { + where?: ResourceTagWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCreateInput.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCreateInput.ts new file mode 100644 index 00000000..e5c04b2b --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagCreateInput.ts @@ -0,0 +1,6 @@ +export type ResourceTagCreateInput = { + key?: string | null; + resourceId?: string | null; + resourceType?: string | null; + value?: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindManyArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindManyArgs.ts new file mode 100644 index 00000000..28ac259b --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindManyArgs.ts @@ -0,0 +1,9 @@ +import { ResourceTagWhereInput } from "./ResourceTagWhereInput"; +import { ResourceTagOrderByInput } from "./ResourceTagOrderByInput"; + +export type ResourceTagFindManyArgs = { + where?: ResourceTagWhereInput; + orderBy?: Array; + skip?: number; + take?: number; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindUniqueArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindUniqueArgs.ts new file mode 100644 index 00000000..af5ad922 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagFindUniqueArgs.ts @@ -0,0 +1,5 @@ +import { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; + +export type ResourceTagFindUniqueArgs = { + where: ResourceTagWhereUniqueInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagListRelationFilter.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagListRelationFilter.ts new file mode 100644 index 00000000..4f6f0469 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagListRelationFilter.ts @@ -0,0 +1,7 @@ +import { ResourceTagWhereInput } from "./ResourceTagWhereInput"; + +export type ResourceTagListRelationFilter = { + every?: ResourceTagWhereInput; + some?: ResourceTagWhereInput; + none?: ResourceTagWhereInput; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagOrderByInput.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagOrderByInput.ts new file mode 100644 index 00000000..6041f0e0 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagOrderByInput.ts @@ -0,0 +1,11 @@ +import { SortOrder } from "../../util/SortOrder"; + +export type ResourceTagOrderByInput = { + createdAt?: SortOrder; + id?: SortOrder; + key?: SortOrder; + resourceId?: SortOrder; + resourceType?: SortOrder; + updatedAt?: SortOrder; + value?: SortOrder; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagUpdateInput.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagUpdateInput.ts new file mode 100644 index 00000000..0f2b4b5f --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagUpdateInput.ts @@ -0,0 +1,6 @@ +export type ResourceTagUpdateInput = { + key?: string | null; + resourceId?: string | null; + resourceType?: string | null; + value?: string | null; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereInput.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereInput.ts new file mode 100644 index 00000000..b1126385 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereInput.ts @@ -0,0 +1,10 @@ +import { StringFilter } from "../../util/StringFilter"; +import { StringNullableFilter } from "../../util/StringNullableFilter"; + +export type ResourceTagWhereInput = { + id?: StringFilter; + key?: StringNullableFilter; + resourceId?: StringNullableFilter; + resourceType?: StringNullableFilter; + value?: StringNullableFilter; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereUniqueInput.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereUniqueInput.ts new file mode 100644 index 00000000..1fcfc462 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/ResourceTagWhereUniqueInput.ts @@ -0,0 +1,3 @@ +export type ResourceTagWhereUniqueInput = { + id: string; +}; diff --git a/apps/audit-tracking-service-admin/src/api/resourceTag/UpdateResourceTagArgs.ts b/apps/audit-tracking-service-admin/src/api/resourceTag/UpdateResourceTagArgs.ts new file mode 100644 index 00000000..77b3635d --- /dev/null +++ b/apps/audit-tracking-service-admin/src/api/resourceTag/UpdateResourceTagArgs.ts @@ -0,0 +1,7 @@ +import { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; +import { ResourceTagUpdateInput } from "./ResourceTagUpdateInput"; + +export type UpdateResourceTagArgs = { + where: ResourceTagWhereUniqueInput; + data: ResourceTagUpdateInput; +}; diff --git a/apps/audit-tracking-service-admin/src/auditLog/AuditLogCreate.tsx b/apps/audit-tracking-service-admin/src/auditLog/AuditLogCreate.tsx new file mode 100644 index 00000000..c3d18285 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/auditLog/AuditLogCreate.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Create, + SimpleForm, + CreateProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const AuditLogCreate = (props: CreateProps): React.ReactElement => { + return ( + + + +
+ + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/auditLog/AuditLogEdit.tsx b/apps/audit-tracking-service-admin/src/auditLog/AuditLogEdit.tsx new file mode 100644 index 00000000..7618d6e2 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/auditLog/AuditLogEdit.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Edit, + SimpleForm, + EditProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const AuditLogEdit = (props: EditProps): React.ReactElement => { + return ( + + + +
+ + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/auditLog/AuditLogList.tsx b/apps/audit-tracking-service-admin/src/auditLog/AuditLogList.tsx new file mode 100644 index 00000000..ef1bd2e1 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/auditLog/AuditLogList.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 AuditLogList = (props: ListProps): React.ReactElement => { + return ( + } + > + + + + + + + + + + + {" "} + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/auditLog/AuditLogShow.tsx b/apps/audit-tracking-service-admin/src/auditLog/AuditLogShow.tsx new file mode 100644 index 00000000..d4d1fd01 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/auditLog/AuditLogShow.tsx @@ -0,0 +1,27 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + TextField, + DateField, +} from "react-admin"; + +export const AuditLogShow = (props: ShowProps): React.ReactElement => { + return ( + + + + + + + + + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/auditLog/AuditLogTitle.ts b/apps/audit-tracking-service-admin/src/auditLog/AuditLogTitle.ts new file mode 100644 index 00000000..c256d0b6 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/auditLog/AuditLogTitle.ts @@ -0,0 +1,7 @@ +import { AuditLog as TAuditLog } from "../api/auditLog/AuditLog"; + +export const AUDITLOG_TITLE_FIELD = "action"; + +export const AuditLogTitle = (record: TAuditLog): string => { + return record.action?.toString() || String(record.id); +}; diff --git a/apps/audit-tracking-service-admin/src/auth-provider/ra-auth-http.ts b/apps/audit-tracking-service-admin/src/auth-provider/ra-auth-http.ts new file mode 100644 index 00000000..c6eeba8c --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/auth-provider/ra-auth-jwt.ts b/apps/audit-tracking-service-admin/src/auth-provider/ra-auth-jwt.ts new file mode 100644 index 00000000..c8bcafc0 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/auth.ts b/apps/audit-tracking-service-admin/src/auth.ts new file mode 100644 index 00000000..498b026b --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/constants.ts b/apps/audit-tracking-service-admin/src/constants.ts new file mode 100644 index 00000000..4b3ca4bb --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/data-provider/graphqlDataProvider.ts b/apps/audit-tracking-service-admin/src/data-provider/graphqlDataProvider.ts new file mode 100644 index 00000000..2deee266 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryCreate.tsx b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryCreate.tsx new file mode 100644 index 00000000..fbb313fe --- /dev/null +++ b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryCreate.tsx @@ -0,0 +1,23 @@ +import * as React from "react"; +import { + Create, + SimpleForm, + CreateProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const DeploymentStatusHistoryCreate = ( + props: CreateProps +): React.ReactElement => { + return ( + + + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryEdit.tsx b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryEdit.tsx new file mode 100644 index 00000000..4295fdbb --- /dev/null +++ b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryEdit.tsx @@ -0,0 +1,23 @@ +import * as React from "react"; +import { + Edit, + SimpleForm, + EditProps, + TextInput, + DateTimeInput, +} from "react-admin"; + +export const DeploymentStatusHistoryEdit = ( + props: EditProps +): React.ReactElement => { + return ( + + + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryList.tsx b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryList.tsx new file mode 100644 index 00000000..e2c2c8d0 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryList.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { List, Datagrid, ListProps, DateField, TextField } from "react-admin"; +import Pagination from "../Components/Pagination"; + +export const DeploymentStatusHistoryList = ( + props: ListProps +): React.ReactElement => { + return ( + } + > + + + + + + + + {" "} + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryShow.tsx b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryShow.tsx new file mode 100644 index 00000000..9e085dec --- /dev/null +++ b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryShow.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + DateField, + TextField, +} from "react-admin"; + +export const DeploymentStatusHistoryShow = ( + props: ShowProps +): React.ReactElement => { + return ( + + + + + + + + + + + + ); +}; diff --git a/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryTitle.ts b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryTitle.ts new file mode 100644 index 00000000..bfb4201b --- /dev/null +++ b/apps/audit-tracking-service-admin/src/deploymentStatusHistory/DeploymentStatusHistoryTitle.ts @@ -0,0 +1,9 @@ +import { DeploymentStatusHistory as TDeploymentStatusHistory } from "../api/deploymentStatusHistory/DeploymentStatusHistory"; + +export const DEPLOYMENTSTATUSHISTORY_TITLE_FIELD = "deployment"; + +export const DeploymentStatusHistoryTitle = ( + record: TDeploymentStatusHistory +): string => { + return record.deployment?.toString() || String(record.id); +}; diff --git a/apps/audit-tracking-service-admin/src/index.css b/apps/audit-tracking-service-admin/src/index.css new file mode 100644 index 00000000..86868480 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/index.tsx b/apps/audit-tracking-service-admin/src/index.tsx new file mode 100644 index 00000000..7467839c --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/login.scss b/apps/audit-tracking-service-admin/src/login.scss new file mode 100644 index 00000000..667d8d2b --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/pages/Dashboard.tsx b/apps/audit-tracking-service-admin/src/pages/Dashboard.tsx new file mode 100644 index 00000000..29776bc2 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/reportWebVitals.ts b/apps/audit-tracking-service-admin/src/reportWebVitals.ts new file mode 100644 index 00000000..821a6cde --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/resourceTag/ResourceTagCreate.tsx b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagCreate.tsx new file mode 100644 index 00000000..2498f146 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagCreate.tsx @@ -0,0 +1,15 @@ +import * as React from "react"; +import { Create, SimpleForm, CreateProps, TextInput } from "react-admin"; + +export const ResourceTagCreate = (props: CreateProps): React.ReactElement => { + return ( + <Create {...props}> + <SimpleForm> + <TextInput label="key" source="key" /> + <TextInput label="resourceId" source="resourceId" /> + <TextInput label="resourceType" source="resourceType" /> + <TextInput label="value" source="value" /> + </SimpleForm> + </Create> + ); +}; diff --git a/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagEdit.tsx b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagEdit.tsx new file mode 100644 index 00000000..6ec2c5e7 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagEdit.tsx @@ -0,0 +1,15 @@ +import * as React from "react"; +import { Edit, SimpleForm, EditProps, TextInput } from "react-admin"; + +export const ResourceTagEdit = (props: EditProps): React.ReactElement => { + return ( + <Edit {...props}> + <SimpleForm> + <TextInput label="key" source="key" /> + <TextInput label="resourceId" source="resourceId" /> + <TextInput label="resourceType" source="resourceType" /> + <TextInput label="value" source="value" /> + </SimpleForm> + </Edit> + ); +}; diff --git a/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagList.tsx b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagList.tsx new file mode 100644 index 00000000..60668802 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagList.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 ResourceTagList = (props: ListProps): React.ReactElement => { + return ( + <List + {...props} + title={"ResourceTags"} + perPage={50} + pagination={<Pagination />} + > + <Datagrid rowClick="show" bulkActionButtons={false}> + <DateField source="createdAt" label="Created At" /> + <TextField label="ID" source="id" /> + <TextField label="key" source="key" /> + <TextField label="resourceId" source="resourceId" /> + <TextField label="resourceType" source="resourceType" /> + <DateField source="updatedAt" label="Updated At" /> + <TextField label="value" source="value" />{" "} + </Datagrid> + </List> + ); +}; diff --git a/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagShow.tsx b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagShow.tsx new file mode 100644 index 00000000..12b73680 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagShow.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { + Show, + SimpleShowLayout, + ShowProps, + DateField, + TextField, +} from "react-admin"; + +export const ResourceTagShow = (props: ShowProps): React.ReactElement => { + return ( + <Show {...props}> + <SimpleShowLayout> + <DateField source="createdAt" label="Created At" /> + <TextField label="ID" source="id" /> + <TextField label="key" source="key" /> + <TextField label="resourceId" source="resourceId" /> + <TextField label="resourceType" source="resourceType" /> + <DateField source="updatedAt" label="Updated At" /> + <TextField label="value" source="value" /> + </SimpleShowLayout> + </Show> + ); +}; diff --git a/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagTitle.ts b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagTitle.ts new file mode 100644 index 00000000..40bf86c1 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/resourceTag/ResourceTagTitle.ts @@ -0,0 +1,7 @@ +import { ResourceTag as TResourceTag } from "../api/resourceTag/ResourceTag"; + +export const RESOURCETAG_TITLE_FIELD = "key"; + +export const ResourceTagTitle = (record: TResourceTag): string => { + return record.key?.toString() || String(record.id); +}; diff --git a/apps/audit-tracking-service-admin/src/setupTests.ts b/apps/audit-tracking-service-admin/src/setupTests.ts new file mode 100644 index 00000000..1dd407a6 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/theme/theme.ts b/apps/audit-tracking-service-admin/src/theme/theme.ts new file mode 100644 index 00000000..bcfca0e6 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/types.ts b/apps/audit-tracking-service-admin/src/types.ts new file mode 100644 index 00000000..45a457df --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/user/EnumRoles.ts b/apps/audit-tracking-service-admin/src/user/EnumRoles.ts new file mode 100644 index 00000000..3df7048d --- /dev/null +++ b/apps/audit-tracking-service-admin/src/user/EnumRoles.ts @@ -0,0 +1,3 @@ +export enum EnumRoles { + User = "user", +} diff --git a/apps/audit-tracking-service-admin/src/user/RolesOptions.ts b/apps/audit-tracking-service-admin/src/user/RolesOptions.ts new file mode 100644 index 00000000..5e30fe9a --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/user/roles.ts b/apps/audit-tracking-service-admin/src/user/roles.ts new file mode 100644 index 00000000..732870a1 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/user/roles.ts @@ -0,0 +1,6 @@ +export const ROLES = [ + { + name: "user", + displayName: "User", + }, +]; diff --git a/apps/audit-tracking-service-admin/src/util/BooleanFilter.ts b/apps/audit-tracking-service-admin/src/util/BooleanFilter.ts new file mode 100644 index 00000000..a142d58c --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/BooleanFilter.ts @@ -0,0 +1,4 @@ +export class BooleanFilter { + equals?: boolean; + not?: boolean; +} diff --git a/apps/audit-tracking-service-admin/src/util/BooleanNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/BooleanNullableFilter.ts new file mode 100644 index 00000000..b94aefce --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/BooleanNullableFilter.ts @@ -0,0 +1,4 @@ +export class BooleanNullableFilter { + equals?: boolean | null; + not?: boolean | null; +} diff --git a/apps/audit-tracking-service-admin/src/util/DateTimeFilter.ts b/apps/audit-tracking-service-admin/src/util/DateTimeFilter.ts new file mode 100644 index 00000000..cd8d2139 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/DateTimeNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/DateTimeNullableFilter.ts new file mode 100644 index 00000000..2f9c7b3b --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/FloatFilter.ts b/apps/audit-tracking-service-admin/src/util/FloatFilter.ts new file mode 100644 index 00000000..62aeb145 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/FloatNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/FloatNullableFilter.ts new file mode 100644 index 00000000..d7bb1635 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/IntFilter.ts b/apps/audit-tracking-service-admin/src/util/IntFilter.ts new file mode 100644 index 00000000..3dc02212 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/IntNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/IntNullableFilter.ts new file mode 100644 index 00000000..2107cae8 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/JsonFilter.ts b/apps/audit-tracking-service-admin/src/util/JsonFilter.ts new file mode 100644 index 00000000..cc447632 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/JsonFilter.ts @@ -0,0 +1,5 @@ +import { InputJsonValue } from "../types"; +export class JsonFilter { + equals?: InputJsonValue; + not?: InputJsonValue; +} diff --git a/apps/audit-tracking-service-admin/src/util/JsonNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/JsonNullableFilter.ts new file mode 100644 index 00000000..e6d15066 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/MetaQueryPayload.ts b/apps/audit-tracking-service-admin/src/util/MetaQueryPayload.ts new file mode 100644 index 00000000..bc3175b1 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/MetaQueryPayload.ts @@ -0,0 +1,3 @@ +export class MetaQueryPayload { + count!: number; +} diff --git a/apps/audit-tracking-service-admin/src/util/QueryMode.ts b/apps/audit-tracking-service-admin/src/util/QueryMode.ts new file mode 100644 index 00000000..8a2164e0 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/QueryMode.ts @@ -0,0 +1,4 @@ +export enum QueryMode { + Default = "default", + Insensitive = "insensitive", +} diff --git a/apps/audit-tracking-service-admin/src/util/SortOrder.ts b/apps/audit-tracking-service-admin/src/util/SortOrder.ts new file mode 100644 index 00000000..a5bcdb67 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/util/SortOrder.ts @@ -0,0 +1,4 @@ +export enum SortOrder { + Asc = "asc", + Desc = "desc", +} diff --git a/apps/audit-tracking-service-admin/src/util/StringFilter.ts b/apps/audit-tracking-service-admin/src/util/StringFilter.ts new file mode 100644 index 00000000..c2e26c5d --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/util/StringNullableFilter.ts b/apps/audit-tracking-service-admin/src/util/StringNullableFilter.ts new file mode 100644 index 00000000..e1e37ec3 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/src/vite-env.d.ts b/apps/audit-tracking-service-admin/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/apps/audit-tracking-service-admin/src/vite-env.d.ts @@ -0,0 +1 @@ +/// <reference types="vite/client" /> diff --git a/apps/audit-tracking-service-admin/tsconfig.json b/apps/audit-tracking-service-admin/tsconfig.json new file mode 100644 index 00000000..31cc7800 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-admin/vite.config.ts b/apps/audit-tracking-service-admin/vite.config.ts new file mode 100644 index 00000000..cf64d08c --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/.dockerignore b/apps/audit-tracking-service-server/.dockerignore new file mode 100644 index 00000000..cb5c30bb --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/.env b/apps/audit-tracking-service-server/.env new file mode 100644 index 00000000..bf73b955 --- /dev/null +++ b/apps/audit-tracking-service-server/.env @@ -0,0 +1,8 @@ +BCRYPT_SALT=10 +COMPOSE_PROJECT_NAME=amp_cmb5pom4f0tfqjwsi4db7dbcd +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/audit-tracking-service-server/.gitignore b/apps/audit-tracking-service-server/.gitignore new file mode 100644 index 00000000..08c9980f --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/.prettierignore b/apps/audit-tracking-service-server/.prettierignore new file mode 100644 index 00000000..e48f3559 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/Dockerfile b/apps/audit-tracking-service-server/Dockerfile new file mode 100644 index 00000000..80dd8d37 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/README.md b/apps/audit-tracking-service-server/README.md new file mode 100644 index 00000000..bca0445d --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/docker-compose.dev.yml b/apps/audit-tracking-service-server/docker-compose.dev.yml new file mode 100644 index 00000000..8d7c3589 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/docker-compose.yml b/apps/audit-tracking-service-server/docker-compose.yml new file mode 100644 index 00000000..ef3a7a5f --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/nest-cli.json b/apps/audit-tracking-service-server/nest-cli.json new file mode 100644 index 00000000..b7b60ae9 --- /dev/null +++ b/apps/audit-tracking-service-server/nest-cli.json @@ -0,0 +1,10 @@ +{ + "sourceRoot": "src", + "compilerOptions": { + "assets": [ + { + "include": "swagger/**/*" + } + ] + } +} diff --git a/apps/audit-tracking-service-server/package.json b/apps/audit-tracking-service-server/package.json new file mode 100644 index 00000000..f56c178f --- /dev/null +++ b/apps/audit-tracking-service-server/package.json @@ -0,0 +1,76 @@ +{ + "name": "@audit-tracking-service/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/audit-tracking-service-server/prisma/schema.prisma b/apps/audit-tracking-service-server/prisma/schema.prisma new file mode 100644 index 00000000..b4b543ce --- /dev/null +++ b/apps/audit-tracking-service-server/prisma/schema.prisma @@ -0,0 +1,41 @@ +datasource db { + provider = "postgresql" + url = env("DB_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model DeploymentStatusHistory { + createdAt DateTime @default(now()) + deployment String? + details String? + id String @id @default(cuid()) + status String? + timestamp DateTime? + updatedAt DateTime @updatedAt +} + +model ResourceTag { + createdAt DateTime @default(now()) + id String @id @default(cuid()) + key String? + resourceId String? + resourceType String? + updatedAt DateTime @updatedAt + value String? +} + +model AuditLog { + action String? + createdAt DateTime @default(now()) + details Json? + entity String? + entityId String? + id String @id @default(cuid()) + status String? + timestamp DateTime? + updatedAt DateTime @updatedAt + userProfile String? +} diff --git a/apps/audit-tracking-service-server/scripts/customSeed.ts b/apps/audit-tracking-service-server/scripts/customSeed.ts new file mode 100644 index 00000000..26ccaf4c --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/scripts/seed.ts b/apps/audit-tracking-service-server/scripts/seed.ts new file mode 100644 index 00000000..04cee655 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/app.module.ts b/apps/audit-tracking-service-server/src/app.module.ts new file mode 100644 index 00000000..d27b4f20 --- /dev/null +++ b/apps/audit-tracking-service-server/src/app.module.ts @@ -0,0 +1,45 @@ +import { Module } from "@nestjs/common"; +import { DeploymentStatusHistoryModule } from "./deploymentStatusHistory/deploymentStatusHistory.module"; +import { ResourceTagModule } from "./resourceTag/resourceTag.module"; +import { AuditLogModule } from "./auditLog/auditLog.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: [ + DeploymentStatusHistoryModule, + ResourceTagModule, + AuditLogModule, + 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/audit-tracking-service-server/src/auditLog/auditLog.controller.ts b/apps/audit-tracking-service-server/src/auditLog/auditLog.controller.ts new file mode 100644 index 00000000..9935b005 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/auditLog.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { AuditLogService } from "./auditLog.service"; +import { AuditLogControllerBase } from "./base/auditLog.controller.base"; + +@swagger.ApiTags("auditLogs") +@common.Controller("auditLogs") +export class AuditLogController extends AuditLogControllerBase { + constructor(protected readonly service: AuditLogService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/auditLog/auditLog.module.ts b/apps/audit-tracking-service-server/src/auditLog/auditLog.module.ts new file mode 100644 index 00000000..d0beced5 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/auditLog.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { AuditLogModuleBase } from "./base/auditLog.module.base"; +import { AuditLogService } from "./auditLog.service"; +import { AuditLogController } from "./auditLog.controller"; +import { AuditLogResolver } from "./auditLog.resolver"; + +@Module({ + imports: [AuditLogModuleBase], + controllers: [AuditLogController], + providers: [AuditLogService, AuditLogResolver], + exports: [AuditLogService], +}) +export class AuditLogModule {} diff --git a/apps/audit-tracking-service-server/src/auditLog/auditLog.resolver.ts b/apps/audit-tracking-service-server/src/auditLog/auditLog.resolver.ts new file mode 100644 index 00000000..367124a0 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/auditLog.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { AuditLogResolverBase } from "./base/auditLog.resolver.base"; +import { AuditLog } from "./base/AuditLog"; +import { AuditLogService } from "./auditLog.service"; + +@graphql.Resolver(() => AuditLog) +export class AuditLogResolver extends AuditLogResolverBase { + constructor(protected readonly service: AuditLogService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/auditLog/auditLog.service.ts b/apps/audit-tracking-service-server/src/auditLog/auditLog.service.ts new file mode 100644 index 00000000..c67f3661 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/auditLog.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { AuditLogServiceBase } from "./base/auditLog.service.base"; + +@Injectable() +export class AuditLogService extends AuditLogServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLog.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLog.ts new file mode 100644 index 00000000..a6585da9 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLog.ts @@ -0,0 +1,128 @@ +/* +------------------------------------------------------------------------------ +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 AuditLog { + @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: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + details!: JsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entity!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entityId!: string | null; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @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 { AuditLog as AuditLog }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCountArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCountArgs.ts new file mode 100644 index 00000000..66f0b081 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCountArgs.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 { AuditLogWhereInput } from "./AuditLogWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class AuditLogCountArgs { + @ApiProperty({ + required: false, + type: () => AuditLogWhereInput, + }) + @Field(() => AuditLogWhereInput, { nullable: true }) + @Type(() => AuditLogWhereInput) + where?: AuditLogWhereInput; +} + +export { AuditLogCountArgs as AuditLogCountArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCreateInput.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCreateInput.ts new file mode 100644 index 00000000..a904b8d3 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogCreateInput.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 { 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 AuditLogCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + action?: string | null; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + details?: InputJsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entity?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entityId?: string | null; + + @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 { AuditLogCreateInput as AuditLogCreateInput }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindManyArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindManyArgs.ts new file mode 100644 index 00000000..ccd5ed7b --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindManyArgs.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 { AuditLogWhereInput } from "./AuditLogWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { AuditLogOrderByInput } from "./AuditLogOrderByInput"; + +@ArgsType() +class AuditLogFindManyArgs { + @ApiProperty({ + required: false, + type: () => AuditLogWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => AuditLogWhereInput, { nullable: true }) + @Type(() => AuditLogWhereInput) + where?: AuditLogWhereInput; + + @ApiProperty({ + required: false, + type: [AuditLogOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [AuditLogOrderByInput], { nullable: true }) + @Type(() => AuditLogOrderByInput) + orderBy?: Array<AuditLogOrderByInput>; + + @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 { AuditLogFindManyArgs as AuditLogFindManyArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindUniqueArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindUniqueArgs.ts new file mode 100644 index 00000000..8bd54cc1 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogFindUniqueArgs.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 { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class AuditLogFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => AuditLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereUniqueInput) + @Field(() => AuditLogWhereUniqueInput, { nullable: false }) + where!: AuditLogWhereUniqueInput; +} + +export { AuditLogFindUniqueArgs as AuditLogFindUniqueArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogListRelationFilter.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogListRelationFilter.ts new file mode 100644 index 00000000..ee6cefba --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogListRelationFilter.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 { AuditLogWhereInput } from "./AuditLogWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class AuditLogListRelationFilter { + @ApiProperty({ + required: false, + type: () => AuditLogWhereInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereInput) + @IsOptional() + @Field(() => AuditLogWhereInput, { + nullable: true, + }) + every?: AuditLogWhereInput; + + @ApiProperty({ + required: false, + type: () => AuditLogWhereInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereInput) + @IsOptional() + @Field(() => AuditLogWhereInput, { + nullable: true, + }) + some?: AuditLogWhereInput; + + @ApiProperty({ + required: false, + type: () => AuditLogWhereInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereInput) + @IsOptional() + @Field(() => AuditLogWhereInput, { + nullable: true, + }) + none?: AuditLogWhereInput; +} +export { AuditLogListRelationFilter as AuditLogListRelationFilter }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogOrderByInput.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogOrderByInput.ts new file mode 100644 index 00000000..3d434dfc --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogOrderByInput.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 AuditLogOrderByInput { + @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, + }) + details?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + entity?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + entityId?: 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, + }) + 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 { AuditLogOrderByInput as AuditLogOrderByInput }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogUpdateInput.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogUpdateInput.ts new file mode 100644 index 00000000..6e95007d --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogUpdateInput.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 { 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 AuditLogUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + action?: string | null; + + @ApiProperty({ + required: false, + }) + @IsJSONValue() + @IsOptional() + @Field(() => GraphQLJSON, { + nullable: true, + }) + details?: InputJsonValue; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entity?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + entityId?: string | null; + + @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 { AuditLogUpdateInput as AuditLogUpdateInput }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereInput.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereInput.ts new file mode 100644 index 00000000..e1a079fa --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereInput.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 { JsonFilter } from "../../util/JsonFilter"; +import { StringFilter } from "../../util/StringFilter"; +import { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +@InputType() +class AuditLogWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + action?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: JsonFilter, + }) + @Type(() => JsonFilter) + @IsOptional() + @Field(() => JsonFilter, { + nullable: true, + }) + details?: JsonFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + entity?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + entityId?: 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, + }) + 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 { AuditLogWhereInput as AuditLogWhereInput }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereUniqueInput.ts b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereUniqueInput.ts new file mode 100644 index 00000000..bf6d98ef --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/AuditLogWhereUniqueInput.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 AuditLogWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { AuditLogWhereUniqueInput as AuditLogWhereUniqueInput }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/CreateAuditLogArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/CreateAuditLogArgs.ts new file mode 100644 index 00000000..3736a045 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/CreateAuditLogArgs.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 { AuditLogCreateInput } from "./AuditLogCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateAuditLogArgs { + @ApiProperty({ + required: true, + type: () => AuditLogCreateInput, + }) + @ValidateNested() + @Type(() => AuditLogCreateInput) + @Field(() => AuditLogCreateInput, { nullable: false }) + data!: AuditLogCreateInput; +} + +export { CreateAuditLogArgs as CreateAuditLogArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/DeleteAuditLogArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/DeleteAuditLogArgs.ts new file mode 100644 index 00000000..35567873 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/DeleteAuditLogArgs.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 { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteAuditLogArgs { + @ApiProperty({ + required: true, + type: () => AuditLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereUniqueInput) + @Field(() => AuditLogWhereUniqueInput, { nullable: false }) + where!: AuditLogWhereUniqueInput; +} + +export { DeleteAuditLogArgs as DeleteAuditLogArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/UpdateAuditLogArgs.ts b/apps/audit-tracking-service-server/src/auditLog/base/UpdateAuditLogArgs.ts new file mode 100644 index 00000000..9503f2c2 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/UpdateAuditLogArgs.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 { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { AuditLogUpdateInput } from "./AuditLogUpdateInput"; + +@ArgsType() +class UpdateAuditLogArgs { + @ApiProperty({ + required: true, + type: () => AuditLogWhereUniqueInput, + }) + @ValidateNested() + @Type(() => AuditLogWhereUniqueInput) + @Field(() => AuditLogWhereUniqueInput, { nullable: false }) + where!: AuditLogWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => AuditLogUpdateInput, + }) + @ValidateNested() + @Type(() => AuditLogUpdateInput) + @Field(() => AuditLogUpdateInput, { nullable: false }) + data!: AuditLogUpdateInput; +} + +export { UpdateAuditLogArgs as UpdateAuditLogArgs }; diff --git a/apps/audit-tracking-service-server/src/auditLog/base/auditLog.controller.base.spec.ts b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.controller.base.spec.ts new file mode 100644 index 00000000..eabc30fa --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.controller.base.spec.ts @@ -0,0 +1,218 @@ +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 { AuditLogController } from "../auditLog.controller"; +import { AuditLogService } from "../auditLog.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + action: "exampleAction", + createdAt: new Date(), + entity: "exampleEntity", + entityId: "exampleEntityId", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const CREATE_RESULT = { + action: "exampleAction", + createdAt: new Date(), + entity: "exampleEntity", + entityId: "exampleEntityId", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; +const FIND_MANY_RESULT = [ + { + action: "exampleAction", + createdAt: new Date(), + entity: "exampleEntity", + entityId: "exampleEntityId", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", + }, +]; +const FIND_ONE_RESULT = { + action: "exampleAction", + createdAt: new Date(), + entity: "exampleEntity", + entityId: "exampleEntityId", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + userProfile: "exampleUserProfile", +}; + +const service = { + createAuditLog() { + return CREATE_RESULT; + }, + auditLogs: () => FIND_MANY_RESULT, + auditLog: ({ 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("AuditLog", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: AuditLogService, + useValue: service, + }, + ], + controllers: [AuditLogController], + 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 /auditLogs", async () => { + await request(app.getHttpServer()) + .post("/auditLogs") + .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 /auditLogs", async () => { + await request(app.getHttpServer()) + .get("/auditLogs") + .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 /auditLogs/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/auditLogs"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /auditLogs/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/auditLogs"}/${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 /auditLogs existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/auditLogs") + .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("/auditLogs") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/audit-tracking-service-server/src/auditLog/base/auditLog.controller.base.ts b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.controller.base.ts new file mode 100644 index 00000000..42623398 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.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 { AuditLogService } from "../auditLog.service"; +import { AuditLogCreateInput } from "./AuditLogCreateInput"; +import { AuditLog } from "./AuditLog"; +import { AuditLogFindManyArgs } from "./AuditLogFindManyArgs"; +import { AuditLogWhereUniqueInput } from "./AuditLogWhereUniqueInput"; +import { AuditLogUpdateInput } from "./AuditLogUpdateInput"; + +export class AuditLogControllerBase { + constructor(protected readonly service: AuditLogService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: AuditLog }) + async createAuditLog( + @common.Body() data: AuditLogCreateInput + ): Promise<AuditLog> { + return await this.service.createAuditLog({ + data: data, + select: { + action: true, + createdAt: true, + details: true, + entity: true, + entityId: true, + id: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [AuditLog] }) + @ApiNestedQuery(AuditLogFindManyArgs) + async auditLogs(@common.Req() request: Request): Promise<AuditLog[]> { + const args = plainToClass(AuditLogFindManyArgs, request.query); + return this.service.auditLogs({ + ...args, + select: { + action: true, + createdAt: true, + details: true, + entity: true, + entityId: true, + id: true, + status: true, + timestamp: true, + updatedAt: true, + userProfile: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: AuditLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async auditLog( + @common.Param() params: AuditLogWhereUniqueInput + ): Promise<AuditLog | null> { + const result = await this.service.auditLog({ + where: params, + select: { + action: true, + createdAt: true, + details: true, + entity: true, + entityId: true, + id: 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: AuditLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateAuditLog( + @common.Param() params: AuditLogWhereUniqueInput, + @common.Body() data: AuditLogUpdateInput + ): Promise<AuditLog | null> { + try { + return await this.service.updateAuditLog({ + where: params, + data: data, + select: { + action: true, + createdAt: true, + details: true, + entity: true, + entityId: true, + id: 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: AuditLog }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteAuditLog( + @common.Param() params: AuditLogWhereUniqueInput + ): Promise<AuditLog | null> { + try { + return await this.service.deleteAuditLog({ + where: params, + select: { + action: true, + createdAt: true, + details: true, + entity: true, + entityId: true, + id: 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/audit-tracking-service-server/src/auditLog/base/auditLog.module.base.ts b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.module.base.ts new file mode 100644 index 00000000..4e40287e --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.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 AuditLogModuleBase {} diff --git a/apps/audit-tracking-service-server/src/auditLog/base/auditLog.resolver.base.ts b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.resolver.base.ts new file mode 100644 index 00000000..6849e020 --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.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 { AuditLog } from "./AuditLog"; +import { AuditLogCountArgs } from "./AuditLogCountArgs"; +import { AuditLogFindManyArgs } from "./AuditLogFindManyArgs"; +import { AuditLogFindUniqueArgs } from "./AuditLogFindUniqueArgs"; +import { CreateAuditLogArgs } from "./CreateAuditLogArgs"; +import { UpdateAuditLogArgs } from "./UpdateAuditLogArgs"; +import { DeleteAuditLogArgs } from "./DeleteAuditLogArgs"; +import { AuditLogService } from "../auditLog.service"; +@graphql.Resolver(() => AuditLog) +export class AuditLogResolverBase { + constructor(protected readonly service: AuditLogService) {} + + async _auditLogsMeta( + @graphql.Args() args: AuditLogCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [AuditLog]) + async auditLogs( + @graphql.Args() args: AuditLogFindManyArgs + ): Promise<AuditLog[]> { + return this.service.auditLogs(args); + } + + @graphql.Query(() => AuditLog, { nullable: true }) + async auditLog( + @graphql.Args() args: AuditLogFindUniqueArgs + ): Promise<AuditLog | null> { + const result = await this.service.auditLog(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => AuditLog) + async createAuditLog( + @graphql.Args() args: CreateAuditLogArgs + ): Promise<AuditLog> { + return await this.service.createAuditLog({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => AuditLog) + async updateAuditLog( + @graphql.Args() args: UpdateAuditLogArgs + ): Promise<AuditLog | null> { + try { + return await this.service.updateAuditLog({ + ...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(() => AuditLog) + async deleteAuditLog( + @graphql.Args() args: DeleteAuditLogArgs + ): Promise<AuditLog | null> { + try { + return await this.service.deleteAuditLog(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/audit-tracking-service-server/src/auditLog/base/auditLog.service.base.ts b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.service.base.ts new file mode 100644 index 00000000..9cf414df --- /dev/null +++ b/apps/audit-tracking-service-server/src/auditLog/base/auditLog.service.base.ts @@ -0,0 +1,47 @@ +/* +------------------------------------------------------------------------------ +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, AuditLog as PrismaAuditLog } from "@prisma/client"; + +export class AuditLogServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count(args: Omit<Prisma.AuditLogCountArgs, "select">): Promise<number> { + return this.prisma.auditLog.count(args); + } + + async auditLogs( + args: Prisma.AuditLogFindManyArgs + ): Promise<PrismaAuditLog[]> { + return this.prisma.auditLog.findMany(args); + } + async auditLog( + args: Prisma.AuditLogFindUniqueArgs + ): Promise<PrismaAuditLog | null> { + return this.prisma.auditLog.findUnique(args); + } + async createAuditLog( + args: Prisma.AuditLogCreateArgs + ): Promise<PrismaAuditLog> { + return this.prisma.auditLog.create(args); + } + async updateAuditLog( + args: Prisma.AuditLogUpdateArgs + ): Promise<PrismaAuditLog> { + return this.prisma.auditLog.update(args); + } + async deleteAuditLog( + args: Prisma.AuditLogDeleteArgs + ): Promise<PrismaAuditLog> { + return this.prisma.auditLog.delete(args); + } +} diff --git a/apps/audit-tracking-service-server/src/connectMicroservices.ts b/apps/audit-tracking-service-server/src/connectMicroservices.ts new file mode 100644 index 00000000..068fa5f0 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/decorators/api-nested-query.decorator.ts b/apps/audit-tracking-service-server/src/decorators/api-nested-query.decorator.ts new file mode 100644 index 00000000..9fd5ba30 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/decorators/public.decorator.ts b/apps/audit-tracking-service-server/src/decorators/public.decorator.ts new file mode 100644 index 00000000..9eab4e06 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/deploymentStatusHistory/base/CreateDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/CreateDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..979ff26a --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/CreateDeploymentStatusHistoryArgs.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 { DeploymentStatusHistoryCreateInput } from "./DeploymentStatusHistoryCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateDeploymentStatusHistoryArgs { + @ApiProperty({ + required: true, + type: () => DeploymentStatusHistoryCreateInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryCreateInput) + @Field(() => DeploymentStatusHistoryCreateInput, { nullable: false }) + data!: DeploymentStatusHistoryCreateInput; +} + +export { CreateDeploymentStatusHistoryArgs as CreateDeploymentStatusHistoryArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeleteDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeleteDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..4304b789 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeleteDeploymentStatusHistoryArgs.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 { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteDeploymentStatusHistoryArgs { + @ApiProperty({ + required: true, + type: () => DeploymentStatusHistoryWhereUniqueInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereUniqueInput) + @Field(() => DeploymentStatusHistoryWhereUniqueInput, { nullable: false }) + where!: DeploymentStatusHistoryWhereUniqueInput; +} + +export { DeleteDeploymentStatusHistoryArgs as DeleteDeploymentStatusHistoryArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistory.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistory.ts new file mode 100644 index 00000000..311c23c7 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistory.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 { 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 DeploymentStatusHistory { + @ApiProperty({ + required: true, + }) + @IsDate() + @Type(() => Date) + @Field(() => Date) + createdAt!: Date; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + deployment!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + details!: string | null; + + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; + + @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; +} + +export { DeploymentStatusHistory as DeploymentStatusHistory }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCountArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCountArgs.ts new file mode 100644 index 00000000..7fc694bd --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCountArgs.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 { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeploymentStatusHistoryCountArgs { + @ApiProperty({ + required: false, + type: () => DeploymentStatusHistoryWhereInput, + }) + @Field(() => DeploymentStatusHistoryWhereInput, { nullable: true }) + @Type(() => DeploymentStatusHistoryWhereInput) + where?: DeploymentStatusHistoryWhereInput; +} + +export { DeploymentStatusHistoryCountArgs as DeploymentStatusHistoryCountArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCreateInput.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCreateInput.ts new file mode 100644 index 00000000..99149ac4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryCreateInput.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, IsDate } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class DeploymentStatusHistoryCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + deployment?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + details?: string | null; + + @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; +} + +export { DeploymentStatusHistoryCreateInput as DeploymentStatusHistoryCreateInput }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindManyArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindManyArgs.ts new file mode 100644 index 00000000..6cb07474 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindManyArgs.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 { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { DeploymentStatusHistoryOrderByInput } from "./DeploymentStatusHistoryOrderByInput"; + +@ArgsType() +class DeploymentStatusHistoryFindManyArgs { + @ApiProperty({ + required: false, + type: () => DeploymentStatusHistoryWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => DeploymentStatusHistoryWhereInput, { nullable: true }) + @Type(() => DeploymentStatusHistoryWhereInput) + where?: DeploymentStatusHistoryWhereInput; + + @ApiProperty({ + required: false, + type: [DeploymentStatusHistoryOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [DeploymentStatusHistoryOrderByInput], { nullable: true }) + @Type(() => DeploymentStatusHistoryOrderByInput) + orderBy?: Array<DeploymentStatusHistoryOrderByInput>; + + @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 { DeploymentStatusHistoryFindManyArgs as DeploymentStatusHistoryFindManyArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindUniqueArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindUniqueArgs.ts new file mode 100644 index 00000000..4a14502c --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryFindUniqueArgs.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 { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeploymentStatusHistoryFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => DeploymentStatusHistoryWhereUniqueInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereUniqueInput) + @Field(() => DeploymentStatusHistoryWhereUniqueInput, { nullable: false }) + where!: DeploymentStatusHistoryWhereUniqueInput; +} + +export { DeploymentStatusHistoryFindUniqueArgs as DeploymentStatusHistoryFindUniqueArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryListRelationFilter.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryListRelationFilter.ts new file mode 100644 index 00000000..9d57b0f6 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryListRelationFilter.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 { DeploymentStatusHistoryWhereInput } from "./DeploymentStatusHistoryWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class DeploymentStatusHistoryListRelationFilter { + @ApiProperty({ + required: false, + type: () => DeploymentStatusHistoryWhereInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereInput) + @IsOptional() + @Field(() => DeploymentStatusHistoryWhereInput, { + nullable: true, + }) + every?: DeploymentStatusHistoryWhereInput; + + @ApiProperty({ + required: false, + type: () => DeploymentStatusHistoryWhereInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereInput) + @IsOptional() + @Field(() => DeploymentStatusHistoryWhereInput, { + nullable: true, + }) + some?: DeploymentStatusHistoryWhereInput; + + @ApiProperty({ + required: false, + type: () => DeploymentStatusHistoryWhereInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereInput) + @IsOptional() + @Field(() => DeploymentStatusHistoryWhereInput, { + nullable: true, + }) + none?: DeploymentStatusHistoryWhereInput; +} +export { DeploymentStatusHistoryListRelationFilter as DeploymentStatusHistoryListRelationFilter }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryOrderByInput.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryOrderByInput.ts new file mode 100644 index 00000000..d41d158e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryOrderByInput.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 DeploymentStatusHistoryOrderByInput { + @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, + }) + deployment?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + details?: 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, + }) + 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; +} + +export { DeploymentStatusHistoryOrderByInput as DeploymentStatusHistoryOrderByInput }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryUpdateInput.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryUpdateInput.ts new file mode 100644 index 00000000..f2d952e7 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryUpdateInput.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, IsDate } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class DeploymentStatusHistoryUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + deployment?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + details?: string | null; + + @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; +} + +export { DeploymentStatusHistoryUpdateInput as DeploymentStatusHistoryUpdateInput }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereInput.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereInput.ts new file mode 100644 index 00000000..b23dec5e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereInput.ts @@ -0,0 +1,78 @@ +/* +------------------------------------------------------------------------------ +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 { DateTimeNullableFilter } from "../../util/DateTimeNullableFilter"; + +@InputType() +class DeploymentStatusHistoryWhereInput { + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + deployment?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + details?: 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, + }) + status?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: DateTimeNullableFilter, + }) + @Type(() => DateTimeNullableFilter) + @IsOptional() + @Field(() => DateTimeNullableFilter, { + nullable: true, + }) + timestamp?: DateTimeNullableFilter; +} + +export { DeploymentStatusHistoryWhereInput as DeploymentStatusHistoryWhereInput }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereUniqueInput.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereUniqueInput.ts new file mode 100644 index 00000000..cdf51874 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/DeploymentStatusHistoryWhereUniqueInput.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 DeploymentStatusHistoryWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { DeploymentStatusHistoryWhereUniqueInput as DeploymentStatusHistoryWhereUniqueInput }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/UpdateDeploymentStatusHistoryArgs.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/UpdateDeploymentStatusHistoryArgs.ts new file mode 100644 index 00000000..c1258d21 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/UpdateDeploymentStatusHistoryArgs.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 { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { DeploymentStatusHistoryUpdateInput } from "./DeploymentStatusHistoryUpdateInput"; + +@ArgsType() +class UpdateDeploymentStatusHistoryArgs { + @ApiProperty({ + required: true, + type: () => DeploymentStatusHistoryWhereUniqueInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryWhereUniqueInput) + @Field(() => DeploymentStatusHistoryWhereUniqueInput, { nullable: false }) + where!: DeploymentStatusHistoryWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => DeploymentStatusHistoryUpdateInput, + }) + @ValidateNested() + @Type(() => DeploymentStatusHistoryUpdateInput) + @Field(() => DeploymentStatusHistoryUpdateInput, { nullable: false }) + data!: DeploymentStatusHistoryUpdateInput; +} + +export { UpdateDeploymentStatusHistoryArgs as UpdateDeploymentStatusHistoryArgs }; diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.controller.base.spec.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.controller.base.spec.ts new file mode 100644 index 00000000..410541e5 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.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 { DeploymentStatusHistoryController } from "../deploymentStatusHistory.controller"; +import { DeploymentStatusHistoryService } from "../deploymentStatusHistory.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + createdAt: new Date(), + deployment: "exampleDeployment", + details: "exampleDetails", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), +}; +const CREATE_RESULT = { + createdAt: new Date(), + deployment: "exampleDeployment", + details: "exampleDetails", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), +}; +const FIND_MANY_RESULT = [ + { + createdAt: new Date(), + deployment: "exampleDeployment", + details: "exampleDetails", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), + }, +]; +const FIND_ONE_RESULT = { + createdAt: new Date(), + deployment: "exampleDeployment", + details: "exampleDetails", + id: "exampleId", + status: "exampleStatus", + timestamp: new Date(), + updatedAt: new Date(), +}; + +const service = { + createDeploymentStatusHistory() { + return CREATE_RESULT; + }, + deploymentStatusHistories: () => FIND_MANY_RESULT, + deploymentStatusHistory: ({ 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("DeploymentStatusHistory", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: DeploymentStatusHistoryService, + useValue: service, + }, + ], + controllers: [DeploymentStatusHistoryController], + 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 /deploymentStatusHistories", async () => { + await request(app.getHttpServer()) + .post("/deploymentStatusHistories") + .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 /deploymentStatusHistories", async () => { + await request(app.getHttpServer()) + .get("/deploymentStatusHistories") + .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 /deploymentStatusHistories/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/deploymentStatusHistories"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /deploymentStatusHistories/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/deploymentStatusHistories"}/${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 /deploymentStatusHistories existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/deploymentStatusHistories") + .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("/deploymentStatusHistories") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.controller.base.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.controller.base.ts new file mode 100644 index 00000000..95037c34 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.controller.base.ts @@ -0,0 +1,156 @@ +/* +------------------------------------------------------------------------------ +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 { DeploymentStatusHistoryService } from "../deploymentStatusHistory.service"; +import { DeploymentStatusHistoryCreateInput } from "./DeploymentStatusHistoryCreateInput"; +import { DeploymentStatusHistory } from "./DeploymentStatusHistory"; +import { DeploymentStatusHistoryFindManyArgs } from "./DeploymentStatusHistoryFindManyArgs"; +import { DeploymentStatusHistoryWhereUniqueInput } from "./DeploymentStatusHistoryWhereUniqueInput"; +import { DeploymentStatusHistoryUpdateInput } from "./DeploymentStatusHistoryUpdateInput"; + +export class DeploymentStatusHistoryControllerBase { + constructor(protected readonly service: DeploymentStatusHistoryService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: DeploymentStatusHistory }) + async createDeploymentStatusHistory( + @common.Body() data: DeploymentStatusHistoryCreateInput + ): Promise<DeploymentStatusHistory> { + return await this.service.createDeploymentStatusHistory({ + data: data, + select: { + createdAt: true, + deployment: true, + details: true, + id: true, + status: true, + timestamp: true, + updatedAt: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [DeploymentStatusHistory] }) + @ApiNestedQuery(DeploymentStatusHistoryFindManyArgs) + async deploymentStatusHistories( + @common.Req() request: Request + ): Promise<DeploymentStatusHistory[]> { + const args = plainToClass( + DeploymentStatusHistoryFindManyArgs, + request.query + ); + return this.service.deploymentStatusHistories({ + ...args, + select: { + createdAt: true, + deployment: true, + details: true, + id: true, + status: true, + timestamp: true, + updatedAt: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: DeploymentStatusHistory }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deploymentStatusHistory( + @common.Param() params: DeploymentStatusHistoryWhereUniqueInput + ): Promise<DeploymentStatusHistory | null> { + const result = await this.service.deploymentStatusHistory({ + where: params, + select: { + createdAt: true, + deployment: true, + details: true, + id: true, + status: true, + timestamp: 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: DeploymentStatusHistory }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateDeploymentStatusHistory( + @common.Param() params: DeploymentStatusHistoryWhereUniqueInput, + @common.Body() data: DeploymentStatusHistoryUpdateInput + ): Promise<DeploymentStatusHistory | null> { + try { + return await this.service.updateDeploymentStatusHistory({ + where: params, + data: data, + select: { + createdAt: true, + deployment: true, + details: true, + id: true, + status: true, + timestamp: 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: DeploymentStatusHistory }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteDeploymentStatusHistory( + @common.Param() params: DeploymentStatusHistoryWhereUniqueInput + ): Promise<DeploymentStatusHistory | null> { + try { + return await this.service.deleteDeploymentStatusHistory({ + where: params, + select: { + createdAt: true, + deployment: true, + details: true, + id: true, + status: true, + timestamp: 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/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.module.base.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.module.base.ts new file mode 100644 index 00000000..b75510dc --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.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 DeploymentStatusHistoryModuleBase {} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.resolver.base.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.resolver.base.ts new file mode 100644 index 00000000..cca0f33e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.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 { DeploymentStatusHistory } from "./DeploymentStatusHistory"; +import { DeploymentStatusHistoryCountArgs } from "./DeploymentStatusHistoryCountArgs"; +import { DeploymentStatusHistoryFindManyArgs } from "./DeploymentStatusHistoryFindManyArgs"; +import { DeploymentStatusHistoryFindUniqueArgs } from "./DeploymentStatusHistoryFindUniqueArgs"; +import { CreateDeploymentStatusHistoryArgs } from "./CreateDeploymentStatusHistoryArgs"; +import { UpdateDeploymentStatusHistoryArgs } from "./UpdateDeploymentStatusHistoryArgs"; +import { DeleteDeploymentStatusHistoryArgs } from "./DeleteDeploymentStatusHistoryArgs"; +import { DeploymentStatusHistoryService } from "../deploymentStatusHistory.service"; +@graphql.Resolver(() => DeploymentStatusHistory) +export class DeploymentStatusHistoryResolverBase { + constructor(protected readonly service: DeploymentStatusHistoryService) {} + + async _deploymentStatusHistoriesMeta( + @graphql.Args() args: DeploymentStatusHistoryCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [DeploymentStatusHistory]) + async deploymentStatusHistories( + @graphql.Args() args: DeploymentStatusHistoryFindManyArgs + ): Promise<DeploymentStatusHistory[]> { + return this.service.deploymentStatusHistories(args); + } + + @graphql.Query(() => DeploymentStatusHistory, { nullable: true }) + async deploymentStatusHistory( + @graphql.Args() args: DeploymentStatusHistoryFindUniqueArgs + ): Promise<DeploymentStatusHistory | null> { + const result = await this.service.deploymentStatusHistory(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => DeploymentStatusHistory) + async createDeploymentStatusHistory( + @graphql.Args() args: CreateDeploymentStatusHistoryArgs + ): Promise<DeploymentStatusHistory> { + return await this.service.createDeploymentStatusHistory({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => DeploymentStatusHistory) + async updateDeploymentStatusHistory( + @graphql.Args() args: UpdateDeploymentStatusHistoryArgs + ): Promise<DeploymentStatusHistory | null> { + try { + return await this.service.updateDeploymentStatusHistory({ + ...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(() => DeploymentStatusHistory) + async deleteDeploymentStatusHistory( + @graphql.Args() args: DeleteDeploymentStatusHistoryArgs + ): Promise<DeploymentStatusHistory | null> { + try { + return await this.service.deleteDeploymentStatusHistory(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.service.base.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.service.base.ts new file mode 100644 index 00000000..b711a9f1 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/base/deploymentStatusHistory.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, + DeploymentStatusHistory as PrismaDeploymentStatusHistory, +} from "@prisma/client"; + +export class DeploymentStatusHistoryServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.DeploymentStatusHistoryCountArgs, "select"> + ): Promise<number> { + return this.prisma.deploymentStatusHistory.count(args); + } + + async deploymentStatusHistories( + args: Prisma.DeploymentStatusHistoryFindManyArgs + ): Promise<PrismaDeploymentStatusHistory[]> { + return this.prisma.deploymentStatusHistory.findMany(args); + } + async deploymentStatusHistory( + args: Prisma.DeploymentStatusHistoryFindUniqueArgs + ): Promise<PrismaDeploymentStatusHistory | null> { + return this.prisma.deploymentStatusHistory.findUnique(args); + } + async createDeploymentStatusHistory( + args: Prisma.DeploymentStatusHistoryCreateArgs + ): Promise<PrismaDeploymentStatusHistory> { + return this.prisma.deploymentStatusHistory.create(args); + } + async updateDeploymentStatusHistory( + args: Prisma.DeploymentStatusHistoryUpdateArgs + ): Promise<PrismaDeploymentStatusHistory> { + return this.prisma.deploymentStatusHistory.update(args); + } + async deleteDeploymentStatusHistory( + args: Prisma.DeploymentStatusHistoryDeleteArgs + ): Promise<PrismaDeploymentStatusHistory> { + return this.prisma.deploymentStatusHistory.delete(args); + } +} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.controller.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.controller.ts new file mode 100644 index 00000000..9a44486e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { DeploymentStatusHistoryService } from "./deploymentStatusHistory.service"; +import { DeploymentStatusHistoryControllerBase } from "./base/deploymentStatusHistory.controller.base"; + +@swagger.ApiTags("deploymentStatusHistories") +@common.Controller("deploymentStatusHistories") +export class DeploymentStatusHistoryController extends DeploymentStatusHistoryControllerBase { + constructor(protected readonly service: DeploymentStatusHistoryService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.module.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.module.ts new file mode 100644 index 00000000..21ec545e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { DeploymentStatusHistoryModuleBase } from "./base/deploymentStatusHistory.module.base"; +import { DeploymentStatusHistoryService } from "./deploymentStatusHistory.service"; +import { DeploymentStatusHistoryController } from "./deploymentStatusHistory.controller"; +import { DeploymentStatusHistoryResolver } from "./deploymentStatusHistory.resolver"; + +@Module({ + imports: [DeploymentStatusHistoryModuleBase], + controllers: [DeploymentStatusHistoryController], + providers: [DeploymentStatusHistoryService, DeploymentStatusHistoryResolver], + exports: [DeploymentStatusHistoryService], +}) +export class DeploymentStatusHistoryModule {} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.resolver.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.resolver.ts new file mode 100644 index 00000000..bc2b2af7 --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { DeploymentStatusHistoryResolverBase } from "./base/deploymentStatusHistory.resolver.base"; +import { DeploymentStatusHistory } from "./base/DeploymentStatusHistory"; +import { DeploymentStatusHistoryService } from "./deploymentStatusHistory.service"; + +@graphql.Resolver(() => DeploymentStatusHistory) +export class DeploymentStatusHistoryResolver extends DeploymentStatusHistoryResolverBase { + constructor(protected readonly service: DeploymentStatusHistoryService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.service.ts b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.service.ts new file mode 100644 index 00000000..6280e16e --- /dev/null +++ b/apps/audit-tracking-service-server/src/deploymentStatusHistory/deploymentStatusHistory.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { DeploymentStatusHistoryServiceBase } from "./base/deploymentStatusHistory.service.base"; + +@Injectable() +export class DeploymentStatusHistoryService extends DeploymentStatusHistoryServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/audit-tracking-service-server/src/errors.ts b/apps/audit-tracking-service-server/src/errors.ts new file mode 100644 index 00000000..bd1aa6da --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/filters/HttpExceptions.filter.ts b/apps/audit-tracking-service-server/src/filters/HttpExceptions.filter.ts new file mode 100644 index 00000000..f5eda8e3 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/health/base/health.controller.base.ts b/apps/audit-tracking-service-server/src/health/base/health.controller.base.ts new file mode 100644 index 00000000..afd9e0dd --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/health/base/health.service.base.ts b/apps/audit-tracking-service-server/src/health/base/health.service.base.ts new file mode 100644 index 00000000..49a93a51 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/health/health.controller.ts b/apps/audit-tracking-service-server/src/health/health.controller.ts new file mode 100644 index 00000000..ff484e78 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/health/health.module.ts b/apps/audit-tracking-service-server/src/health/health.module.ts new file mode 100644 index 00000000..39eff7f1 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/health/health.service.ts b/apps/audit-tracking-service-server/src/health/health.service.ts new file mode 100644 index 00000000..44d93432 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/main.ts b/apps/audit-tracking-service-server/src/main.ts new file mode 100644 index 00000000..474eeadf --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/prisma.util.spec.ts b/apps/audit-tracking-service-server/src/prisma.util.spec.ts new file mode 100644 index 00000000..0aa308ed --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/prisma.util.ts b/apps/audit-tracking-service-server/src/prisma.util.ts new file mode 100644 index 00000000..029b98a9 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/prisma/prisma.module.ts b/apps/audit-tracking-service-server/src/prisma/prisma.module.ts new file mode 100644 index 00000000..1edbf95e --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/prisma/prisma.service.ts b/apps/audit-tracking-service-server/src/prisma/prisma.service.ts new file mode 100644 index 00000000..79ea4fa7 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/providers/secrets/base/secretsManager.service.base.spec.ts b/apps/audit-tracking-service-server/src/providers/secrets/base/secretsManager.service.base.spec.ts new file mode 100644 index 00000000..f1611722 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/providers/secrets/base/secretsManager.service.base.ts b/apps/audit-tracking-service-server/src/providers/secrets/base/secretsManager.service.base.ts new file mode 100644 index 00000000..340818c2 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/providers/secrets/secretsManager.module.ts b/apps/audit-tracking-service-server/src/providers/secrets/secretsManager.module.ts new file mode 100644 index 00000000..3a621e40 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/providers/secrets/secretsManager.service.ts b/apps/audit-tracking-service-server/src/providers/secrets/secretsManager.service.ts new file mode 100644 index 00000000..89907c3b --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/providers/secrets/secretsNameKey.enum.ts b/apps/audit-tracking-service-server/src/providers/secrets/secretsNameKey.enum.ts new file mode 100644 index 00000000..e225d65d --- /dev/null +++ b/apps/audit-tracking-service-server/src/providers/secrets/secretsNameKey.enum.ts @@ -0,0 +1 @@ +export enum EnumSecretsNameKey {} \ No newline at end of file diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/CreateResourceTagArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/CreateResourceTagArgs.ts new file mode 100644 index 00000000..e46155af --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/CreateResourceTagArgs.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 { ResourceTagCreateInput } from "./ResourceTagCreateInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class CreateResourceTagArgs { + @ApiProperty({ + required: true, + type: () => ResourceTagCreateInput, + }) + @ValidateNested() + @Type(() => ResourceTagCreateInput) + @Field(() => ResourceTagCreateInput, { nullable: false }) + data!: ResourceTagCreateInput; +} + +export { CreateResourceTagArgs as CreateResourceTagArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/DeleteResourceTagArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/DeleteResourceTagArgs.ts new file mode 100644 index 00000000..46681fa5 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/DeleteResourceTagArgs.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 { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class DeleteResourceTagArgs { + @ApiProperty({ + required: true, + type: () => ResourceTagWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereUniqueInput) + @Field(() => ResourceTagWhereUniqueInput, { nullable: false }) + where!: ResourceTagWhereUniqueInput; +} + +export { DeleteResourceTagArgs as DeleteResourceTagArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTag.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTag.ts new file mode 100644 index 00000000..cc11b744 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTag.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 ResourceTag { + @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, + }) + key!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceId!: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceType!: 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, + }) + value!: string | null; +} + +export { ResourceTag as ResourceTag }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCountArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCountArgs.ts new file mode 100644 index 00000000..f4092899 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCountArgs.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 { ResourceTagWhereInput } from "./ResourceTagWhereInput"; +import { Type } from "class-transformer"; + +@ArgsType() +class ResourceTagCountArgs { + @ApiProperty({ + required: false, + type: () => ResourceTagWhereInput, + }) + @Field(() => ResourceTagWhereInput, { nullable: true }) + @Type(() => ResourceTagWhereInput) + where?: ResourceTagWhereInput; +} + +export { ResourceTagCountArgs as ResourceTagCountArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCreateInput.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCreateInput.ts new file mode 100644 index 00000000..abda99b6 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagCreateInput.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 ResourceTagCreateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + key?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceType?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + value?: string | null; +} + +export { ResourceTagCreateInput as ResourceTagCreateInput }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindManyArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindManyArgs.ts new file mode 100644 index 00000000..67ab567c --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindManyArgs.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 { ResourceTagWhereInput } from "./ResourceTagWhereInput"; +import { IsOptional, ValidateNested, IsInt } from "class-validator"; +import { Type } from "class-transformer"; +import { ResourceTagOrderByInput } from "./ResourceTagOrderByInput"; + +@ArgsType() +class ResourceTagFindManyArgs { + @ApiProperty({ + required: false, + type: () => ResourceTagWhereInput, + }) + @IsOptional() + @ValidateNested() + @Field(() => ResourceTagWhereInput, { nullable: true }) + @Type(() => ResourceTagWhereInput) + where?: ResourceTagWhereInput; + + @ApiProperty({ + required: false, + type: [ResourceTagOrderByInput], + }) + @IsOptional() + @ValidateNested({ each: true }) + @Field(() => [ResourceTagOrderByInput], { nullable: true }) + @Type(() => ResourceTagOrderByInput) + orderBy?: Array<ResourceTagOrderByInput>; + + @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 { ResourceTagFindManyArgs as ResourceTagFindManyArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindUniqueArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindUniqueArgs.ts new file mode 100644 index 00000000..8e7604fb --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagFindUniqueArgs.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 { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; + +@ArgsType() +class ResourceTagFindUniqueArgs { + @ApiProperty({ + required: true, + type: () => ResourceTagWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereUniqueInput) + @Field(() => ResourceTagWhereUniqueInput, { nullable: false }) + where!: ResourceTagWhereUniqueInput; +} + +export { ResourceTagFindUniqueArgs as ResourceTagFindUniqueArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagListRelationFilter.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagListRelationFilter.ts new file mode 100644 index 00000000..b49a01c4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagListRelationFilter.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 { ResourceTagWhereInput } from "./ResourceTagWhereInput"; +import { ValidateNested, IsOptional } from "class-validator"; +import { Type } from "class-transformer"; + +@InputType() +class ResourceTagListRelationFilter { + @ApiProperty({ + required: false, + type: () => ResourceTagWhereInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereInput) + @IsOptional() + @Field(() => ResourceTagWhereInput, { + nullable: true, + }) + every?: ResourceTagWhereInput; + + @ApiProperty({ + required: false, + type: () => ResourceTagWhereInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereInput) + @IsOptional() + @Field(() => ResourceTagWhereInput, { + nullable: true, + }) + some?: ResourceTagWhereInput; + + @ApiProperty({ + required: false, + type: () => ResourceTagWhereInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereInput) + @IsOptional() + @Field(() => ResourceTagWhereInput, { + nullable: true, + }) + none?: ResourceTagWhereInput; +} +export { ResourceTagListRelationFilter as ResourceTagListRelationFilter }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagOrderByInput.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagOrderByInput.ts new file mode 100644 index 00000000..10c83bd0 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagOrderByInput.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 ResourceTagOrderByInput { + @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, + }) + key?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + resourceId?: SortOrder; + + @ApiProperty({ + required: false, + enum: ["asc", "desc"], + }) + @IsOptional() + @IsEnum(SortOrder) + @Field(() => SortOrder, { + nullable: true, + }) + resourceType?: 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, + }) + value?: SortOrder; +} + +export { ResourceTagOrderByInput as ResourceTagOrderByInput }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagUpdateInput.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagUpdateInput.ts new file mode 100644 index 00000000..801f8ec4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagUpdateInput.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 ResourceTagUpdateInput { + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + key?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceId?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + resourceType?: string | null; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + @MaxLength(1000) + @IsOptional() + @Field(() => String, { + nullable: true, + }) + value?: string | null; +} + +export { ResourceTagUpdateInput as ResourceTagUpdateInput }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereInput.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereInput.ts new file mode 100644 index 00000000..b631115a --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereInput.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 ResourceTagWhereInput { + @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, + }) + key?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + resourceId?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + resourceType?: StringNullableFilter; + + @ApiProperty({ + required: false, + type: StringNullableFilter, + }) + @Type(() => StringNullableFilter) + @IsOptional() + @Field(() => StringNullableFilter, { + nullable: true, + }) + value?: StringNullableFilter; +} + +export { ResourceTagWhereInput as ResourceTagWhereInput }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereUniqueInput.ts b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereUniqueInput.ts new file mode 100644 index 00000000..b84da8d4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/ResourceTagWhereUniqueInput.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 ResourceTagWhereUniqueInput { + @ApiProperty({ + required: true, + type: String, + }) + @IsString() + @Field(() => String) + id!: string; +} + +export { ResourceTagWhereUniqueInput as ResourceTagWhereUniqueInput }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/UpdateResourceTagArgs.ts b/apps/audit-tracking-service-server/src/resourceTag/base/UpdateResourceTagArgs.ts new file mode 100644 index 00000000..893274be --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/UpdateResourceTagArgs.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 { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; +import { ValidateNested } from "class-validator"; +import { Type } from "class-transformer"; +import { ResourceTagUpdateInput } from "./ResourceTagUpdateInput"; + +@ArgsType() +class UpdateResourceTagArgs { + @ApiProperty({ + required: true, + type: () => ResourceTagWhereUniqueInput, + }) + @ValidateNested() + @Type(() => ResourceTagWhereUniqueInput) + @Field(() => ResourceTagWhereUniqueInput, { nullable: false }) + where!: ResourceTagWhereUniqueInput; + + @ApiProperty({ + required: true, + type: () => ResourceTagUpdateInput, + }) + @ValidateNested() + @Type(() => ResourceTagUpdateInput) + @Field(() => ResourceTagUpdateInput, { nullable: false }) + data!: ResourceTagUpdateInput; +} + +export { UpdateResourceTagArgs as UpdateResourceTagArgs }; diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.controller.base.spec.ts b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.controller.base.spec.ts new file mode 100644 index 00000000..0b67eaf4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.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 { ResourceTagController } from "../resourceTag.controller"; +import { ResourceTagService } from "../resourceTag.service"; + +const nonExistingId = "nonExistingId"; +const existingId = "existingId"; +const CREATE_INPUT = { + createdAt: new Date(), + id: "exampleId", + key: "exampleKey", + resourceId: "exampleResourceId", + resourceType: "exampleResourceType", + updatedAt: new Date(), + value: "exampleValue", +}; +const CREATE_RESULT = { + createdAt: new Date(), + id: "exampleId", + key: "exampleKey", + resourceId: "exampleResourceId", + resourceType: "exampleResourceType", + updatedAt: new Date(), + value: "exampleValue", +}; +const FIND_MANY_RESULT = [ + { + createdAt: new Date(), + id: "exampleId", + key: "exampleKey", + resourceId: "exampleResourceId", + resourceType: "exampleResourceType", + updatedAt: new Date(), + value: "exampleValue", + }, +]; +const FIND_ONE_RESULT = { + createdAt: new Date(), + id: "exampleId", + key: "exampleKey", + resourceId: "exampleResourceId", + resourceType: "exampleResourceType", + updatedAt: new Date(), + value: "exampleValue", +}; + +const service = { + createResourceTag() { + return CREATE_RESULT; + }, + resourceTags: () => FIND_MANY_RESULT, + resourceTag: ({ 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("ResourceTag", () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleRef = await Test.createTestingModule({ + providers: [ + { + provide: ResourceTagService, + useValue: service, + }, + ], + controllers: [ResourceTagController], + 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 /resourceTags", async () => { + await request(app.getHttpServer()) + .post("/resourceTags") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }); + }); + + test("GET /resourceTags", async () => { + await request(app.getHttpServer()) + .get("/resourceTags") + .expect(HttpStatus.OK) + .expect([ + { + ...FIND_MANY_RESULT[0], + createdAt: FIND_MANY_RESULT[0].createdAt.toISOString(), + updatedAt: FIND_MANY_RESULT[0].updatedAt.toISOString(), + }, + ]); + }); + + test("GET /resourceTags/:id non existing", async () => { + await request(app.getHttpServer()) + .get(`${"/resourceTags"}/${nonExistingId}`) + .expect(HttpStatus.NOT_FOUND) + .expect({ + statusCode: HttpStatus.NOT_FOUND, + message: `No resource was found for {"${"id"}":"${nonExistingId}"}`, + error: "Not Found", + }); + }); + + test("GET /resourceTags/:id existing", async () => { + await request(app.getHttpServer()) + .get(`${"/resourceTags"}/${existingId}`) + .expect(HttpStatus.OK) + .expect({ + ...FIND_ONE_RESULT, + createdAt: FIND_ONE_RESULT.createdAt.toISOString(), + updatedAt: FIND_ONE_RESULT.updatedAt.toISOString(), + }); + }); + + test("POST /resourceTags existing resource", async () => { + const agent = request(app.getHttpServer()); + await agent + .post("/resourceTags") + .send(CREATE_INPUT) + .expect(HttpStatus.CREATED) + .expect({ + ...CREATE_RESULT, + createdAt: CREATE_RESULT.createdAt.toISOString(), + updatedAt: CREATE_RESULT.updatedAt.toISOString(), + }) + .then(function () { + agent + .post("/resourceTags") + .send(CREATE_INPUT) + .expect(HttpStatus.CONFLICT) + .expect({ + statusCode: HttpStatus.CONFLICT, + }); + }); + }); + + afterAll(async () => { + await app.close(); + }); +}); diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.controller.base.ts b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.controller.base.ts new file mode 100644 index 00000000..874bbf5e --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.controller.base.ts @@ -0,0 +1,151 @@ +/* +------------------------------------------------------------------------------ +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 { ResourceTagService } from "../resourceTag.service"; +import { ResourceTagCreateInput } from "./ResourceTagCreateInput"; +import { ResourceTag } from "./ResourceTag"; +import { ResourceTagFindManyArgs } from "./ResourceTagFindManyArgs"; +import { ResourceTagWhereUniqueInput } from "./ResourceTagWhereUniqueInput"; +import { ResourceTagUpdateInput } from "./ResourceTagUpdateInput"; + +export class ResourceTagControllerBase { + constructor(protected readonly service: ResourceTagService) {} + @common.Post() + @swagger.ApiCreatedResponse({ type: ResourceTag }) + async createResourceTag( + @common.Body() data: ResourceTagCreateInput + ): Promise<ResourceTag> { + return await this.service.createResourceTag({ + data: data, + select: { + createdAt: true, + id: true, + key: true, + resourceId: true, + resourceType: true, + updatedAt: true, + value: true, + }, + }); + } + + @common.Get() + @swagger.ApiOkResponse({ type: [ResourceTag] }) + @ApiNestedQuery(ResourceTagFindManyArgs) + async resourceTags(@common.Req() request: Request): Promise<ResourceTag[]> { + const args = plainToClass(ResourceTagFindManyArgs, request.query); + return this.service.resourceTags({ + ...args, + select: { + createdAt: true, + id: true, + key: true, + resourceId: true, + resourceType: true, + updatedAt: true, + value: true, + }, + }); + } + + @common.Get("/:id") + @swagger.ApiOkResponse({ type: ResourceTag }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async resourceTag( + @common.Param() params: ResourceTagWhereUniqueInput + ): Promise<ResourceTag | null> { + const result = await this.service.resourceTag({ + where: params, + select: { + createdAt: true, + id: true, + key: true, + resourceId: true, + resourceType: true, + updatedAt: true, + value: true, + }, + }); + if (result === null) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + return result; + } + + @common.Patch("/:id") + @swagger.ApiOkResponse({ type: ResourceTag }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async updateResourceTag( + @common.Param() params: ResourceTagWhereUniqueInput, + @common.Body() data: ResourceTagUpdateInput + ): Promise<ResourceTag | null> { + try { + return await this.service.updateResourceTag({ + where: params, + data: data, + select: { + createdAt: true, + id: true, + key: true, + resourceId: true, + resourceType: true, + updatedAt: true, + value: 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: ResourceTag }) + @swagger.ApiNotFoundResponse({ type: errors.NotFoundException }) + async deleteResourceTag( + @common.Param() params: ResourceTagWhereUniqueInput + ): Promise<ResourceTag | null> { + try { + return await this.service.deleteResourceTag({ + where: params, + select: { + createdAt: true, + id: true, + key: true, + resourceId: true, + resourceType: true, + updatedAt: true, + value: true, + }, + }); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new errors.NotFoundException( + `No resource was found for ${JSON.stringify(params)}` + ); + } + throw error; + } + } +} diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.module.base.ts b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.module.base.ts new file mode 100644 index 00000000..4e46405e --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.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 ResourceTagModuleBase {} diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.resolver.base.ts b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.resolver.base.ts new file mode 100644 index 00000000..f4e3c496 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.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 { ResourceTag } from "./ResourceTag"; +import { ResourceTagCountArgs } from "./ResourceTagCountArgs"; +import { ResourceTagFindManyArgs } from "./ResourceTagFindManyArgs"; +import { ResourceTagFindUniqueArgs } from "./ResourceTagFindUniqueArgs"; +import { CreateResourceTagArgs } from "./CreateResourceTagArgs"; +import { UpdateResourceTagArgs } from "./UpdateResourceTagArgs"; +import { DeleteResourceTagArgs } from "./DeleteResourceTagArgs"; +import { ResourceTagService } from "../resourceTag.service"; +@graphql.Resolver(() => ResourceTag) +export class ResourceTagResolverBase { + constructor(protected readonly service: ResourceTagService) {} + + async _resourceTagsMeta( + @graphql.Args() args: ResourceTagCountArgs + ): Promise<MetaQueryPayload> { + const result = await this.service.count(args); + return { + count: result, + }; + } + + @graphql.Query(() => [ResourceTag]) + async resourceTags( + @graphql.Args() args: ResourceTagFindManyArgs + ): Promise<ResourceTag[]> { + return this.service.resourceTags(args); + } + + @graphql.Query(() => ResourceTag, { nullable: true }) + async resourceTag( + @graphql.Args() args: ResourceTagFindUniqueArgs + ): Promise<ResourceTag | null> { + const result = await this.service.resourceTag(args); + if (result === null) { + return null; + } + return result; + } + + @graphql.Mutation(() => ResourceTag) + async createResourceTag( + @graphql.Args() args: CreateResourceTagArgs + ): Promise<ResourceTag> { + return await this.service.createResourceTag({ + ...args, + data: args.data, + }); + } + + @graphql.Mutation(() => ResourceTag) + async updateResourceTag( + @graphql.Args() args: UpdateResourceTagArgs + ): Promise<ResourceTag | null> { + try { + return await this.service.updateResourceTag({ + ...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(() => ResourceTag) + async deleteResourceTag( + @graphql.Args() args: DeleteResourceTagArgs + ): Promise<ResourceTag | null> { + try { + return await this.service.deleteResourceTag(args); + } catch (error) { + if (isRecordNotFoundError(error)) { + throw new GraphQLError( + `No resource was found for ${JSON.stringify(args.where)}` + ); + } + throw error; + } + } +} diff --git a/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.service.base.ts b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.service.base.ts new file mode 100644 index 00000000..61ed4bf5 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/base/resourceTag.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, ResourceTag as PrismaResourceTag } from "@prisma/client"; + +export class ResourceTagServiceBase { + constructor(protected readonly prisma: PrismaService) {} + + async count( + args: Omit<Prisma.ResourceTagCountArgs, "select"> + ): Promise<number> { + return this.prisma.resourceTag.count(args); + } + + async resourceTags( + args: Prisma.ResourceTagFindManyArgs + ): Promise<PrismaResourceTag[]> { + return this.prisma.resourceTag.findMany(args); + } + async resourceTag( + args: Prisma.ResourceTagFindUniqueArgs + ): Promise<PrismaResourceTag | null> { + return this.prisma.resourceTag.findUnique(args); + } + async createResourceTag( + args: Prisma.ResourceTagCreateArgs + ): Promise<PrismaResourceTag> { + return this.prisma.resourceTag.create(args); + } + async updateResourceTag( + args: Prisma.ResourceTagUpdateArgs + ): Promise<PrismaResourceTag> { + return this.prisma.resourceTag.update(args); + } + async deleteResourceTag( + args: Prisma.ResourceTagDeleteArgs + ): Promise<PrismaResourceTag> { + return this.prisma.resourceTag.delete(args); + } +} diff --git a/apps/audit-tracking-service-server/src/resourceTag/resourceTag.controller.ts b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.controller.ts new file mode 100644 index 00000000..44318e48 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.controller.ts @@ -0,0 +1,12 @@ +import * as common from "@nestjs/common"; +import * as swagger from "@nestjs/swagger"; +import { ResourceTagService } from "./resourceTag.service"; +import { ResourceTagControllerBase } from "./base/resourceTag.controller.base"; + +@swagger.ApiTags("resourceTags") +@common.Controller("resourceTags") +export class ResourceTagController extends ResourceTagControllerBase { + constructor(protected readonly service: ResourceTagService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/resourceTag/resourceTag.module.ts b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.module.ts new file mode 100644 index 00000000..2479095a --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.module.ts @@ -0,0 +1,13 @@ +import { Module } from "@nestjs/common"; +import { ResourceTagModuleBase } from "./base/resourceTag.module.base"; +import { ResourceTagService } from "./resourceTag.service"; +import { ResourceTagController } from "./resourceTag.controller"; +import { ResourceTagResolver } from "./resourceTag.resolver"; + +@Module({ + imports: [ResourceTagModuleBase], + controllers: [ResourceTagController], + providers: [ResourceTagService, ResourceTagResolver], + exports: [ResourceTagService], +}) +export class ResourceTagModule {} diff --git a/apps/audit-tracking-service-server/src/resourceTag/resourceTag.resolver.ts b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.resolver.ts new file mode 100644 index 00000000..021afaf4 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.resolver.ts @@ -0,0 +1,11 @@ +import * as graphql from "@nestjs/graphql"; +import { ResourceTagResolverBase } from "./base/resourceTag.resolver.base"; +import { ResourceTag } from "./base/ResourceTag"; +import { ResourceTagService } from "./resourceTag.service"; + +@graphql.Resolver(() => ResourceTag) +export class ResourceTagResolver extends ResourceTagResolverBase { + constructor(protected readonly service: ResourceTagService) { + super(service); + } +} diff --git a/apps/audit-tracking-service-server/src/resourceTag/resourceTag.service.ts b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.service.ts new file mode 100644 index 00000000..e589a965 --- /dev/null +++ b/apps/audit-tracking-service-server/src/resourceTag/resourceTag.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "../prisma/prisma.service"; +import { ResourceTagServiceBase } from "./base/resourceTag.service.base"; + +@Injectable() +export class ResourceTagService extends ResourceTagServiceBase { + constructor(protected readonly prisma: PrismaService) { + super(prisma); + } +} diff --git a/apps/audit-tracking-service-server/src/serveStaticOptions.service.ts b/apps/audit-tracking-service-server/src/serveStaticOptions.service.ts new file mode 100644 index 00000000..390248b4 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/swagger.ts b/apps/audit-tracking-service-server/src/swagger.ts new file mode 100644 index 00000000..5a56d170 --- /dev/null +++ b/apps/audit-tracking-service-server/src/swagger.ts @@ -0,0 +1,20 @@ +import { DocumentBuilder, SwaggerCustomOptions } from "@nestjs/swagger"; + +export const swaggerPath = "api"; + +export const swaggerDocumentOptions = new DocumentBuilder() + .setTitle("Audit & Tracking Service") + .setDescription( + 'Logs actions, tracks status, and archives results.\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: "Audit & Tracking Service", +}; diff --git a/apps/audit-tracking-service-server/src/swagger/favicon.png b/apps/audit-tracking-service-server/src/swagger/favicon.png new file mode 100644 index 00000000..a79882d5 Binary files /dev/null and b/apps/audit-tracking-service-server/src/swagger/favicon.png differ diff --git a/apps/audit-tracking-service-server/src/swagger/logo-amplication-white.svg b/apps/audit-tracking-service-server/src/swagger/logo-amplication-white.svg new file mode 100644 index 00000000..0054cd4d --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/swagger/swagger.css b/apps/audit-tracking-service-server/src/swagger/swagger.css new file mode 100644 index 00000000..b7c40372 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/tests/health/health.service.spec.ts b/apps/audit-tracking-service-server/src/tests/health/health.service.spec.ts new file mode 100644 index 00000000..4b191f1f --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/types.ts b/apps/audit-tracking-service-server/src/types.ts new file mode 100644 index 00000000..f762a5df --- /dev/null +++ b/apps/audit-tracking-service-server/src/types.ts @@ -0,0 +1,3 @@ +import type { JsonValue } from "type-fest"; + +export type InputJsonValue = Omit<JsonValue, "null">; diff --git a/apps/audit-tracking-service-server/src/util/BooleanFilter.ts b/apps/audit-tracking-service-server/src/util/BooleanFilter.ts new file mode 100644 index 00000000..75f4e344 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/BooleanNullableFilter.ts b/apps/audit-tracking-service-server/src/util/BooleanNullableFilter.ts new file mode 100644 index 00000000..9f48ac17 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/DateTimeFilter.ts b/apps/audit-tracking-service-server/src/util/DateTimeFilter.ts new file mode 100644 index 00000000..d2b6dfba --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/DateTimeNullableFilter.ts b/apps/audit-tracking-service-server/src/util/DateTimeNullableFilter.ts new file mode 100644 index 00000000..ccc00a54 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/FloatFilter.ts b/apps/audit-tracking-service-server/src/util/FloatFilter.ts new file mode 100644 index 00000000..a3266d21 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/FloatNullableFilter.ts b/apps/audit-tracking-service-server/src/util/FloatNullableFilter.ts new file mode 100644 index 00000000..feb0fc52 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/IntFilter.ts b/apps/audit-tracking-service-server/src/util/IntFilter.ts new file mode 100644 index 00000000..f6880e77 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/IntNullableFilter.ts b/apps/audit-tracking-service-server/src/util/IntNullableFilter.ts new file mode 100644 index 00000000..e3b71a33 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/JsonFilter.ts b/apps/audit-tracking-service-server/src/util/JsonFilter.ts new file mode 100644 index 00000000..7040b74f --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/JsonNullableFilter.ts b/apps/audit-tracking-service-server/src/util/JsonNullableFilter.ts new file mode 100644 index 00000000..3381d524 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/MetaQueryPayload.ts b/apps/audit-tracking-service-server/src/util/MetaQueryPayload.ts new file mode 100644 index 00000000..fc30531c --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/QueryMode.ts b/apps/audit-tracking-service-server/src/util/QueryMode.ts new file mode 100644 index 00000000..f9b1653e --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/SortOrder.ts b/apps/audit-tracking-service-server/src/util/SortOrder.ts new file mode 100644 index 00000000..d4108e69 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/StringFilter.ts b/apps/audit-tracking-service-server/src/util/StringFilter.ts new file mode 100644 index 00000000..80b573d0 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/util/StringNullableFilter.ts b/apps/audit-tracking-service-server/src/util/StringNullableFilter.ts new file mode 100644 index 00000000..01b399cb --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/validators/index.ts b/apps/audit-tracking-service-server/src/validators/index.ts new file mode 100644 index 00000000..7f62d844 --- /dev/null +++ b/apps/audit-tracking-service-server/src/validators/index.ts @@ -0,0 +1 @@ +export * from "./is-json-value-validator"; diff --git a/apps/audit-tracking-service-server/src/validators/is-json-value-validator.spec.ts b/apps/audit-tracking-service-server/src/validators/is-json-value-validator.spec.ts new file mode 100644 index 00000000..5a778242 --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/src/validators/is-json-value-validator.ts b/apps/audit-tracking-service-server/src/validators/is-json-value-validator.ts new file mode 100644 index 00000000..1002540a --- /dev/null +++ b/apps/audit-tracking-service-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/audit-tracking-service-server/tsconfig.build.json b/apps/audit-tracking-service-server/tsconfig.build.json new file mode 100644 index 00000000..e5794017 --- /dev/null +++ b/apps/audit-tracking-service-server/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "prisma", "test", "dist", "**/*spec.ts", "admin"] +} diff --git a/apps/audit-tracking-service-server/tsconfig.json b/apps/audit-tracking-service-server/tsconfig.json new file mode 100644 index 00000000..707e8cd0 --- /dev/null +++ b/apps/audit-tracking-service-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"] +}