Merge branch 'feature/auth-configure' of https://github.com/IT-Lab-KubSU/platform into feature/auth-configure

feature/auth-configure
AlexBarmen 1 year ago
commit 398638c79c

@ -6,3 +6,4 @@ POSTGRES_DB=root
AUTH_SOURCE_URL=postgresql://postgres:postgres@localhost:5444/user-authentication
PUBLIC_KEY_PATH=tokens/jwt.key.pub
PRIVATE_KEY_PATH=tokens/jwt.key
USER_DATA_SOURCE_URL=postgresql://postgres:postgres@localhost:5445/sc-user-data

@ -45,6 +45,14 @@ copy .env.example .env
cd apps/auth/serving && copy database.env.example database.env && sudo docker-compose up -d
```
```bash
cd apps/auth/serving && copy database.env.example database.env && sudo docker-compose up -d && cd ../../../
```
```bash
cd apps/user-data/serving && copy database.env.example database.env && sudo docker-compose up -d && cd ../../../
```
auth
```bash
prisma generate --schema="./libs/prisma-clients/auth/prisma/schema.prisma"
```
@ -52,6 +60,14 @@ prisma generate --schema="./libs/prisma-clients/auth/prisma/schema.prisma"
```bash
prisma db push --schema="./libs/prisma-clients/auth/prisma/schema.prisma"
```
user data
```bash
prisma generate --schema="./libs/prisma-clients/user-data/prisma/schema.prisma"
```
```bash
prisma db push --schema="./libs/prisma-clients/user-data/prisma/schema.prisma"
```
Run all services:
```bash
@ -128,7 +144,7 @@ Just run `nx build demoapp` to build the application. The build artifacts will b
# Backend
## Prisma Types
```bash
nx generate @nx/plugin:generator prisma-generator --project=prisma-generator
nx g prisma-generator
```
# Frontend

@ -1,8 +0,0 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL=postgresql://postgres:postgres@sc-user-data-database/sc-user-data
PORT=3002

@ -1 +0,0 @@
migrations

@ -11,18 +11,8 @@ services:
- user-data-database:/var/lib/postgresql
env_file:
- ./database.env
user-data-database-admin:
container_name: user-data-database-admin
image: bitnami/phppgadmin:latest
restart: always
networks:
- user-data
depends_on:
- user-data-database
environment:
- DATABASE_HOST=user-data-database
ports:
- "8083:8080"
- 5445:5432
networks:
user-data:

