Add customer management
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export interface PhoneNumberDto {
|
||||
number: string;
|
||||
note: string;
|
||||
}
|
||||
|
||||
export interface NoteDto {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface CreateCustomerDto {
|
||||
email: string;
|
||||
name: string;
|
||||
companyName: string;
|
||||
phoneNumbers: PhoneNumberDto[];
|
||||
street: string;
|
||||
zip: string;
|
||||
city: string;
|
||||
notes: NoteDto[];
|
||||
}
|
||||
32
internal_frontend/services/customers/entities/customer.ts
Normal file
32
internal_frontend/services/customers/entities/customer.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export interface PhoneNumber {
|
||||
number: string;
|
||||
note: string;
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedBy: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Note {
|
||||
text: string;
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedBy: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface Customer {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
companyName: string;
|
||||
phoneNumbers: PhoneNumber[];
|
||||
street: string;
|
||||
zip: string;
|
||||
city: string;
|
||||
notes: Note[];
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedBy: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import {Customer} from "@/services/customers/entities/customer";
|
||||
import {CreateCustomerDto} from "@/services/customers/dtos/createCustomer.dto";
|
||||
import {callApi} from "@/lib/api/callApi";
|
||||
|
||||
export class CustomerRepository {
|
||||
static async getAll(): Promise<Customer[]> {
|
||||
return await callApi<Customer[]>("/customers", "GET");
|
||||
}
|
||||
|
||||
static async create(payload: CreateCustomerDto): Promise<void> {
|
||||
await callApi<void, CreateCustomerDto>("/customers", "POST", payload);
|
||||
}
|
||||
}
|
||||
21
internal_frontend/services/customers/usecases/addCustomer.ts
Normal file
21
internal_frontend/services/customers/usecases/addCustomer.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import {CreateCustomerDto} from "@/services/customers/dtos/createCustomer.dto";
|
||||
import {CustomerRepository} from "@/services/customers/repositories/customerRepository";
|
||||
|
||||
export async function addCustomer(params: CreateCustomerDto): Promise<void> {
|
||||
const {email, name, companyName, street, zip, city, phoneNumbers, notes} = params;
|
||||
|
||||
const payload: CreateCustomerDto = {
|
||||
email,
|
||||
name,
|
||||
companyName,
|
||||
street,
|
||||
zip,
|
||||
city,
|
||||
phoneNumbers,
|
||||
notes: notes.map(({text}) => ({text})),
|
||||
};
|
||||
|
||||
await CustomerRepository.create(payload);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
"use server";
|
||||
|
||||
import {callApi} from "@/lib/api/callApi";
|
||||
import {Customer} from "@/app/customers/page";
|
||||
import {customerRoutes} from "@/app/api/customers/customerRoutes";
|
||||
|
||||
export async function validateCustomer(input: {
|
||||
email: string;
|
||||
companyName: string;
|
||||
street: string;
|
||||
zip: string;
|
||||
city: string;
|
||||
}): Promise<Customer[]> {
|
||||
return await callApi<Customer[]>(customerRoutes.validate, "POST", input);
|
||||
}
|
||||
Reference in New Issue
Block a user