change repo

This commit is contained in:
Ruben Kallinich
2024-07-11 10:04:05 +02:00
commit eb3870fa81
48 changed files with 7830 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CustomerController } from './customer.controller';
import { CustomerService } from './customer.service';
describe('CustomerController', () => {
let controller: CustomerController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CustomerController],
providers: [CustomerService],
}).compile();
controller = module.get<CustomerController>(CustomerController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@@ -0,0 +1,54 @@
import { Controller } from '@nestjs/common';
import { PagespeedService } from '../pagespeed/pagespeed.service';
import { WebsiteService } from '../website/website.service';
import { CustomerService } from './customer.service';
@Controller('customer')
export class CustomerController {
// constructor(
// private readonly customerService: CustomerService,
// private readonly websiteService: WebsiteService,
// private readonly pageSpeedService: PagespeedService,
// ) {}
// @Post()
// async createCustomer(
// @Body() createCustomerDto: CreateCustomerDto,
// ): Promise<Customer> {
// return this.customerService.createOrUpdateCustomer(createCustomerDto);
// }
// @Post()
// async createCustomer(
// @Body() createCustomerDto: CreateCustomerDto,
// ): Promise<Customer> {
// return this.customerService.createOrUpdateCustomer(createCustomerDto);
// }
//
// @Get('all')
// findAll(): Promise<Customer[]> {
// return this.customerService.getAllCustomers();
// }
// @Get('id/:id')
// async findOneCustomerById(@Param('id') id: string): Promise<Customer> {
// return this.customerService.getCustomerById(id);
// }
// @Get('name/:name')
// async findOneCustomerByName(@Param('name') name: string): Promise<Customer> {
// return this.customerService.getCustomerByName(name);
// }
// @Get('website/:id')
// async findOneWebsiteById(@Param('id') id: string): Promise<Website> {
// return this.websiteService.getWebsiteById(id);
// }
// @Get('website/:id/pagespeed')
// async getPageSpeedByWebsiteId(
// @Param('id') id: string,
// ): Promise<PageSpeedData[]> {
// return this.pageSpeedService.getPageSpeedsByWebsiteId(id);
// }
// @Get('display/:displayName')
// async findOneWebsiteByDisplayName(
// @Param('displayName') displayName: string,
// ): Promise<Website> {
// return this.websiteService.getWebsiteByDisplayName(displayName);
// }
}

View File

@@ -0,0 +1,23 @@
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PagespeedService } from '../pagespeed/pagespeed.service';
import { WebsiteService } from '../website/website.service';
import { PageSpeedData } from '../pagespeed/entities/pagespeeddata.entity';
import { Website } from '../website/entities/website.entity';
import { CustomerController } from './customer.controller';
import { CustomerService } from './customer.service';
import { Customer } from './entities/customer.entity';
@Module({
imports: [
ConfigModule,
HttpModule,
TypeOrmModule.forFeature([Customer, Website, PageSpeedData]),
],
controllers: [CustomerController],
providers: [CustomerService, WebsiteService, PagespeedService],
exports: [CustomerService, WebsiteService, PagespeedService, TypeOrmModule],
})
export class CustomerModule {}

View File

@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CustomerService } from './customer.service';
describe('CustomerService', () => {
let service: CustomerService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [CustomerService],
}).compile();
service = module.get<CustomerService>(CustomerService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

View File

@@ -0,0 +1,39 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CreateCustomerDto } from './dto/create-customer.dto';
import { Customer } from './entities/customer.entity';
@Injectable()
export class CustomerService {
constructor(
@InjectRepository(Customer)
private customerRepository: Repository<Customer>,
) {}
async createOrUpdateCustomer(
data: Partial<CreateCustomerDto>,
): Promise<Customer> {
let customer = await this.customerRepository.findOne({
where: { email: data.email },
});
if (!customer) {
customer = new Customer();
customer.firstName = data.firstName;
customer.lastName = data.lastName;
customer.email = data.email;
customer.dsgvo = data.dsgvo;
await this.customerRepository.save(customer);
}
return customer;
}
async getAllCustomers(): Promise<Customer[]> {
return this.customerRepository.find();
}
async getCustomerById(id: string): Promise<Customer> {
return this.customerRepository.findOne({ where: { id: id } });
}
async getCustomerByName(name: string): Promise<Customer> {
return this.customerRepository.findOne({ where: { firstName: name } });
}
}

View File

@@ -0,0 +1,32 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsBoolean, IsEmail, IsString } from 'class-validator';
import { CreateWebsiteDto } from '../../website/dto/create-website.dto';
export class CreateCustomerDto {
@ApiProperty({ description: 'Customer Id' })
@IsString()
id: string;
@ApiProperty({ description: 'First name' })
@IsString()
firstName: string;
@ApiProperty({ description: 'Last name ' })
@IsString()
lastName: string;
@ApiProperty({ description: 'E-Mail adress' })
@IsString()
@IsEmail()
email: string;
@ApiProperty({
type: () => CreateWebsiteDto,
description: 'Website Association',
})
website: CreateWebsiteDto[];
@ApiProperty({ description: 'DSGVO confirmation' })
@IsBoolean()
dsgvo: boolean;
}

View File

@@ -0,0 +1,24 @@
import { ApiProperty } from '@nestjs/swagger';
import { LoadWebsiteDto } from '../../website/dto/load-website.dto';
import { IsString } from 'class-validator';
export class LoadCustomerDto {
@ApiProperty()
@IsString()
id: string;
@ApiProperty()
@IsString()
firstName: string;
@ApiProperty()
@IsString()
lastName: string;
@ApiProperty()
@IsString()
email: string;
@ApiProperty({ type: () => LoadWebsiteDto })
website: LoadCustomerDto;
}

View File

@@ -0,0 +1,25 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsEmail } from 'class-validator';
import { UpdateWebsiteDto } from '../../website/dto/update-website.dto';
export class UpdateCustomerDto {
@ApiProperty()
@IsString()
id: string;
@ApiProperty()
@IsString()
firstName: string;
@ApiProperty()
@IsString()
lastName: string;
@ApiProperty()
@IsString()
@IsEmail()
email: string;
@ApiProperty({ type: () => UpdateWebsiteDto })
website: UpdateWebsiteDto[];
}

View File

@@ -0,0 +1,36 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail } from 'class-validator';
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Website } from '../../website/entities/website.entity';
@Entity()
export class Customer {
@PrimaryGeneratedColumn('uuid')
@ApiProperty()
id: string;
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
@ApiProperty()
createdAt: Date;
@Column({ nullable: false })
@ApiProperty()
firstName: string;
@Column({ nullable: false })
@ApiProperty()
lastName: string;
@Column({ nullable: false })
@ApiProperty()
@IsEmail()
email: string;
@ApiProperty()
@OneToMany(() => Website, (website) => website.customers)
websites: Website[];
@ApiProperty()
@Column({ nullable: false })
dsgvo: boolean;
}