@ -1,5 +1,5 @@
import { Body, Controller, HttpCode, Inject, Post, UseInterceptors } from "@nestjs/common";
import { Prisma, Email } from "@prisma/client";
import { EmailFindUniqueArgs, EmailFindFirstArgs, EmailFindManyArgs, EmailUpdateArgs, EmailCountArgs, EmailCreateArgs, EmailDeleteArgs, Email } from "@platform/prisma-clients/user-data";
import { EmailService } from "./service/email.service";
import { PrismaErrorInterceptor } from "../prisma/interceptor/prisma-error.interceptor";
@ -11,43 +11,43 @@ export class EmailController {
@Post("find/unique")
@HttpCode(200)
async FindUnique(@Body() emailFindUniqueArgs: Prisma.EmailFindUniqueArgs): Promise<Partial<Email> | null> {
async FindUnique(@Body() emailFindUniqueArgs: EmailFindUniqueArgs): Promise<Partial<Email> | null> {
return await this.email.FindUnique(emailFindUniqueArgs);
}
@Post("find/first")
@HttpCode(200)
async FindFirst(@Body() emailFindFirstArgs: Prisma.EmailFindFirstArgs): Promise<Partial<Email> | null> {
async FindFirst(@Body() emailFindFirstArgs: EmailFindFirstArgs): Promise<Partial<Email> | null> {
return await this.email.FindFirst(emailFindFirstArgs);
}
@Post("find/many")
@HttpCode(200)
async FindMany(@Body() emailFindManyArgs: Prisma.EmailFindManyArgs): Promise<Partial<Email>[]> {
async FindMany(@Body() emailFindManyArgs: EmailFindManyArgs): Promise<Partial<Email>[]> {
return await this.email.FindMany(emailFindManyArgs);
}
@Post("update")
@HttpCode(200)
async Update(@Body() emailUpdateArgs: Prisma.EmailUpdateArgs): Promise<Partial<Email>> {
async Update(@Body() emailUpdateArgs: EmailUpdateArgs): Promise<Partial<Email>> {
return await this.email.Update(emailUpdateArgs);
}
@Post("count")
@HttpCode(200)
async Count(@Body() emailCountArgs: Prisma.EmailCountArgs): Promise<number> {
async Count(@Body() emailCountArgs: EmailCountArgs): Promise<number> {
return await this.email.Count(emailCountArgs);
}
@Post("create")
@HttpCode(200)
async Create(@Body() emailCreateArgs: Prisma.EmailCreateArgs): Promise<Partial<Email>> {
async Create(@Body() emailCreateArgs: EmailCreateArgs): Promise<Partial<Email>> {
return await this.email.Create(emailCreateArgs);
}
@Post("delete")
@HttpCode(200)
async Delete(@Body() emailDeleteArgs: Prisma.EmailDeleteArgs): Promise<Partial<Email>> {
async Delete(@Body() emailDeleteArgs: EmailDeleteArgs): Promise<Partial<Email>> {
return await this.email.Delete(emailDeleteArgs);
}
}

@ -1,6 +1,10 @@
import { Inject, Injectable } from "@nestjs/common";
import { PrismaService } from '../../prisma/service/prisma.service';
import { Email, Prisma } from "@prisma/client";
import { UserDataClient as Prisma } from "@platform/prisma-clients";
import { Email, EmailFindUniqueArgs,
EmailFindFirstArgs, EmailFindManyArgs, EmailUpdateArgs,
EmailCountArgs, EmailCreateArgs, EmailDeleteArgs
} from "@platform/prisma-clients/user-data";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import { UniqueConstraintFailedError } from "../../prisma/error/unique-constraint-failed.error";
import { RecordNotFoundError } from "../../prisma/error/record-not-found.error";
@ -10,19 +14,19 @@ export class EmailService {
constructor(@Inject(PrismaService) private prisma: PrismaService) {
}
async FindUnique(emailFindUniqueArgs: Prisma.EmailFindUniqueArgs): Promise<Partial<Email> | null> {
async FindUnique(emailFindUniqueArgs: EmailFindUniqueArgs): Promise<Partial<Email> | null> {
return await this.prisma.email.findUnique(emailFindUniqueArgs);
}
async FindFirst(emailFindFirstArgs: Prisma.EmailFindFirstArgs): Promise<Partial<Email> | null> {
async FindFirst(emailFindFirstArgs: EmailFindFirstArgs): Promise<Partial<Email> | null> {
return await this.prisma.email.findFirst(emailFindFirstArgs);
}
async FindMany(emailFindManyArgs: Prisma.EmailFindManyArgs): Promise<Partial<Email>[]> {
async FindMany(emailFindManyArgs: EmailFindManyArgs): Promise<Partial<Email>[]> {
return await this.prisma.email.findMany(emailFindManyArgs);
}
async Update(emailUpdateArgs: Prisma.EmailUpdateArgs): Promise<Partial<Email>> {
async Update(emailUpdateArgs: EmailUpdateArgs): Promise<Partial<Email>> {
try {
return await this.prisma.email.update(emailUpdateArgs);
} catch (e) {
@ -34,11 +38,11 @@ export class EmailService {
}
}
async Count(emailCountArgs: Prisma.EmailCountArgs): Promise<number> {
async Count(emailCountArgs: EmailCountArgs): Promise<number> {
return await this.prisma.email.count(emailCountArgs);
}
async Create(emailCreateArgs: Prisma.EmailCreateArgs): Promise<Partial<Email>> {
async Create(emailCreateArgs: EmailCreateArgs): Promise<Partial<Email>> {
try {
return await this.prisma.email.create(emailCreateArgs);
} catch (e) {
@ -49,7 +53,7 @@ export class EmailService {
}
}
async Delete(emailDeleteArgs: Prisma.EmailDeleteArgs): Promise<Partial<Email>> {
async Delete(emailDeleteArgs: EmailDeleteArgs): Promise<Partial<Email>> {
try {
return await this.prisma.email.delete(emailDeleteArgs);
} catch (e) {

@ -1,5 +1,9 @@
import { Body, Controller, HttpCode, Inject, Post, UseInterceptors } from "@nestjs/common";
import { PhoneNumber, Prisma } from "@prisma/client";
import { UserDataClient as Prisma } from "@platform/prisma-clients";
import { PhoneNumber, PhoneNumberFindUniqueArgs,
PhoneNumberFindFirstArgs, PhoneNumberFindManyArgs, PhoneNumberUpdateArgs,
PhoneNumberCountArgs, PhoneNumberCreateArgs, PhoneNumberDeleteArgs
} from "@platform/prisma-clients/user-data";
import { PhoneNumberService } from "./service/phone-number.service";
import { PrismaErrorInterceptor } from "../prisma/interceptor/prisma-error.interceptor";
@ -11,43 +15,43 @@ export class PhoneNumberController {
@Post("find/unique")
@HttpCode(200)
async FindUnique(@Body() phoneNumberFindUniqueArgs: Prisma.PhoneNumberFindUniqueArgs): Promise<Partial<PhoneNumber> | null> {
async FindUnique(@Body() phoneNumberFindUniqueArgs: PhoneNumberFindUniqueArgs): Promise<Partial<PhoneNumber> | null> {
return await this.phoneNumber.FindUnique(phoneNumberFindUniqueArgs);
}
@Post("find/first")
@HttpCode(200)
async FindFirst(@Body() phoneNumberFindFirstArgs: Prisma.PhoneNumberFindFirstArgs): Promise<Partial<PhoneNumber> | null> {
async FindFirst(@Body() phoneNumberFindFirstArgs: PhoneNumberFindFirstArgs): Promise<Partial<PhoneNumber> | null> {
return await this.phoneNumber.FindFirst(phoneNumberFindFirstArgs);
}
@Post("find/many")
@HttpCode(200)
async FindMany(@Body() phoneNumberFindManyArgs: Prisma.PhoneNumberFindManyArgs): Promise<Partial<PhoneNumber>[]> {
async FindMany(@Body() phoneNumberFindManyArgs: PhoneNumberFindManyArgs): Promise<Partial<PhoneNumber>[]> {
return await this.phoneNumber.FindMany(phoneNumberFindManyArgs);
}
@Post("update")
@HttpCode(200)
async Update(@Body() phoneNumberUpdateArgs: Prisma.PhoneNumberUpdateArgs): Promise<Partial<PhoneNumber>> {
async Update(@Body() phoneNumberUpdateArgs: PhoneNumberUpdateArgs): Promise<Partial<PhoneNumber>> {
return await this.phoneNumber.Update(phoneNumberUpdateArgs);
}
@Post("count")
@HttpCode(200)
async Count(@Body() phoneNumberCountArgs: Prisma.PhoneNumberCountArgs): Promise<number> {
async Count(@Body() phoneNumberCountArgs: PhoneNumberCountArgs): Promise<number> {
return await this.phoneNumber.Count(phoneNumberCountArgs);
}
@Post("create")
@HttpCode(200)
async Create(@Body() phoneNumberCreateArgs: Prisma.PhoneNumberCreateArgs): Promise<Partial<PhoneNumber>> {
async Create(@Body() phoneNumberCreateArgs: PhoneNumberCreateArgs): Promise<Partial<PhoneNumber>> {
return await this.phoneNumber.Create(phoneNumberCreateArgs);
}
@Post("delete")
@HttpCode(200)
async Delete(@Body() phoneNumberDeleteArgs: Prisma.PhoneNumberDeleteArgs): Promise<Partial<PhoneNumber>> {
async Delete(@Body() phoneNumberDeleteArgs: PhoneNumberDeleteArgs): Promise<Partial<PhoneNumber>> {
return await this.phoneNumber.Delete(phoneNumberDeleteArgs);
}
}

@ -1,6 +1,9 @@
import { Inject, Injectable } from "@nestjs/common";
import { PrismaService } from "../../prisma/service/prisma.service";
import { PhoneNumber, Prisma } from "@prisma/client";
import { PhoneNumber, PhoneNumberFindUniqueArgs,
PhoneNumberFindFirstArgs, PhoneNumberFindManyArgs, PhoneNumberUpdateArgs,
PhoneNumberCountArgs, PhoneNumberCreateArgs, PhoneNumberDeleteArgs
} from "@platform/prisma-clients/user-data";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import { UniqueConstraintFailedError } from "../../prisma/error/unique-constraint-failed.error";
import { RecordNotFoundError } from "../../prisma/error/record-not-found.error";
@ -10,19 +13,19 @@ export class PhoneNumberService {
constructor(@Inject(PrismaService) private prisma: PrismaService) {
}
async FindUnique(phoneNumberFindUniqueArgs: Prisma.PhoneNumberFindUniqueArgs): Promise<Partial<PhoneNumber> | null> {
async FindUnique(phoneNumberFindUniqueArgs: PhoneNumberFindUniqueArgs): Promise<Partial<PhoneNumber> | null> {
return await this.prisma.phoneNumber.findUnique(phoneNumberFindUniqueArgs);
}
async FindFirst(phoneNumberFindFirstArgs: Prisma.PhoneNumberFindFirstArgs): Promise<Partial<PhoneNumber> | null> {
async FindFirst(phoneNumberFindFirstArgs: PhoneNumberFindFirstArgs): Promise<Partial<PhoneNumber> | null> {
return await this.prisma.phoneNumber.findFirst(phoneNumberFindFirstArgs);
}
async FindMany(phoneNumberFindManyArgs: Prisma.PhoneNumberFindManyArgs): Promise<Partial<PhoneNumber>[]> {
async FindMany(phoneNumberFindManyArgs: PhoneNumberFindManyArgs): Promise<Partial<PhoneNumber>[]> {
return await this.prisma.phoneNumber.findMany(phoneNumberFindManyArgs);
}
async Update(phoneNumberUpdateArgs: Prisma.PhoneNumberUpdateArgs): Promise<Partial<PhoneNumber>> {
async Update(phoneNumberUpdateArgs: PhoneNumberUpdateArgs): Promise<Partial<PhoneNumber>> {
try {
return await this.prisma.phoneNumber.update(phoneNumberUpdateArgs);
} catch (e) {
@ -34,11 +37,11 @@ export class PhoneNumberService {
}
}
async Count(phoneNumberCountArgs: Prisma.PhoneNumberCountArgs): Promise<number> {
async Count(phoneNumberCountArgs: PhoneNumberCountArgs): Promise<number> {
return await this.prisma.phoneNumber.count(phoneNumberCountArgs);
}
async Create(phoneNumberCreateArgs: Prisma.PhoneNumberCreateArgs): Promise<Partial<PhoneNumber>> {
async Create(phoneNumberCreateArgs: PhoneNumberCreateArgs): Promise<Partial<PhoneNumber>> {
try {
return await this.prisma.phoneNumber.create(phoneNumberCreateArgs);
} catch (e) {
@ -49,7 +52,7 @@ export class PhoneNumberService {
}
}
async Delete(phoneNumberDeleteArgs: Prisma.PhoneNumberDeleteArgs): Promise<Partial<PhoneNumber>> {
async Delete(phoneNumberDeleteArgs: PhoneNumberDeleteArgs): Promise<Partial<PhoneNumber>> {
try {
return await this.prisma.phoneNumber.delete(phoneNumberDeleteArgs);
} catch (e) {

@ -1,8 +1,9 @@
import { INestApplication, Injectable, OnModuleInit } from "@nestjs/common";
import { PrismaClient } from "@prisma/client";
import {UserDataClient} from "@platform/prisma-clients";
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
export class PrismaService extends UserDataClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}

@ -1,6 +1,9 @@
import { Inject, Injectable } from "@nestjs/common";
import { PrismaService } from "../../prisma/service/prisma.service";
import { Prisma, User } from "@prisma/client";
import { User, UserFindUniqueArgs,
UserFindUniqueArgs, UserFindFirstArgs, UserFindManyArgs,
UserUpdateArgs, UserCountArgs, UserCreateArgs, UserDeleteArgs
} from "@platform/prisma-clients/user-data";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime";
import { UniqueConstraintFailedError } from "../../prisma/error/unique-constraint-failed.error";
import { RecordNotFoundError } from "../../prisma/error/record-not-found.error";
@ -10,19 +13,19 @@ export class UserService {
constructor(@Inject(PrismaService) private prisma: PrismaService) {
}
async FindUnique(userFindUniqueArgs: Prisma.UserFindUniqueArgs): Promise<Partial<User> | null> {
async FindUnique(userFindUniqueArgs: UserFindUniqueArgs): Promise<Partial<User> | null> {
return await this.prisma.user.findUnique(userFindUniqueArgs);
}
async FindFirst(userFindFirstArgs: Prisma.UserFindFirstArgs): Promise<Partial<User> | null> {
async FindFirst(userFindFirstArgs: UserFindFirstArgs): Promise<Partial<User> | null> {
return await this.prisma.user.findFirst(userFindFirstArgs);
}
async FindMany(userFindManyArgs: Prisma.UserFindManyArgs): Promise<Partial<User>[]> {
async FindMany(userFindManyArgs: UserFindManyArgs): Promise<Partial<User>[]> {
return await this.prisma.user.findMany(userFindManyArgs);
}
async Update(userUpdateArgs: Prisma.UserUpdateArgs): Promise<Partial<User>> {
async Update(userUpdateArgs: UserUpdateArgs): Promise<Partial<User>> {
try {
return await this.prisma.user.update(userUpdateArgs);
} catch (e) {
@ -34,11 +37,11 @@ export class UserService {
}
}
async Count(userCountArgs: Prisma.UserCountArgs): Promise<number> {
async Count(userCountArgs: UserCountArgs): Promise<number> {
return await this.prisma.user.count(userCountArgs);
}
async Create(userCreateArgs: Prisma.UserCreateArgs): Promise<Partial<User>> {
async Create(userCreateArgs: UserCreateArgs): Promise<Partial<User>> {
try {
return await this.prisma.user.create(userCreateArgs);
} catch (e) {
@ -49,7 +52,7 @@ export class UserService {
}
}
async Delete(userDeleteArgs: Prisma.UserDeleteArgs): Promise<Partial<User>> {
async Delete(userDeleteArgs: UserDeleteArgs): Promise<Partial<User>> {
try {
return await this.prisma.user.delete(userDeleteArgs);
} catch (e) {

@ -1,5 +1,8 @@
import { Body, Controller, HttpCode, Inject, Post, UseInterceptors } from "@nestjs/common";
import { Prisma, User } from "@prisma/client";
import { User, UserFindUniqueArgs,
UserFindUniqueArgs, UserFindFirstArgs, UserFindManyArgs,
UserUpdateArgs, UserCountArgs, UserCreateArgs, UserDeleteArgs
} from "@platform/prisma-clients/user-data";
import { UserService } from "./service/user.service";
import { PrismaErrorInterceptor } from "../prisma/interceptor/prisma-error.interceptor";
@ -11,43 +14,43 @@ export class UserController {
@Post("find/unique")
@HttpCode(200)
async FindUnique(@Body() userFindUniqueArgs: Prisma.UserFindUniqueArgs): Promise<Partial<User> | null> {
async FindUnique(@Body() userFindUniqueArgs: UserFindUniqueArgs): Promise<Partial<User> | null> {
return await this.user.FindUnique(userFindUniqueArgs);
}
@Post("find/first")
@HttpCode(200)
async FindFirst(@Body() userFindFirstArgs: Prisma.UserFindFirstArgs): Promise<Partial<User> | null> {
async FindFirst(@Body() userFindFirstArgs: UserFindFirstArgs): Promise<Partial<User> | null> {
return await this.user.FindFirst(userFindFirstArgs);
}
@Post("find/many")
@HttpCode(200)
async FindMany(@Body() userFindManyArgs: Prisma.UserFindManyArgs): Promise<Partial<User>[]> {
async FindMany(@Body() userFindManyArgs: UserFindManyArgs): Promise<Partial<User>[]> {
return await this.user.FindMany(userFindManyArgs);
}
@Post("update")
@HttpCode(200)
async Update(@Body() userUpdateArgs: Prisma.UserUpdateArgs): Promise<Partial<User>> {
async Update(@Body() userUpdateArgs: UserUpdateArgs): Promise<Partial<User>> {
return await this.user.Update(userUpdateArgs);
}
@Post("count")
@HttpCode(200)
async Count(@Body() userCountArgs: Prisma.UserCountArgs): Promise<number> {
async Count(@Body() userCountArgs: UserCountArgs): Promise<number> {
return await this.user.Count(userCountArgs);
}
@Post("create")
@HttpCode(200)
async Create(@Body() userCreateArgs: Prisma.UserCreateArgs): Promise<Partial<User>> {
async Create(@Body() userCreateArgs: UserCreateArgs): Promise<Partial<User>> {
return await this.user.Create(userCreateArgs);
}
@Post("delete")
@HttpCode(200)
async Delete(@Body() userDeleteArgs: Prisma.UserDeleteArgs): Promise<Partial<User>> {
async Delete(@Body() userDeleteArgs: UserDeleteArgs): Promise<Partial<User>> {
return await this.user.Delete(userDeleteArgs);
}
}

@ -1 +1,2 @@
export { AuthClient } from './auth';
export { UserDataClient } from './user-data';

@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env

@ -0,0 +1,2 @@
export { PrismaClient as UserDataClient } from '.prisma/user-data-client';
export * from '.prisma/user-data-client';

@ -0,0 +1 @@
export class RecordNotFoundError extends Error {}

@ -0,0 +1 @@
export class UniqueConstraintFailedError extends Error {}

@ -0,0 +1,26 @@
import {
CallHandler,
ConflictException,
ExecutionContext,
Injectable,
NestInterceptor,
NotFoundException,
} from '@nestjs/common';
import { catchError, Observable } from 'rxjs';
import { RecordNotFoundError } from '../error/record-not-found.error';
import { UniqueConstraintFailedError } from '../error/unique-constraint-failed.error';
@Injectable()
export class PrismaErrorInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
catchError((err) => {
if (err instanceof RecordNotFoundError)
throw new NotFoundException(err.message);
if (err instanceof UniqueConstraintFailedError)
throw new ConflictException(err.message);
throw err;
})
);
}
}

@ -1,10 +1,14 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
output = "../../../../node_modules/.prisma/user-data-client"
}
datasource db {
provider = "postgresql"
url = env("USER_DATA_SOURCE_URL")
}
model User {

@ -17,6 +17,7 @@
"paths": {
"@pconfig": ["config/index.ts"],
"@platform/prisma-clients": ["libs/prisma-clients/index.ts"],
"@platform/prisma-clients/*": ["libs/prisma-clients/*"],
"@platform/prisma-generator": ["libs/prisma-generator/src/index.ts"],
"@platform/site-layouts": ["libs/site-layouts/src/index.ts"],
"@platform/site-pages": ["libs/site-pages/src/index.ts"],

Loading…
Cancel
Save